Search in sources :

Example 76 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class SearchesTest method fieldStatsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void fieldStatsRecordsMetrics() throws Exception {
    FieldStatsResult result = searches.fieldStats("n", "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 77 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class SearchesTest method termsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void termsRecordsMetrics() throws Exception {
    TermsResult result = searches.terms("n", 25, "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) TermsResult(org.graylog2.indexer.results.TermsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 78 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class StreamRouterEngineTest method testAndStreamWithMultipleRules.

@Test
public void testAndStreamWithMultipleRules() {
    final String dummyField = "dummyField";
    final String dummyValue = "dummyValue";
    final StreamRule streamRule1 = getStreamRuleMock("StreamRule1Id", StreamRuleType.EXACT, dummyField, dummyValue);
    final StreamRule streamRule2 = getStreamRuleMock("StreamRule2Id", StreamRuleType.EXACT, dummyField, dummyValue);
    final Stream stream = mock(Stream.class);
    when(stream.getId()).thenReturn("Stream1Id");
    when(stream.getMatchingType()).thenReturn(Stream.MatchingType.OR);
    when(stream.getStreamRules()).thenReturn(Lists.newArrayList(streamRule1, streamRule2));
    final Message message = mock(Message.class);
    when(message.getField(eq(dummyField))).thenReturn(dummyValue);
    final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
    final List<Stream> result = engine.match(message);
    assertThat(result).hasSize(1);
    assertThat(result).contains(stream);
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 79 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class StreamRouterEngineTest method testOrMatching.

@Test
public void testOrMatching() {
    final String dummyField = "dummyField";
    final String dummyValue = "dummyValue";
    final Stream stream = mock(Stream.class);
    when(stream.getMatchingType()).thenReturn(Stream.MatchingType.OR);
    final StreamRule streamRule1 = getStreamRuleMock("StreamRule1Id", StreamRuleType.EXACT, dummyField, dummyValue);
    final StreamRule streamRule2 = getStreamRuleMock("StreamRule2Id", StreamRuleType.EXACT, dummyField, "not" + dummyValue);
    when(stream.getStreamRules()).thenReturn(Lists.newArrayList(streamRule1, streamRule2));
    final Message message = mock(Message.class);
    when(message.getField(eq(dummyField))).thenReturn(dummyValue);
    final StreamRouterEngine engine = newEngine(Lists.newArrayList(stream));
    final List<Stream> result = engine.match(message);
    assertThat(result).hasSize(1);
    assertThat(result).contains(stream);
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 80 with Result

use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.

the class StreamRouterEngineTest method getStreamRuleMock.

private StreamRule getStreamRuleMock(String id, StreamRuleType type, String field, String value) {
    final StreamRule result = mock(StreamRule.class);
    when(result.getId()).thenReturn(id);
    when(result.getType()).thenReturn(type);
    when(result.getField()).thenReturn(field);
    when(result.getValue()).thenReturn(value);
    return result;
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule)

Aggregations

Test (org.junit.Test)73 Message (org.graylog2.plugin.Message)51 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 Stream (org.graylog2.plugin.streams.Stream)20 StreamRule (org.graylog2.plugin.streams.StreamRule)19 DateTime (org.joda.time.DateTime)18 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)12 ApiResponses (io.swagger.annotations.ApiResponses)11 Produces (javax.ws.rs.Produces)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 Function (com.google.common.base.Function)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)8 ZonedDateTime (java.time.ZonedDateTime)8 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)8 Sorting (org.graylog2.indexer.searches.Sorting)8 URI (java.net.URI)7 MessageSummary (org.graylog2.plugin.MessageSummary)7