List of usage examples for io.netty.channel DefaultChannelPromise DefaultChannelPromise
public DefaultChannelPromise(Channel channel, EventExecutor executor)
From source file:com.github.milenkovicm.kafka.KafkaTopic.java
License:Apache License
private DefaultChannelPromise getDefaultChannelPromise() { final DefaultChannelPromise channelPromise = new DefaultChannelPromise(null, GlobalEventExecutor.INSTANCE); channelPromise.cancel(true);/*from ww w .j ava 2 s. c o m*/ return channelPromise; }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testSendAck() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();// www .j ava2s. c o m when(channel.writeAndFlush(any())).thenReturn(promise); Ack ack = mock(Ack.class); assertSame(promise, clientSession.sendAck(ack)); verify(channel).writeAndFlush(ack); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testIdentifyWhenCommandIsIdentifyWritesToChannel() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();/* ww w . ja v a 2s . c om*/ when(channel.writeAndFlush(any())).thenReturn(promise); Admin admin = new Admin(); admin.setBoxId("test"); admin.setAdminCommand(AdminCommand.IDENTIFY); clientSession.identify(admin); verify(channel).writeAndFlush(admin); verify(sessionHandler).fireSessionInitialized(clientSession); assertTrue(clientSession.isIdentified()); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test(expected = IllegalStateException.class) public void testIdentifyWhenCommandIsNotIdentifyThrows() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();/*from ww w . ja v a2 s.co m*/ when(channel.writeAndFlush(any())).thenReturn(promise); Admin admin = new Admin(); admin.setBoxId("test"); admin.setAdminCommand(AdminCommand.RESTART); clientSession.identify(admin); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test(expected = RuntimeException.class) public void testIdentifyWhenWriteFailsAndChannelIsActiveClosesChannelAndThrows() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setFailure(new IOException("test")); when(channel.writeAndFlush(any())).thenReturn(promise); when(channel.isActive()).thenReturn(true); when(channel.close()).thenReturn(promise); Admin admin = new Admin(); admin.setBoxId("test"); admin.setAdminCommand(AdminCommand.IDENTIFY); try {/* w ww . j a v a 2s .co m*/ clientSession.identify(admin); } finally { verify(channel).writeAndFlush(admin); verify(channel).close(); assertTrue(clientSession.isClosed()); } }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test(expected = RuntimeException.class) public void testIdentifyWhenWriteFailsAndChannelIsInactiveSetsClosedState() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setFailure(new IOException("test")); when(channel.writeAndFlush(any())).thenReturn(promise); when(channel.isActive()).thenReturn(false); Admin admin = new Admin(); admin.setBoxId("test"); admin.setAdminCommand(AdminCommand.IDENTIFY); try {/*w ww .ja v a 2s . c o m*/ clientSession.identify(admin); } finally { verify(channel).writeAndFlush(admin); verify(channel, times(0)).close(); assertTrue(clientSession.isClosed()); } }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testCloseWhenChannelIsActiveClosesChannel() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();/*from w ww. j a va 2s . c om*/ when(channel.isActive()).thenReturn(true); when(channel.close()).thenReturn(promise); clientSession.close(); verify(channel).close(); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testCloseWhenChannelIsInactiveClosesChannel() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();/*from w w w. j av a 2 s . co m*/ when(channel.isActive()).thenReturn(false); when(channel.close()).thenReturn(promise); clientSession.close(); verify(channel, times(0)).close(); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testDestroysClosesChannelAndDestroysTheWindow() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();//w w w .j a v a 2s. c o m when(channel.isActive()).thenReturn(false); when(channel.close()).thenReturn(promise); WindowFuture windowFuture = clientSession.getWindow().offer(UUID.randomUUID(), new Sms(), 5000); clientSession.destroy(); verify(channel, times(0)).close(); assertNull("Session handler must be null after destruction", clientSession.getSessionHandler()); assertTrue("The outstanding requests should be canceled", windowFuture.isCancelled()); }
From source file:com.github.spapageo.jannel.client.ClientSessionTest.java
License:Open Source License
@Test public void testSendSmsSetsUUIDAndBoxIdWhenNull() throws Exception { DefaultChannelPromise promise = new DefaultChannelPromise(channel, eventExecutors.next()); promise.setSuccess();//from w ww . j a v a 2 s. c om when(channel.writeAndFlush(any())).thenReturn(promise); Sms sms = new Sms("from", "to", "date", SmsType.MOBILE_TERMINATED_PUSH, DataCoding.DC_8BIT); clientSession.sendSms(sms, 5000); assertNotNull(sms.getId()); assertSame(clientSessionConfiguration.getClientId(), sms.getBoxId()); verify(channel).writeAndFlush(sms); }