use of org.graylog2.inputs.InputService in project graylog2-server by Graylog2.
the class InputFacadeTest method setUp.
@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() throws Exception {
final MetricRegistry metricRegistry = new MetricRegistry();
final ClusterEventBus clusterEventBus = new ClusterEventBus("cluster-event-bus", Executors.newSingleThreadExecutor());
final GrokPatternService grokPatternService = new InMemoryGrokPatternService(clusterEventBus);
grokPatternService.save(GrokPattern.create("GREEDY", ".*"));
final EventBus clusterBus = new EventBus();
final GrokPatternRegistry grokPatternRegistry = new GrokPatternRegistry(clusterBus, grokPatternService, Executors.newScheduledThreadPool(1));
final ExtractorFactory extractorFactory = new ExtractorFactory(metricRegistry, grokPatternRegistry, lookupTableService);
final ConverterFactory converterFactory = new ConverterFactory(lookupTableService);
inputService = new InputServiceImpl(mongodb.mongoConnection(), extractorFactory, converterFactory, messageInputFactory, clusterEventBus);
final InputRegistry inputRegistry = new InputRegistry();
Set<PluginMetaData> pluginMetaData = new HashSet<>();
Map<String, MessageInput.Factory<? extends MessageInput>> inputFactories = new HashMap<>();
final FakeHttpMessageInput.Factory fakeHttpMessageInputFactory = mock(FakeHttpMessageInput.Factory.class);
final FakeHttpMessageInput.Descriptor fakeHttpMessageInputDescriptor = mock(FakeHttpMessageInput.Descriptor.class);
when(fakeHttpMessageInputFactory.getDescriptor()).thenReturn(fakeHttpMessageInputDescriptor);
final RawUDPInput.Factory rawUDPInputFactory = mock(RawUDPInput.Factory.class);
final RawUDPInput.Descriptor rawUDPInputDescriptor = mock(RawUDPInput.Descriptor.class);
when(rawUDPInputFactory.getDescriptor()).thenReturn(rawUDPInputDescriptor);
inputFactories.put("org.graylog2.inputs.random.FakeHttpMessageInput", fakeHttpMessageInputFactory);
inputFactories.put("org.graylog2.inputs.raw.udp.RawUDPInput", rawUDPInputFactory);
facade = new InputFacade(objectMapper, inputService, inputRegistry, dbLookupTableService, grokPatternService, messageInputFactory, extractorFactory, converterFactory, serverStatus, pluginMetaData, inputFactories);
}
use of org.graylog2.inputs.InputService in project graylog2-server by Graylog2.
the class ExtractorFilterTest method testFailureHandling.
@Test
void testFailureHandling() throws NotFoundException {
final Input input = mock(Input.class);
when(input.getId()).thenReturn("123");
when(inputService.all()).thenReturn(ImmutableList.of(input));
final Extractor extractor = buildExceptionalExtractor();
when(extractor.getTitle()).thenReturn("failing extractor");
when(extractor.getId()).thenReturn("888");
when(inputService.getExtractors(any())).thenReturn(ImmutableList.of(extractor));
// extractors are initialized within constructor
dut = new ExtractorFilter(inputService, eventBus, executorService);
final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
message.setSourceInputId("123");
dut.filter(message);
assertThat(message.processingErrors()).hasSize(1);
assertThat(message.processingErrors().get(0)).satisfies(pe -> {
assertThat(pe.getCause()).isEqualTo(ProcessingFailureCause.ExtractorException);
assertThat(pe.getMessage()).isEqualTo("Could not apply extractor <failing extractor(888)>");
assertThat(pe.getDetails()).isEqualTo("EIEIO!");
});
}
use of org.graylog2.inputs.InputService in project graylog2-server by Graylog2.
the class StaticFieldFilterTest method testFilter.
@Test
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void testFilter() throws Exception {
Message msg = new Message("hello", "junit", Tools.nowUTC());
msg.setSourceInputId("someid");
when(input.getId()).thenReturn("someid");
when(inputService.all()).thenReturn(Collections.singletonList(input));
when(inputService.find(eq("someid"))).thenReturn(input);
when(inputService.getStaticFields(eq(input))).thenReturn(Collections.singletonList(Maps.immutableEntry("foo", "bar")));
final StaticFieldFilter filter = new StaticFieldFilter(inputService, new EventBus(), Executors.newSingleThreadScheduledExecutor());
filter.filter(msg);
assertEquals("hello", msg.getMessage());
assertEquals("junit", msg.getSource());
assertEquals("bar", msg.getField("foo"));
}
use of org.graylog2.inputs.InputService in project graylog2-server by Graylog2.
the class MongoInputStatusServiceTest method setUp.
@Before
public void setUp() {
final ObjectMapper objectMapper = new ObjectMapperProvider().get();
final MongoJackObjectMapperProvider mapperProvider = new MongoJackObjectMapperProvider(objectMapper);
cut = new MongoInputStatusService(mongodb.mongoConnection(), mapperProvider, inputService, mockEventBus);
db = JacksonDBCollection.wrap(mongodb.mongoConnection().getDatabase().getCollection(MongoInputStatusService.COLLECTION_NAME), InputStatusRecord.class, ObjectId.class, mapperProvider.get());
}
use of org.graylog2.inputs.InputService in project graylog2-server by Graylog2.
the class InputServiceImplTest method setUp.
@Before
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void setUp() throws Exception {
clusterEventBus = new ClusterEventBus("inputs-test", Executors.newSingleThreadExecutor());
inputService = new InputServiceImpl(mongodb.mongoConnection(), extractorFactory, converterFactory, messageInputFactory, clusterEventBus);
}
Aggregations