use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.
the class MongoStorageTest method testMap.
@Test
public void testMap() throws Exception {
MongoStorage ms = new MongoStorage();
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
ResourceSchema schema = new ResourceSchema(Utils.getSchemaFromString("m:map[]"));
Map<String, Object> val = new HashMap<String, Object>();
val.put("f1", 1);
val.put("f2", "2");
ms.writeField(builder, schema.getFields()[0], val);
DBObject out = builder.get();
Set<String> outKeySet = out.keySet();
assertEquals(2, outKeySet.size());
assertEquals(1, out.get("f1"));
assertEquals("2", out.get("f2"));
}
use of com.mongodb.BasicDBObjectBuilder in project mongo-hadoop by mongodb.
the class MongoStorage method putNext.
public void putNext(final Tuple tuple) throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("writing " + tuple.toString());
}
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
ResourceFieldSchema[] fields = this.schema.getFields();
for (int i = 0; i < fields.length; i++) {
writeField(builder, fields[i], tuple.get(i));
}
if (LOG.isDebugEnabled()) {
LOG.debug("writing out:" + builder.get().toString());
}
// noinspection unchecked
recordWriter.write(null, builder.get());
}
use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method getReturnsExistingConfig.
@Test
public void getReturnsExistingConfig() 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);
CustomConfig customConfig = clusterConfigService.get(CustomConfig.class);
assertThat(customConfig.text).isEqualTo("TEST");
}
use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method writeUpdatesExistingClusterConfig.
@Test
public void writeUpdatesExistingClusterConfig() throws Exception {
CustomConfig customConfig = new CustomConfig();
customConfig.text = "TEST";
DBObject seedObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "ORIGINAL")).add("last_updated", TIME.toString()).add("last_updated_by", "NOT ID").get();
@SuppressWarnings("deprecation") final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
collection.save(seedObject);
assertThat(collection.count()).isEqualTo(1L);
clusterConfigService.write(customConfig);
assertThat(collection.count()).isEqualTo(1L);
DBObject dbObject = collection.findOne();
assertThat((String) dbObject.get("type")).isEqualTo(CustomConfig.class.getCanonicalName());
assertThat((String) dbObject.get("last_updated_by")).isEqualTo("ID");
@SuppressWarnings("unchecked") Map<String, Object> payload = (Map<String, Object>) dbObject.get("payload");
assertThat(payload).containsEntry("text", "TEST");
}
use of com.mongodb.BasicDBObjectBuilder in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method getWithKeyReturnsExistingConfig.
@Test
public void getWithKeyReturnsExistingConfig() throws Exception {
DBObject dbObject = new BasicDBObjectBuilder().add("type", "foo").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);
CustomConfig customConfig = clusterConfigService.get("foo", CustomConfig.class);
assertThat(customConfig).isInstanceOf(CustomConfig.class);
assertThat(customConfig.text).isEqualTo("TEST");
}
Aggregations