List of usage examples for io.netty.channel DefaultChannelPromise DefaultChannelPromise
public DefaultChannelPromise(Channel channel, EventExecutor executor)
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test(expected = DuplicateKeyException.class) public void testSendSmsReturnsFailedFutureWhenOfferToWindowFails() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();/* w w w .j a v a 2s.c o m*/ when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); //add the sms so the next offer fails clientSession.getWindow().offer(sms.getId(), sms, 5000); WindowFuture<Sms, Ack> future = clientSession.sendSms(sms, 5000); assertFalse(future.isCancelled()); assertSame(sms, future.getRequest()); Futures.getChecked(future, DuplicateKeyException.class); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test(expected = IOException.class) public void testSendSmsReturnsFailedFutureWhenWriteFails() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setFailure(new IOException()); when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); WindowFuture<Sms, Ack> future = clientSession.sendSms(sms, 5000); Futures.getChecked(future, IOException.class); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test(expected = CancellationException.class) public void testSendSmsReturnsFailedFutureWhenWriteIsCancelled() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.cancel(true);/*from ww w. j ava 2 s. co m*/ when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); WindowFuture<Sms, Ack> future = clientSession.sendSms(sms, 5000); Futures.getUnchecked(future); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testSendHeartBeat() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();/*from w w w . jav a 2s . c om*/ when(channel.writeAndFlush(any())).thenReturn(promise); HeartBeat heartBeat = new HeartBeat(); assertSame(promise, clientSession.sendHeartBeat(heartBeat)); verify(channel).writeAndFlush(heartBeat); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testSendSmsAndWaitReturnsCorrectResponse() throws Exception { final DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();//ww w . j a va 2 s. com when(channel.writeAndFlush(any())).thenReturn(promise); final Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); final Ack expectedResponse = new Ack(); scheduledExecutorService.schedule(new Runnable() { @Override public void run() { clientSession.getWindow().complete(sms.getId(), expectedResponse); } }, 100, TimeUnit.MILLISECONDS); final Ack response = clientSession.sendSmsAndWait(sms, 5000); assertSame(expectedResponse, response); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testSendSmsAndWaitThrowsWhenOfferToWindowTimesOut() { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();/* w ww . j a v a 2 s . com*/ when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); clientSessionConfiguration.setRequestExpiryTimeout(1); try { clientSession.sendSmsAndWait(sms, 1); } catch (InterruptedException e) { fail("Not the correct exception"); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof TimeoutException); } }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testSendSmsAndWaitThrowsWhenOfferToWindowFails() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();//from w w w.j ava2s . c o m when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); //add the sms so the next offer fails clientSession.getWindow().offer(sms.getId(), sms, 5000); try { clientSession.sendSmsAndWait(sms, 5000); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof DuplicateKeyException); } }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testSendSmsAndWaitThrowsWhenWriteFails() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setFailure(new IOException()); when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); try {/* w w w . java 2 s . c o m*/ clientSession.sendSmsAndWait(sms, 5000); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof IOException); } }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test(expected = CancellationException.class) public void testSendSmsAndWaitThrowsWhenWriteIsCancelled() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.cancel(true);// w ww . j a va 2 s.c o m when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms(); sms.setId(UUID.randomUUID()); sms.setBoxId("test box"); clientSession.sendSmsAndWait(sms, 5000); }
From source file:com.lambdaworks.redis.protocol.CommandHandlerTest.java
License:Apache License
@Test public void shouldCancelCommandOnQueueSingleFailure() throws Exception { Command<String, String, String> commandMock = mock(Command.class); RuntimeException exception = new RuntimeException(); when(commandMock.getOutput()).thenThrow(exception); ChannelPromise channelPromise = new DefaultChannelPromise(null, ImmediateEventExecutor.INSTANCE); try {//from w w w. j a va2 s . c om sut.write(context, commandMock, channelPromise); fail("Missing RuntimeException"); } catch (RuntimeException e) { assertThat(e).isSameAs(exception); } assertThat((Collection) ReflectionTestUtils.getField(sut, "queue")).isEmpty(); verify(commandMock).completeExceptionally(exception); }