Search in sources :

Example 16 with BasicDBObjectBuilder

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);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 17 with BasicDBObjectBuilder

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);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) Test(org.junit.Test)

Example 18 with BasicDBObjectBuilder

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();
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 19 with BasicDBObjectBuilder

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());
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 20 with BasicDBObjectBuilder

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());
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) BasicDBList(com.mongodb.BasicDBList) List(java.util.List) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)44 DBObject (com.mongodb.DBObject)30 Test (org.junit.Test)21 DBCollection (com.mongodb.DBCollection)18 BasicDBObject (com.mongodb.BasicDBObject)12 ArrayList (java.util.ArrayList)7 BasicDBList (com.mongodb.BasicDBList)6 List (java.util.List)4 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)4 HiveTest (com.mongodb.hadoop.hive.HiveTest)3 IOException (java.io.IOException)3 Map (java.util.Map)3 MongoException (com.mongodb.MongoException)2 Configuration (org.apache.hadoop.conf.Configuration)2 JobConf (org.apache.hadoop.mapred.JobConf)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 ResourceSchema (org.apache.pig.ResourceSchema)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 BasicBSONObject (org.bson.BasicBSONObject)2 GeometryType (org.teiid.core.types.GeometryType)2