Search in sources :

Example 1 with IOUringSocketChannel

use of io.netty.incubator.channel.uring.IOUringSocketChannel in project zuul by Netflix.

the class IoUringTest method exerciseIoUringServer.

private void exerciseIoUringServer() throws Exception {
    IOUring.ensureAvailability();
    ServerStatusManager ssm = mock(ServerStatusManager.class);
    Map<NamedSocketAddress, ChannelInitializer<?>> initializers = new HashMap<>();
    final List<IOUringSocketChannel> ioUringChannels = Collections.synchronizedList(new ArrayList<IOUringSocketChannel>());
    ChannelInitializer<Channel> init = new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) {
            LOGGER.info("Channel: " + ch.getClass().getName() + ", isActive=" + ch.isActive() + ", isOpen=" + ch.isOpen());
            if (ch instanceof IOUringSocketChannel) {
                ioUringChannels.add((IOUringSocketChannel) ch);
            }
        }
    };
    initializers.put(new NamedSocketAddress("test", new InetSocketAddress(0)), init);
    // The port to channel map keys on the port, post bind. This should be unique even if InetAddress is same
    initializers.put(new NamedSocketAddress("test2", new InetSocketAddress(0)), init);
    ClientConnectionsShutdown ccs = new ClientConnectionsShutdown(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), GlobalEventExecutor.INSTANCE, /* discoveryClient= */
    null);
    EventLoopGroupMetrics elgm = new EventLoopGroupMetrics(Spectator.globalRegistry());
    EventLoopConfig elc = new EventLoopConfig() {

        @Override
        public int eventLoopCount() {
            return 1;
        }

        @Override
        public int acceptorCount() {
            return 1;
        }
    };
    Server s = new Server(new NoopRegistry(), ssm, initializers, ccs, elgm, elc);
    s.start();
    List<NamedSocketAddress> addresses = s.getListeningAddresses();
    assertEquals(2, addresses.size());
    addresses.forEach(address -> {
        assertTrue(address.unwrap() instanceof InetSocketAddress);
        InetSocketAddress inetAddress = ((InetSocketAddress) address.unwrap());
        assertNotEquals(inetAddress.getPort(), 0);
        checkConnection(inetAddress.getPort());
    });
    await().atMost(1, SECONDS).until(() -> ioUringChannels.size() == 2);
    s.stop();
    assertEquals(2, ioUringChannels.size());
    for (IOUringSocketChannel ch : ioUringChannels) {
        assertTrue("isShutdown", ch.isShutdown());
    }
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) ServerStatusManager(com.netflix.netty.common.status.ServerStatusManager) InetSocketAddress(java.net.InetSocketAddress) IOUringSocketChannel(io.netty.incubator.channel.uring.IOUringSocketChannel) Channel(io.netty.channel.Channel) IOUringSocketChannel(io.netty.incubator.channel.uring.IOUringSocketChannel) EventLoopGroupMetrics(com.netflix.netty.common.metrics.EventLoopGroupMetrics) NoopRegistry(com.netflix.spectator.api.NoopRegistry) ChannelInitializer(io.netty.channel.ChannelInitializer)

Aggregations

EventLoopGroupMetrics (com.netflix.netty.common.metrics.EventLoopGroupMetrics)1 ServerStatusManager (com.netflix.netty.common.status.ServerStatusManager)1 NoopRegistry (com.netflix.spectator.api.NoopRegistry)1 Channel (io.netty.channel.Channel)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 IOUringSocketChannel (io.netty.incubator.channel.uring.IOUringSocketChannel)1 InetSocketAddress (java.net.InetSocketAddress)1