Search in sources :

Example 11 with EventLoopGroupFactory

use of org.graylog2.inputs.transports.netty.EventLoopGroupFactory in project graylog2-server by Graylog2.

the class AbstractTcpTransportTest method getChildChannelHandlersFailsIfTempDirDoesNotExist.

@Test
public void getChildChannelHandlersFailsIfTempDirDoesNotExist() throws IOException {
    final File tmpDir = temporaryFolder.newFolder();
    assumeTrue(tmpDir.delete());
    System.setProperty("java.io.tmpdir", tmpDir.getAbsolutePath());
    final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
    final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, tlsConfiguration) {
    };
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Couldn't write to temporary directory: " + tmpDir.getAbsolutePath());
    transport.getChildChannelHandlers(input);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) File(java.io.File) Test(org.junit.Test)

Example 12 with EventLoopGroupFactory

use of org.graylog2.inputs.transports.netty.EventLoopGroupFactory in project graylog2-server by Graylog2.

the class AbstractTcpTransportTest method testConnectionCounter.

@Test
@Ignore("Disabled test due to being unreliable. For details see https://github.com/Graylog2/graylog2-server/issues/4791.")
public void testConnectionCounter() throws Exception {
    final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "127.0.0.1", "port", 0));
    final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, tlsConfiguration) {
    };
    transport.launch(input);
    await().atMost(5, TimeUnit.SECONDS).until(() -> transport.getLocalAddress() != null);
    final InetSocketAddress localAddress = (InetSocketAddress) transport.getLocalAddress();
    assertThat(localAddress).isNotNull();
    final ChannelFuture future1 = clientChannel(localAddress.getHostString(), localAddress.getPort()).channel().writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE).syncUninterruptibly();
    final ChannelFuture future2 = clientChannel(localAddress.getHostString(), localAddress.getPort()).channel().writeAndFlush(Unpooled.EMPTY_BUFFER).syncUninterruptibly();
    // TODO: Get rid of this (arbitrary) wait time
    Thread.sleep(100L);
    assertThat(future1.channel().isActive()).isFalse();
    assertThat(future2.channel().isActive()).isTrue();
    assertThat(localRegistry.getGauges().get("open_connections").getValue()).isEqualTo(1);
    assertThat(localRegistry.getGauges().get("total_connections").getValue()).isEqualTo(2L);
    future2.channel().close().syncUninterruptibly();
    // TODO: Get rid of this (arbitrary) wait time
    Thread.sleep(100L);
    assertThat(future1.channel().isActive()).isFalse();
    assertThat(future2.channel().isActive()).isFalse();
    assertThat(localRegistry.getGauges().get("open_connections").getValue()).isEqualTo(0);
    assertThat(localRegistry.getGauges().get("total_connections").getValue()).isEqualTo(2L);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Configuration(org.graylog2.plugin.configuration.Configuration) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) InetSocketAddress(java.net.InetSocketAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NettyTransportConfiguration (org.graylog2.inputs.transports.NettyTransportConfiguration)8 Test (org.junit.Test)8 Configuration (org.graylog2.plugin.configuration.Configuration)7 TLSProtocolsConfiguration (org.graylog2.configuration.TLSProtocolsConfiguration)6 LocalMetricRegistry (org.graylog2.plugin.LocalMetricRegistry)6 EventLoopGroupFactory (org.graylog2.inputs.transports.netty.EventLoopGroupFactory)4 ThroughputCounter (org.graylog2.plugin.inputs.util.ThroughputCounter)4 File (java.io.File)3 MessageInput (org.graylog2.plugin.inputs.MessageInput)3 Before (org.junit.Before)3 ChannelFuture (io.netty.channel.ChannelFuture)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 InetSocketAddress (java.net.InetSocketAddress)2 Ignore (org.junit.Ignore)2 ChannelHandler (io.netty.channel.ChannelHandler)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 LinkedHashMap (java.util.LinkedHashMap)1 Callable (java.util.concurrent.Callable)1 NetflowV9CodecAggregator (org.graylog.plugins.netflow.codecs.NetflowV9CodecAggregator)1 SuppressForbidden (org.graylog2.shared.SuppressForbidden)1