use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.
the class MessageOutputFactory method getAvailableOutputs.
public Map<String, AvailableOutputSummary> getAvailableOutputs() {
final Map<String, AvailableOutputSummary> result = new HashMap<>(availableOutputs.size());
for (Map.Entry<String, MessageOutput.Factory<? extends MessageOutput>> messageOutputEntry : this.availableOutputs.entrySet()) {
final MessageOutput.Factory messageOutputFactoryClass = messageOutputEntry.getValue();
final MessageOutput.Descriptor descriptor = messageOutputFactoryClass.getDescriptor();
final AvailableOutputSummary availableOutputSummary = AvailableOutputSummary.create(descriptor.getName(), messageOutputEntry.getKey(), descriptor.getHumanName(), descriptor.getLinkToDocs(), messageOutputFactoryClass.getConfig().getRequestedConfiguration());
result.put(messageOutputEntry.getKey(), availableOutputSummary);
}
return result;
}
use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.
the class OutputRouterTest method testGetOutputsFromTwoStreams.
@Test
public void testGetOutputsFromTwoStreams() throws Exception {
final Stream stream1 = mock(Stream.class);
final Stream stream2 = mock(Stream.class);
final MessageOutput messageOutput1 = mock(MessageOutput.class);
final Set<MessageOutput> messageOutputSet1 = ImmutableSet.of(messageOutput1);
final MessageOutput messageOutput2 = mock(MessageOutput.class);
final Set<MessageOutput> messageOutputSet2 = ImmutableSet.of(messageOutput2);
final Message message = mock(Message.class);
when(message.getStreams()).thenReturn(ImmutableSet.of(stream1, stream2));
OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
doReturn(messageOutputSet1).when(outputRouter).getMessageOutputsForStream(eq(stream1));
doReturn(messageOutputSet2).when(outputRouter).getMessageOutputsForStream(eq(stream2));
final Collection<MessageOutput> result = outputRouter.getOutputsForMessage(message);
assertEquals(result.size(), 3);
assertTrue(result.contains(defaultMessageOutput));
assertTrue(result.contains(messageOutput1));
assertTrue(result.contains(messageOutput2));
}
use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.
the class OutputRouterTest method testGetOutputFromSingleStreams.
@Test
public void testGetOutputFromSingleStreams() throws Exception {
final Stream stream = mock(Stream.class);
final Message message = mock(Message.class);
when(message.getStreams()).thenReturn(ImmutableSet.of(stream));
final MessageOutput messageOutput = mock(MessageOutput.class);
final Set<MessageOutput> messageOutputList = ImmutableSet.of(messageOutput);
final OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
doReturn(messageOutputList).when(outputRouter).getMessageOutputsForStream(eq(stream));
// Call to test
final Collection<MessageOutput> messageOutputs = outputRouter.getOutputsForMessage(message);
// Verification
assertEquals(messageOutputs.size(), 2);
assertTrue(messageOutputs.contains(defaultMessageOutput));
assertTrue(messageOutputs.contains(messageOutput));
}
use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.
the class OutputRegistryTest method testNonExistingInput.
@Test
public void testNonExistingInput() throws Exception {
final String outputId = "foobar";
final Stream stream = mock(Stream.class);
when(outputService.load(eq(outputId))).thenThrow(NotFoundException.class);
final OutputRegistry outputRegistry = new OutputRegistry(null, outputService, null, null, null, FAULT_COUNT_THRESHOLD, FAULT_PENALTY_SECONDS);
MessageOutput messageOutput = outputRegistry.getOutputForIdAndStream(outputId, stream);
assertNull(messageOutput);
assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
}
use of org.graylog2.plugin.outputs.MessageOutput in project graylog2-server by Graylog2.
the class OutputRegistryTest method testInvalidOutputConfiguration.
@Test
public void testInvalidOutputConfiguration() throws Exception {
final String outputId = "foobar";
final Stream stream = mock(Stream.class);
when(messageOutputFactory.fromStreamOutput(eq(output), any(Stream.class), any(Configuration.class))).thenThrow(new MessageOutputConfigurationException());
when(outputService.load(eq(outputId))).thenReturn(output);
final OutputRegistry outputRegistry = new OutputRegistry(null, outputService, messageOutputFactory, null, null, FAULT_COUNT_THRESHOLD, FAULT_PENALTY_SECONDS);
assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
MessageOutput result = outputRegistry.getOutputForIdAndStream(outputId, stream);
assertNull(result);
assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
}
Aggregations