use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class UserServiceImpl method loadAllForRole.
@Override
public Collection<User> loadAllForRole(Role role) {
final String roleId = role.getId();
final DBObject query = BasicDBObjectBuilder.start(UserImpl.ROLES, new ObjectId(roleId)).get();
final List<DBObject> result = query(UserImpl.class, query);
if (result == null || result.isEmpty()) {
return Collections.emptySet();
}
final Set<User> users = Sets.newHashSetWithExpectedSize(result.size());
for (DBObject dbObject : result) {
//noinspection unchecked
users.add(userFactory.create((ObjectId) dbObject.get("_id"), dbObject.toMap()));
}
return users;
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class AlarmCallbackHistoryServiceImplTest method testError.
@Test
public void testError() throws Exception {
final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(new Date());
final Alert alert = mockAlert();
final AlertCondition alertCondition = mockAlertCondition();
final String errorMessage = "Dummy Error Message";
final AlarmCallbackHistory alarmCallbackHistory = this.alarmCallbackHistoryService.error(alarmCallbackConfiguration, alert, alertCondition, errorMessage);
verifyAlarmCallbackHistory(alarmCallbackHistory, alert, alertCondition);
assertThat(alarmCallbackHistory.result()).isNotNull().isInstanceOf(AlarmCallbackError.class);
assertThat(alarmCallbackHistory.result().type()).isEqualTo("error");
final AlarmCallbackError result = (AlarmCallbackError) alarmCallbackHistory.result();
assertThat(result.error()).isEqualTo(errorMessage);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class GelfChunkAggregatorTest method missingChunk.
@Test
public void missingChunk() {
final DateTime initialTime = new DateTime(2014, 1, 1, 1, 59, 59, 0, DateTimeZone.UTC);
final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
DateTimeUtils.setCurrentMillisProvider(clock);
// we don't want the clean up task to run automatically
poolExecutor = mock(ScheduledThreadPoolExecutor.class);
final MetricRegistry metricRegistry = new MetricRegistry();
aggregator = new GelfChunkAggregator(poolExecutor, metricRegistry);
final GelfChunkAggregator.ChunkEvictionTask evictionTask = aggregator.new ChunkEvictionTask();
// creates 5 chunks
final ChannelBuffer[] chunks = createChunkedMessage(4096 + 512, 1024);
int i = 0;
for (final ChannelBuffer chunk : chunks) {
final CodecAggregator.Result result;
// skip first chunk
if (i++ == 0) {
continue;
}
result = aggregator.addChunk(chunk);
assertTrue(result.isValid());
assertNull("chunks not complete", result.getMessage());
}
// move clock forward enough to evict all of the chunks
clock.tick(Period.seconds(10));
evictionTask.run();
final CodecAggregator.Result result = aggregator.addChunk(chunks[0]);
assertNull("message should not be complete because chunks were evicted already", result.getMessage());
assertTrue(result.isValid());
// we send all chunks but the last one comes too late
assertEquals("no message is complete", 0, counterValueNamed(metricRegistry, COMPLETE_MESSAGES));
assertEquals("received 5 chunks", 5, counterValueNamed(metricRegistry, CHUNK_COUNTER));
assertEquals("last chunk creates another waiting message", 1, counterValueNamed(metricRegistry, WAITING_MESSAGES));
assertEquals("4 chunks expired", 4, counterValueNamed(metricRegistry, EXPIRED_CHUNKS));
assertEquals("one message expired", 1, counterValueNamed(metricRegistry, EXPIRED_MESSAGES));
assertEquals("no duplicate chunks", 0, counterValueNamed(metricRegistry, DUPLICATE_CHUNKS));
// reset clock for other tests
DateTimeUtils.setCurrentMillisSystem();
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class SearchesTest method testCount.
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testCount() throws Exception {
CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
assertThat(result.count()).isEqualTo(10L);
}
use of org.graylog2.plugin.inputs.Extractor.Result in project graylog2-server by Graylog2.
the class SearchesTest method testTermsAscending.
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTermsAscending() throws Exception {
TermsResult result = searches.terms("n", 1, "*", null, AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), Sorting.Direction.ASC);
assertThat(result.getTotal()).isEqualTo(10L);
assertThat(result.getMissing()).isEqualTo(2L);
assertThat(result.getTerms()).hasSize(1).containsEntry("4", 1L);
}
Aggregations