use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project reactor-netty by reactor.
the class NettyInboundTest method onReadIdleReplaces.
@Test
public void onReadIdleReplaces() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel();
NettyContext mockContext = () -> channel;
NettyInbound inbound = new NettyInbound() {
@Override
public NettyContext context() {
return mockContext;
}
@Override
public Flux<?> receiveObject() {
return Flux.empty();
}
};
AtomicLong idle1 = new AtomicLong();
AtomicLong idle2 = new AtomicLong();
inbound.onReadIdle(100, idle1::incrementAndGet);
inbound.onReadIdle(150, idle2::incrementAndGet);
ReactorNetty.InboundIdleStateHandler idleStateHandler = (ReactorNetty.InboundIdleStateHandler) channel.pipeline().get(NettyPipeline.OnChannelReadIdle);
idleStateHandler.onReadIdle.run();
assertThat(channel.pipeline().names(), is(Arrays.asList(NettyPipeline.OnChannelReadIdle, "DefaultChannelPipeline$TailContext#0")));
assertThat(idle1.intValue(), is(0));
assertThat(idle2.intValue(), is(1));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project reactor-netty by reactor.
the class NettyOutboundTest method onWriteIdleReplaces.
@Test
public void onWriteIdleReplaces() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel();
NettyContext mockContext = () -> channel;
NettyOutbound outbound = () -> mockContext;
AtomicLong idle1 = new AtomicLong();
AtomicLong idle2 = new AtomicLong();
outbound.onWriteIdle(100, idle1::incrementAndGet);
outbound.onWriteIdle(150, idle2::incrementAndGet);
ReactorNetty.OutboundIdleStateHandler idleStateHandler = (ReactorNetty.OutboundIdleStateHandler) channel.pipeline().get(NettyPipeline.OnChannelWriteIdle);
idleStateHandler.onWriteIdle.run();
assertThat(channel.pipeline().names()).containsExactly(NettyPipeline.OnChannelWriteIdle, "DefaultChannelPipeline$TailContext#0");
assertThat(idle1.intValue()).isZero();
assertThat(idle2.intValue()).isEqualTo(1);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project openflowplugin by opendaylight.
the class ConnectionAdapterImplStatisticsTest method testEnterOFJavaCounter.
/**
* Test statistic counter for all rpc calls (counters DS_ENTERED_OFJAVA and DS_FLOW_MODS_ENTERED have to be
* enabled).
*/
@Test
public void testEnterOFJavaCounter() {
if (!statCounters.isCounterEnabled(CounterEventTypes.DS_ENTERED_OFJAVA)) {
Assert.fail("Counter " + CounterEventTypes.DS_ENTERED_OFJAVA + " is not enabled");
}
if (!statCounters.isCounterEnabled(CounterEventTypes.DS_FLOW_MODS_ENTERED)) {
Assert.fail("Counter " + CounterEventTypes.DS_FLOW_MODS_ENTERED + " is not enabled");
}
final EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
adapter = new ConnectionAdapterImpl(embChannel, InetSocketAddress.createUnresolved("localhost", 9876), true, CHANNEL_OUTBOUND_QUEUE_SIZE);
cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
adapter.setResponseCache(cache);
adapter.barrier(barrierInput);
embChannel.runPendingTasks();
adapter.echo(echoInput);
embChannel.runPendingTasks();
adapter.echoReply(echoReplyInput);
embChannel.runPendingTasks();
adapter.experimenter(experimenterInput);
embChannel.runPendingTasks();
adapter.flowMod(flowModInput);
embChannel.runPendingTasks();
adapter.getConfig(getConfigInput);
embChannel.runPendingTasks();
adapter.getFeatures(getFeaturesInput);
embChannel.runPendingTasks();
adapter.getQueueConfig(getQueueConfigInput);
embChannel.runPendingTasks();
adapter.groupMod(groupModInput);
embChannel.runPendingTasks();
adapter.hello(helloInput);
embChannel.runPendingTasks();
adapter.meterMod(meterModInput);
embChannel.runPendingTasks();
adapter.packetOut(packetOutInput);
embChannel.runPendingTasks();
adapter.multipartRequest(multipartRequestInput);
embChannel.runPendingTasks();
adapter.portMod(portModInput);
embChannel.runPendingTasks();
adapter.roleRequest(roleRequestInput);
embChannel.runPendingTasks();
adapter.setConfig(setConfigInput);
embChannel.runPendingTasks();
adapter.tableMod(tableModInput);
embChannel.runPendingTasks();
adapter.getAsync(getAsyncInput);
embChannel.runPendingTasks();
adapter.setAsync(setAsyncInput);
embChannel.runPendingTasks();
Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl rpc methods", 19, statCounters.getCounter(CounterEventTypes.DS_ENTERED_OFJAVA).getCounterValue());
Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl flow-mod entered", 1, statCounters.getCounter(CounterEventTypes.DS_FLOW_MODS_ENTERED).getCounterValue());
adapter.disconnect();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project activemq-artemis by apache.
the class NettyConnectionTest method testCreateBuffer.
@Test
public void testCreateBuffer() throws Exception {
EmbeddedChannel channel = createChannel();
NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
final int size = 1234;
ActiveMQBuffer buff = conn.createTransportBuffer(size);
// Netty buffer does lazy initialization.
buff.writeByte((byte) 0x00);
Assert.assertEquals(size, buff.capacity());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project activemq-artemis by apache.
the class NettyConnectionTest method throwsExceptionOnBlockUntilWritableIfClosed.
@Test(expected = IllegalStateException.class)
public void throwsExceptionOnBlockUntilWritableIfClosed() {
EmbeddedChannel channel = createChannel();
NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
conn.close();
// to make sure the channel is closed it needs to run the pending tasks
channel.runPendingTasks();
conn.blockUntilWritable(0, 0, TimeUnit.NANOSECONDS);
}
Aggregations