Search in sources :

Example 6 with DefaultMessageOutput

use of org.graylog2.outputs.DefaultMessageOutput 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 7 with DefaultMessageOutput

use of org.graylog2.outputs.DefaultMessageOutput 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 8 with DefaultMessageOutput

use of org.graylog2.outputs.DefaultMessageOutput 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)8 Test (org.junit.Test)7 Stream (org.graylog2.plugin.streams.Stream)6 Message (org.graylog2.plugin.Message)5 Output (org.graylog2.plugin.streams.Output)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 DefaultMessageOutput (org.graylog2.outputs.DefaultMessageOutput)1