use of org.graylog2.Configuration 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);
}
use of org.graylog2.Configuration 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);
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class MessageOutputFactoryTest method testNonExistentOutputType.
@Test(expected = IllegalArgumentException.class)
public void testNonExistentOutputType() throws MessageOutputConfigurationException {
final String outputType = "non.existent";
final Output output = mock(Output.class);
when(output.getType()).thenReturn(outputType);
final Stream stream = mock(Stream.class);
final Configuration configuration = mock(Configuration.class);
messageOutputFactory.fromStreamOutput(output, stream, configuration);
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class InputFacadeTest method createNativeEntity.
@Test
@Ignore("Doesn't work without massive amount of mocks")
public void createNativeEntity() {
final Map<String, Object> configuration = new HashMap<>();
configuration.put("override_source", null);
configuration.put("recv_buffer_size", 262144);
configuration.put("bind_address", "127.0.0.1");
configuration.put("port", 5555);
configuration.put("number_worker_threads", 8);
final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
final NativeEntity<InputWithExtractors> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
final InputWithExtractors inputWithExtractors = nativeEntity.entity();
final Input savedInput = inputWithExtractors.input();
final String savedId = savedInput.getId();
assertThat(nativeEntity.descriptor()).isEqualTo(EntityDescriptor.create(savedId, ModelTypes.INPUT_V1));
assertThat(savedInput.getTitle()).isEqualTo("Local Raw UDP");
assertThat(savedInput.getType()).isEqualTo("org.graylog2.inputs.raw.udp.RawUDPInput");
assertThat(savedInput.isGlobal()).isFalse();
assertThat(savedInput.getContentPack()).isNull();
}
use of org.graylog2.Configuration 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);
}
Aggregations