Search in sources :

Example 81 with EmbeddedChannel

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));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 82 with EmbeddedChannel

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 83 with EmbeddedChannel

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();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 84 with EmbeddedChannel

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());
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 85 with EmbeddedChannel

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);
}
Also used : NettyConnection(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Aggregations

EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1027 Test (org.junit.jupiter.api.Test)515 ByteBuf (io.netty.buffer.ByteBuf)356 Test (org.junit.Test)342 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)85 HttpResponse (io.netty.handler.codec.http.HttpResponse)73 HttpRequest (io.netty.handler.codec.http.HttpRequest)69 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)64 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)60 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)55 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)50 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)49 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)46 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)42 IOException (java.io.IOException)38 InetSocketAddress (java.net.InetSocketAddress)38 Executable (org.junit.jupiter.api.function.Executable)36 ArrayList (java.util.ArrayList)35 Before (org.junit.Before)32 ChannelHandler (io.netty.channel.ChannelHandler)27