Search in sources :

Example 1 with NettyTransportConfiguration

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

the class NetFlowUdpTransportTest method setUp.

@Before
public void setUp() {
    final NettyTransportConfiguration nettyTransportConfiguration = new NettyTransportConfiguration("nio", "jdk", 1);
    eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
    eventLoopGroup = new NioEventLoopGroup(1);
    transport = new NetFlowUdpTransport(Configuration.EMPTY_CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, new ThroughputCounter(eventLoopGroup), new LocalMetricRegistry());
    transport.setMessageAggregator(new NetflowV9CodecAggregator());
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) NetflowV9CodecAggregator(org.graylog.plugins.netflow.codecs.NetflowV9CodecAggregator) EventLoopGroupFactory(org.graylog2.inputs.transports.netty.EventLoopGroupFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Before(org.junit.Before)

Example 2 with NettyTransportConfiguration

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

the class BeatsTransportTest method customChildChannelHandlersContainBeatsHandler.

@Test
public void customChildChannelHandlersContainBeatsHandler() {
    final NettyTransportConfiguration nettyTransportConfiguration = new NettyTransportConfiguration("nio", "jdk", 1);
    final EventLoopGroupFactory eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
    final BeatsTransport transport = new BeatsTransport(Configuration.EMPTY_CONFIGURATION, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, new ThroughputCounter(eventLoopGroup), new LocalMetricRegistry(), tlsConfiguration);
    final MessageInput input = mock(MessageInput.class);
    assertThat(transport.getCustomChildChannelHandlers(input)).containsKey("beats");
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) MessageInput(org.graylog2.plugin.inputs.MessageInput) EventLoopGroupFactory(org.graylog2.inputs.transports.netty.EventLoopGroupFactory) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Test(org.junit.Test)

Example 3 with NettyTransportConfiguration

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

the class AbstractTcpTransportTest method getChildChannelHandlersFailsIfTempDirIsNoDirectory.

@Test
public void getChildChannelHandlersFailsIfTempDirIsNoDirectory() throws IOException {
    final File file = temporaryFolder.newFile();
    assumeTrue(file.isFile());
    System.setProperty("java.io.tmpdir", file.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: " + file.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 4 with NettyTransportConfiguration

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

the class AbstractTcpTransportTest method testTrafficCounter.

@Test
@Ignore("Disabled test due to being unreliable. For details see https://github.com/Graylog2/graylog2-server/issues/4702.")
public void testTrafficCounter() 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 channelFuture = clientChannel(localAddress.getHostString(), localAddress.getPort());
    channelFuture.channel().writeAndFlush(Unpooled.copiedBuffer(new byte[1024])).syncUninterruptibly();
    channelFuture.channel().writeAndFlush(Unpooled.copiedBuffer(new byte[1024])).addListener(ChannelFutureListener.CLOSE).syncUninterruptibly();
    // Wait 1s so that the cumulative throughput can be calculated
    Thread.sleep(1000L);
    assertThat(throughputCounter.gauges().get(ThroughputCounter.READ_BYTES_TOTAL).getValue()).isEqualTo(2048L);
    assertThat(throughputCounter.gauges().get(ThroughputCounter.READ_BYTES_1_SEC).getValue()).isEqualTo(2048L);
}
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)

Example 5 with NettyTransportConfiguration

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

the class UdpTransportTest method setUp.

@Before
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void setUp() throws Exception {
    eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
    localMetricRegistry = new LocalMetricRegistry();
    eventLoopGroup = eventLoopGroupFactory.create(1, localMetricRegistry, "test");
    throughputCounter = new ThroughputCounter(eventLoopGroup);
    udpTransport = new UdpTransport(CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, localMetricRegistry);
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) EventLoopGroupFactory(org.graylog2.inputs.transports.netty.EventLoopGroupFactory) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

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