use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method removeSuccessfullyRemovesConfig.
@Test
public void removeSuccessfullyRemovesConfig() throws Exception {
DBObject dbObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get();
@SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
collection.save(dbObject);
assertThat(collection.count()).isEqualTo(1L);
assertThat(clusterConfigService.remove(CustomConfig.class)).isEqualTo(1);
assertThat(collection.count()).isEqualTo(0L);
}
use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method listReturnsAllClasses.
@Test
public void listReturnsAllClasses() throws Exception {
@SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
collection.save(new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get());
collection.save(new BasicDBObjectBuilder().add("type", AnotherCustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get());
assertThat(collection.count()).isEqualTo(2L);
assertThat(clusterConfigService.list()).hasSize(2).containsOnly(CustomConfig.class, AnotherCustomConfig.class);
}
use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method getReturnsNullOnInvalidPayload.
@Test
public void getReturnsNullOnInvalidPayload() throws Exception {
DBObject dbObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", "wrong payload").add("last_updated", TIME.toString()).add("last_updated_by", "ID").get();
@SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
collection.save(dbObject);
assertThat(collection.count()).isEqualTo(1L);
assertThat(clusterConfigService.get(CustomConfig.class)).isNull();
}
use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterEventPeriodicalTest method localEventIsNotProcessedFromDB.
@Test
public void localEventIsNotProcessedFromDB() {
DBObject event = new BasicDBObjectBuilder().add("timestamp", TIME.getMillis()).add("producer", "TEST-PRODUCER").add("consumers", Collections.singletonList(nodeId.toString())).add("event_class", SimpleEvent.class.getCanonicalName()).add("payload", ImmutableMap.of("payload", "test")).get();
@SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
collection.save(event);
clusterEventPeriodical.run();
verify(serverEventBus, never()).post(any());
verify(clusterEventBus, never()).post(any());
}
use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterEventPeriodicalTest method serverEventBusDispatchesTypedEvents.
@Test
public void serverEventBusDispatchesTypedEvents() throws Exception {
final SimpleEventHandler handler = new SimpleEventHandler();
serverEventBus.register(handler);
DBObject event = new BasicDBObjectBuilder().add("timestamp", TIME.getMillis()).add("producer", "TEST-PRODUCER").add("consumers", Collections.emptyList()).add("event_class", SimpleEvent.class.getCanonicalName()).add("payload", ImmutableMap.of("payload", "test")).get();
@SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(ClusterEventPeriodical.COLLECTION_NAME);
assertThat(collection.count()).isEqualTo(0L);
assertThat(collection.save(event).wasAcknowledged()).isTrue();
assertThat(collection.count()).isEqualTo(1L);
assertThat(handler.invocations).hasValue(0);
clusterEventPeriodical.run();
assertThat(handler.invocations).hasValue(1);
assertThat(collection.count()).isEqualTo(1L);
@SuppressWarnings("unchecked") final List<String> consumers = (List<String>) collection.findOne().get("consumers");
assertThat(consumers).containsExactly(nodeId.toString());
verify(serverEventBus, times(1)).post(any(SimpleEvent.class));
verify(clusterEventBus, never()).post(any());
}
Aggregations