Search in sources :

Example 1 with NoopRegistry

use of com.netflix.spectator.api.NoopRegistry in project zuul by Netflix.

the class BaseZuulChannelInitializerTest method tcpHandlersAdded_withProxyProtocol.

@Test
public void tcpHandlersAdded_withProxyProtocol() {
    ChannelConfig channelConfig = new ChannelConfig();
    channelConfig.set(CommonChannelConfigKeys.withProxyProtocol, true);
    ChannelConfig channelDependencies = new ChannelConfig();
    channelDependencies.set(ZuulDependencyKeys.registry, new NoopRegistry());
    channelDependencies.set(ZuulDependencyKeys.rateLimitingChannelHandlerProvider, new NullChannelHandlerProvider());
    channelDependencies.set(ZuulDependencyKeys.sslClientCertCheckChannelHandlerProvider, new NullChannelHandlerProvider());
    ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    BaseZuulChannelInitializer init = new BaseZuulChannelInitializer("1234", channelConfig, channelDependencies, channelGroup) {

        @Override
        protected void initChannel(Channel ch) {
        }
    };
    EmbeddedChannel channel = new EmbeddedChannel();
    init.addTcpRelatedHandlers(channel.pipeline());
    assertNotNull(channel.pipeline().context(SourceAddressChannelHandler.class));
    assertNotNull(channel.pipeline().context(PerEventLoopMetricsChannelHandler.Connections.class));
    assertNotNull(channel.pipeline().context(ElbProxyProtocolChannelHandler.NAME));
    assertNotNull(channel.pipeline().context(MaxInboundConnectionsHandler.class));
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) SourceAddressChannelHandler(com.netflix.netty.common.SourceAddressChannelHandler) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) NoopRegistry(com.netflix.spectator.api.NoopRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) MaxInboundConnectionsHandler(com.netflix.netty.common.throttle.MaxInboundConnectionsHandler) NullChannelHandlerProvider(com.netflix.zuul.netty.ratelimiting.NullChannelHandlerProvider) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Test(org.junit.Test)

Example 2 with NoopRegistry

use of com.netflix.spectator.api.NoopRegistry 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)

Example 3 with NoopRegistry

use of com.netflix.spectator.api.NoopRegistry in project zuul by Netflix.

the class Http2OrHttpHandlerTest method swapInHttp2HandlerBasedOnALPN.

@Test
public void swapInHttp2HandlerBasedOnALPN() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel();
    final NoopRegistry registry = new NoopRegistry();
    final ChannelConfig channelConfig = new ChannelConfig();
    channelConfig.add(new ChannelConfigValue<>(CommonChannelConfigKeys.maxHttp2HeaderListSize, 32768));
    Http2ConnectionCloseHandler connectionCloseHandler = new Http2ConnectionCloseHandler(registry);
    Http2ConnectionExpiryHandler connectionExpiryHandler = new Http2ConnectionExpiryHandler(100, 100, 20 * 60 * 1000);
    Http2MetricsChannelHandlers http2MetricsChannelHandlers = new Http2MetricsChannelHandlers(registry, "server", "http2-443");
    final Http2OrHttpHandler http2OrHttpHandler = new Http2OrHttpHandler(new Http2StreamInitializer(channel, (x) -> {
    }, http2MetricsChannelHandlers, connectionCloseHandler, connectionExpiryHandler), channelConfig, cp -> {
    });
    channel.pipeline().addLast("codec_placeholder", new DummyChannelHandler());
    channel.pipeline().addLast(Http2OrHttpHandler.class.getSimpleName(), http2OrHttpHandler);
    http2OrHttpHandler.configurePipeline(channel.pipeline().lastContext(), ApplicationProtocolNames.HTTP_2);
    assertThat(channel.pipeline().get(Http2FrameCodec.class.getSimpleName() + "#0")).isInstanceOf(Http2FrameCodec.class);
    assertThat(channel.pipeline().get(BaseZuulChannelInitializer.HTTP_CODEC_HANDLER_NAME)).isInstanceOf(Http2MultiplexHandler.class);
    assertEquals("HTTP/2", channel.attr(Http2OrHttpHandler.PROTOCOL_NAME).get());
}
Also used : NoopRegistry(com.netflix.spectator.api.NoopRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) RunWith(org.junit.runner.RunWith) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec) ChannelConfigValue(com.netflix.netty.common.channel.config.ChannelConfigValue) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BaseZuulChannelInitializer(com.netflix.zuul.netty.server.BaseZuulChannelInitializer) CommonChannelConfigKeys(com.netflix.netty.common.channel.config.CommonChannelConfigKeys) Http2ConnectionExpiryHandler(com.netflix.netty.common.Http2ConnectionExpiryHandler) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2ConnectionCloseHandler(com.netflix.netty.common.Http2ConnectionCloseHandler) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) Assert.assertEquals(org.junit.Assert.assertEquals) Http2MetricsChannelHandlers(com.netflix.netty.common.metrics.Http2MetricsChannelHandlers) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) NoopRegistry(com.netflix.spectator.api.NoopRegistry) Http2ConnectionExpiryHandler(com.netflix.netty.common.Http2ConnectionExpiryHandler) Http2MetricsChannelHandlers(com.netflix.netty.common.metrics.Http2MetricsChannelHandlers) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Http2ConnectionCloseHandler(com.netflix.netty.common.Http2ConnectionCloseHandler) Test(org.junit.Test)

Example 4 with NoopRegistry

use of com.netflix.spectator.api.NoopRegistry in project zuul by Netflix.

the class BaseZuulChannelInitializerTest method tcpHandlersAdded.

@Test
public void tcpHandlersAdded() {
    ChannelConfig channelConfig = new ChannelConfig();
    ChannelConfig channelDependencies = new ChannelConfig();
    channelDependencies.set(ZuulDependencyKeys.registry, new NoopRegistry());
    channelDependencies.set(ZuulDependencyKeys.rateLimitingChannelHandlerProvider, new NullChannelHandlerProvider());
    channelDependencies.set(ZuulDependencyKeys.sslClientCertCheckChannelHandlerProvider, new NullChannelHandlerProvider());
    ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    BaseZuulChannelInitializer init = new BaseZuulChannelInitializer("1234", channelConfig, channelDependencies, channelGroup) {

        @Override
        protected void initChannel(Channel ch) {
        }
    };
    EmbeddedChannel channel = new EmbeddedChannel();
    init.addTcpRelatedHandlers(channel.pipeline());
    assertNotNull(channel.pipeline().context(SourceAddressChannelHandler.class));
    assertNotNull(channel.pipeline().context(PerEventLoopMetricsChannelHandler.Connections.class));
    assertNotNull(channel.pipeline().context(ElbProxyProtocolChannelHandler.NAME));
    assertNotNull(channel.pipeline().context(MaxInboundConnectionsHandler.class));
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) SourceAddressChannelHandler(com.netflix.netty.common.SourceAddressChannelHandler) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) NoopRegistry(com.netflix.spectator.api.NoopRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) MaxInboundConnectionsHandler(com.netflix.netty.common.throttle.MaxInboundConnectionsHandler) NullChannelHandlerProvider(com.netflix.zuul.netty.ratelimiting.NullChannelHandlerProvider) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Test(org.junit.Test)

Example 5 with NoopRegistry

use of com.netflix.spectator.api.NoopRegistry in project zuul by Netflix.

the class BaseZuulChannelInitializerTest method serverStateHandlerAdded.

@Test
public void serverStateHandlerAdded() {
    ChannelConfig channelConfig = new ChannelConfig();
    ChannelConfig channelDependencies = new ChannelConfig();
    channelDependencies.set(ZuulDependencyKeys.registry, new NoopRegistry());
    channelDependencies.set(ZuulDependencyKeys.rateLimitingChannelHandlerProvider, new NullChannelHandlerProvider());
    channelDependencies.set(ZuulDependencyKeys.sslClientCertCheckChannelHandlerProvider, new NullChannelHandlerProvider());
    ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    BaseZuulChannelInitializer init = new BaseZuulChannelInitializer("1234", channelConfig, channelDependencies, channelGroup) {

        @Override
        protected void initChannel(Channel ch) {
        }
    };
    EmbeddedChannel channel = new EmbeddedChannel();
    init.addPassportHandler(channel.pipeline());
    assertNotNull(channel.pipeline().context(ServerStateHandler.InboundHandler.class));
    assertNotNull(channel.pipeline().context(ServerStateHandler.OutboundHandler.class));
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) NoopRegistry(com.netflix.spectator.api.NoopRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) NullChannelHandlerProvider(com.netflix.zuul.netty.ratelimiting.NullChannelHandlerProvider) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Test(org.junit.Test)

Aggregations

NoopRegistry (com.netflix.spectator.api.NoopRegistry)6 Channel (io.netty.channel.Channel)5 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)5 Test (org.junit.Test)5 ChannelConfig (com.netflix.netty.common.channel.config.ChannelConfig)4 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 NullChannelHandlerProvider (com.netflix.zuul.netty.ratelimiting.NullChannelHandlerProvider)3 ChannelGroup (io.netty.channel.group.ChannelGroup)3 SourceAddressChannelHandler (com.netflix.netty.common.SourceAddressChannelHandler)2 EventLoopGroupMetrics (com.netflix.netty.common.metrics.EventLoopGroupMetrics)2 ServerStatusManager (com.netflix.netty.common.status.ServerStatusManager)2 MaxInboundConnectionsHandler (com.netflix.netty.common.throttle.MaxInboundConnectionsHandler)2 ChannelInitializer (io.netty.channel.ChannelInitializer)2 InetSocketAddress (java.net.InetSocketAddress)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Http2ConnectionCloseHandler (com.netflix.netty.common.Http2ConnectionCloseHandler)1 Http2ConnectionExpiryHandler (com.netflix.netty.common.Http2ConnectionExpiryHandler)1 ChannelConfigValue (com.netflix.netty.common.channel.config.ChannelConfigValue)1 CommonChannelConfigKeys (com.netflix.netty.common.channel.config.CommonChannelConfigKeys)1 Http2MetricsChannelHandlers (com.netflix.netty.common.metrics.Http2MetricsChannelHandlers)1