Search in sources :

Example 11 with MessageOutput

use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.

the class OutputRouterTest method testGetMessageOutputsForEmptyStream.

@Test
public void testGetMessageOutputsForEmptyStream() throws Exception {
    final Stream stream = mock(Stream.class);
    final OutputRouter outputRouter = new OutputRouter(defaultMessageOutput, outputRegistry);
    final Collection<MessageOutput> messageOutputs = outputRouter.getMessageOutputsForStream(stream);
    assertEquals(messageOutputs.size(), 0);
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 12 with MessageOutput

use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.

the class OutputRouterTest method testGetMessageOutputsForStreamWithTwoOutputs.

@Test
public void testGetMessageOutputsForStreamWithTwoOutputs() throws Exception {
    final Stream stream = mock(Stream.class);
    final Output output1 = mock(Output.class);
    final Output output2 = mock(Output.class);
    final String output1Id = "foo";
    final String output2Id = "bar";
    final MessageOutput messageOutput1 = mock(MessageOutput.class);
    final MessageOutput messageOutput2 = mock(MessageOutput.class);
    final Set<Output> outputSet = ImmutableSet.of(output1, output2);
    when(stream.getOutputs()).thenReturn(outputSet);
    when(output1.getId()).thenReturn(output1Id);
    when(output2.getId()).thenReturn(output2Id);
    when(outputRegistry.getOutputForIdAndStream(eq(output1Id), eq(stream))).thenReturn(messageOutput1);
    when(outputRegistry.getOutputForIdAndStream(eq(output2Id), eq(stream))).thenReturn(messageOutput2);
    final OutputRouter outputRouter = new OutputRouter(defaultMessageOutput, outputRegistry);
    final Collection<MessageOutput> messageOutputs = outputRouter.getMessageOutputsForStream(stream);
    assertEquals(messageOutputs.size(), 2);
    assertTrue(messageOutputs.contains(messageOutput1));
    assertTrue(messageOutputs.contains(messageOutput2));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 13 with MessageOutput

use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.

the class OutputRouterTest method testGetOutputsWithIdenticalMessageOutputs.

@Test
public void testGetOutputsWithIdenticalMessageOutputs() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final MessageOutput messageOutput = mock(MessageOutput.class);
    final Set<MessageOutput> messageOutputSet = ImmutableSet.of(messageOutput);
    final Message message = mock(Message.class);
    when(message.getStreams()).thenReturn(ImmutableSet.of(stream1, stream2));
    OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
    doReturn(messageOutputSet).when(outputRouter).getMessageOutputsForStream(eq(stream1));
    doReturn(messageOutputSet).when(outputRouter).getMessageOutputsForStream(eq(stream2));
    final Collection<MessageOutput> result = outputRouter.getOutputsForMessage(message);
    assertEquals(result.size(), 2);
    assertTrue(result.contains(defaultMessageOutput));
    assertTrue(result.contains(messageOutput));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Message(org.graylog2.plugin.Message) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 14 with MessageOutput

use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.

the class OutputRouterTest method testGetMessageOutputsForSingleStream.

@Test
public void testGetMessageOutputsForSingleStream() throws Exception {
    final Stream stream = mock(Stream.class);
    final Output output = mock(Output.class);
    final String outputId = "foobar";
    final MessageOutput messageOutput = mock(MessageOutput.class);
    final Set<Output> outputSet = ImmutableSet.of(output);
    when(stream.getOutputs()).thenReturn(outputSet);
    when(output.getId()).thenReturn(outputId);
    when(outputRegistry.getOutputForIdAndStream(eq(outputId), eq(stream))).thenReturn(messageOutput);
    final OutputRouter outputRouter = new OutputRouter(defaultMessageOutput, outputRegistry);
    final Collection<MessageOutput> messageOutputs = outputRouter.getMessageOutputsForStream(stream);
    assertEquals(messageOutputs.size(), 1);
    assertTrue(messageOutputs.contains(messageOutput));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 15 with MessageOutput

use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.

the class OutputRouterTest method testAlwaysIncludeDefaultOutput.

@Test
public void testAlwaysIncludeDefaultOutput() throws Exception {
    final Message message = mock(Message.class);
    final OutputRouter outputRouter = new OutputRouter(defaultMessageOutput, outputRegistry);
    final Collection<MessageOutput> messageOutputs = outputRouter.getOutputsForMessage(message);
    assertEquals(messageOutputs.size(), 1);
    assertTrue(messageOutputs.contains(defaultMessageOutput));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Aggregations

MessageOutput (org.graylog2.plugin.outputs.MessageOutput)15 Test (org.junit.Test)10 Stream (org.graylog2.plugin.streams.Stream)9 Message (org.graylog2.plugin.Message)5 Configuration (org.graylog2.plugin.configuration.Configuration)2 Output (org.graylog2.plugin.streams.Output)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BlockingBatchedESOutput (org.graylog2.outputs.BlockingBatchedESOutput)1 DefaultMessageOutput (org.graylog2.outputs.DefaultMessageOutput)1 MessageOutputConfigurationException (org.graylog2.plugin.outputs.MessageOutputConfigurationException)1 AvailableOutputSummary (org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary)1