Search in sources :

Example 11 with ThroughputCounter

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

Example 12 with ThroughputCounter

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

the class UdpTransportTest method launchTransportForBootStrapTest.

private UdpTransport launchTransportForBootStrapTest(final ChannelInboundHandler channelHandler) throws MisfireException {
    final UdpTransport transport = new UdpTransport(CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, new LocalMetricRegistry()) {

        @Override
        protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChannelHandlers(MessageInput input) {
            final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
            handlers.put("logging", () -> new LoggingHandler(LogLevel.INFO));
            handlers.put("counter", () -> channelHandler);
            handlers.putAll(super.getChannelHandlers(input));
            return handlers;
        }
    };
    final MessageInput messageInput = mock(MessageInput.class);
    when(messageInput.getId()).thenReturn("TEST");
    when(messageInput.getName()).thenReturn("TEST");
    transport.launch(messageInput);
    return transport;
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(io.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with ThroughputCounter

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

the class UdpTransportTest method receiveBufferSizeIsNotLimited.

@Test
public void receiveBufferSizeIsNotLimited() {
    final int recvBufferSize = Ints.saturatedCast(Size.megabytes(1L).toBytes());
    ImmutableMap<String, Object> source = ImmutableMap.of(NettyTransport.CK_BIND_ADDRESS, BIND_ADDRESS, NettyTransport.CK_PORT, PORT, NettyTransport.CK_RECV_BUFFER_SIZE, recvBufferSize);
    Configuration config = new Configuration(source);
    UdpTransport udpTransport = new UdpTransport(config, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, new LocalMetricRegistry());
    assertThat(udpTransport.getBootstrap(mock(MessageInput.class)).config().options().get(ChannelOption.SO_RCVBUF)).isEqualTo(recvBufferSize);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Test(org.junit.Test)

Example 14 with ThroughputCounter

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

the class UdpTransportTest method launchTransportForBootStrapTest.

private UdpTransport launchTransportForBootStrapTest(final ChannelHandler channelHandler) throws MisfireException {
    final UdpTransport transport = new UdpTransport(CONFIGURATION, throughputCounter, new LocalMetricRegistry()) {

        @Override
        protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
            final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
            handlers.put("counter", Callables.returning(channelHandler));
            handlers.putAll(super.getFinalChannelHandlers(input));
            return handlers;
        }
    };
    final MessageInput messageInput = mock(MessageInput.class);
    when(messageInput.getId()).thenReturn("TEST");
    when(messageInput.getName()).thenReturn("TEST");
    transport.launch(messageInput);
    return transport;
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(org.jboss.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with ThroughputCounter

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

the class AbstractTcpTransportTest method getChildChannelHandlersGeneratesSelfSignedCertificates.

@Test
public void getChildChannelHandlersGeneratesSelfSignedCertificates() {
    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) {
    };
    final MessageInput input = mock(MessageInput.class);
    assertThat(transport.getChildChannelHandlers(input)).containsKey("tls");
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) MessageInput(org.graylog2.plugin.inputs.MessageInput) 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