Search in sources :

Example 16 with ThroughputCounter

use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.

the class AbstractTcpTransportTest method getChildChannelHandlersFailsIfTempDirIsNotWritable.

@Test
public void getChildChannelHandlersFailsIfTempDirIsNotWritable() throws IOException {
    final File tmpDir = temporaryFolder.newFolder();
    assumeTrue(tmpDir.setWritable(false));
    assumeFalse(tmpDir.canWrite());
    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 17 with ThroughputCounter

use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.

the class AbstractTcpTransportTest method setUp.

@Before
public void setUp() {
    eventLoopGroup = new NioEventLoopGroup();
    eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
    throughputCounter = new ThroughputCounter(eventLoopGroup);
    localRegistry = new LocalMetricRegistry();
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) EventLoopGroupFactory(org.graylog2.inputs.transports.netty.EventLoopGroupFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Before(org.junit.Before)

Example 18 with ThroughputCounter

use of org.graylog2.plugin.inputs.util.ThroughputCounter 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 19 with ThroughputCounter

use of org.graylog2.plugin.inputs.util.ThroughputCounter 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

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