use of io.netty.channel.DefaultChannelPromise in project grpc-java by grpc.
the class NettyClientStreamTest method removeUserAgentFromApplicationHeaders.
@Test
public void removeUserAgentFromApplicationHeaders() {
Metadata metadata = new Metadata();
metadata.put(GrpcUtil.USER_AGENT_KEY, "bad agent");
listener = mock(ClientStreamListener.class);
Mockito.reset(writeQueue);
ChannelPromise completedPromise = new DefaultChannelPromise(channel).setSuccess();
when(writeQueue.enqueue(any(QueuedCommand.class), anyBoolean())).thenReturn(completedPromise);
stream = new NettyClientStream(new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE), methodDescriptor, new Metadata(), channel, AsciiString.of("localhost"), AsciiString.of("http"), AsciiString.of("good agent"), StatsTraceContext.NOOP, transportTracer, CallOptions.DEFAULT, false);
stream.start(listener);
ArgumentCaptor<CreateStreamCommand> cmdCap = ArgumentCaptor.forClass(CreateStreamCommand.class);
verify(writeQueue).enqueue(cmdCap.capture(), eq(false));
assertThat(ImmutableListMultimap.copyOf(cmdCap.getValue().headers())).containsEntry(Utils.USER_AGENT, AsciiString.of("good agent"));
}
use of io.netty.channel.DefaultChannelPromise in project bgpcep by opendaylight.
the class AbstractPCEPSessionTest method setUp.
@Before
public final void setUp() {
MockitoAnnotations.initMocks(this);
final ChannelFuture future = new DefaultChannelPromise(this.channel);
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
AbstractPCEPSessionTest.this.msgsSend.add((Notification) args[0]);
return future;
}).when(this.channel).writeAndFlush(any(Notification.class));
doReturn(this.channelFuture).when(this.channel).closeFuture();
doReturn(this.channelFuture).when(this.channelFuture).addListener(any(GenericFutureListener.class));
doReturn("TestingChannel").when(this.channel).toString();
doReturn(this.pipeline).when(this.channel).pipeline();
doReturn(this.address).when(this.channel).localAddress();
doReturn(this.address).when(this.channel).remoteAddress();
doReturn(this.eventLoop).when(this.channel).eventLoop();
doReturn(true).when(this.future).cancel(false);
doReturn(this.future).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
doReturn(this.pipeline).when(this.pipeline).addFirst(any(ChannelHandler.class));
doReturn(true).when(this.channel).isActive();
doReturn(mock(ChannelFuture.class)).when(this.channel).close();
doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).remoteAddress();
doReturn(new InetSocketAddress(this.ipAddress, this.port)).when(this.channel).localAddress();
this.openMsg = new OpenBuilder().setOpenMessage(new OpenMessageBuilder().setOpen(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder().setDeadTimer(DEADTIMER).setKeepalive(KEEP_ALIVE).setSessionId((short) 0).build()).build()).build();
this.kaMsg = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
this.startTlsMsg = new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build();
this.closeMsg = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason((short) 6).build()).build()).build();
this.listener = new SimpleSessionListener();
}
use of io.netty.channel.DefaultChannelPromise in project drill by axbaretto.
the class WebSessionResourcesTest method testDoubleClose.
/**
* Validates double call to {@link WebSessionResources#close()} doesn't throw any exception.
* @throws Exception
*/
@Test
public void testDoubleClose() throws Exception {
try {
ChannelPromise closeFuture = new DefaultChannelPromise(null, mock(EventExecutor.class));
webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock(UserSession.class), closeFuture);
webSessionResources.close();
verify(webSessionResources.getAllocator()).close();
verify(webSessionResources.getSession()).close();
assertTrue(webSessionResources.getCloseFuture() == null);
webSessionResources.close();
} catch (Exception e) {
fail();
}
}
use of io.netty.channel.DefaultChannelPromise in project drill by axbaretto.
the class WebSessionResourcesTest method testChannelPromiseWithNullExecutor.
/**
* Validates {@link WebSessionResources#close()} throws NPE when closefuture passed to WebSessionResources doesn't
* have a valid channel and EventExecutor associated with it.
* @throws Exception
*/
@Test
public void testChannelPromiseWithNullExecutor() throws Exception {
try {
ChannelPromise closeFuture = new DefaultChannelPromise(null);
webSessionResources = new WebSessionResources(mock(BufferAllocator.class), mock(SocketAddress.class), mock(UserSession.class), closeFuture);
webSessionResources.close();
fail();
} catch (Exception e) {
assertTrue(e instanceof NullPointerException);
verify(webSessionResources.getAllocator()).close();
verify(webSessionResources.getSession()).close();
}
}
use of io.netty.channel.DefaultChannelPromise in project x-pipe by ctripcorp.
the class DefaultRedisMasterReplicationTest method testCancelScheduleWhenConnected.
@Test
public void testCancelScheduleWhenConnected() throws IOException {
AtomicInteger replConfCount = new AtomicInteger();
defaultRedisMasterReplication = new DefaultRedisMasterReplication(redisMaster, redisKeeperServer, nioEventLoopGroup, scheduled, replTimeoutMilli) {
@Override
protected Command<Object> createReplConf() {
replConfCount.incrementAndGet();
return super.createReplConf();
}
};
defaultRedisMasterReplication.onContinue(RunidGenerator.DEFAULT.generateRunid(), RunidGenerator.DEFAULT.generateRunid());
Channel channel = mock(Channel.class);
when(channel.closeFuture()).thenReturn(new DefaultChannelPromise(channel));
defaultRedisMasterReplication.masterConnected(channel);
int countBefore = replConfCount.get();
sleep(DefaultRedisMasterReplication.REPLCONF_INTERVAL_MILLI * 2);
int countAfter = replConfCount.get();
Assert.assertEquals(countBefore, countAfter);
}
Aggregations