Search in sources :

Example 1 with MongoCollectionType

use of org.apache.rya.mongodb.batch.collection.MongoCollectionType in project incubator-rya by apache.

the class MongoDBRyaBatchWriterIT method testMongoCollectionFlush.

@Test
public void testMongoCollectionFlush() throws Exception {
    final MongoDBStorageStrategy<RyaStatement> storageStrategy = new SimpleMongoDBStorageStrategy();
    final List<Document> documents = Lists.newArrayList(toDocument(storageStrategy.serialize(statement(1))), toDocument(storageStrategy.serialize(statement(2))), toDocument(storageStrategy.serialize(statement(2))), null, toDocument(storageStrategy.serialize(statement(3))), toDocument(storageStrategy.serialize(statement(3))), toDocument(storageStrategy.serialize(statement(4))));
    final MongoCollectionType mongoCollectionType = new MongoCollectionType(getRyaCollection());
    final MongoDbBatchWriterConfig mongoDbBatchWriterConfig = MongoDbBatchWriterUtils.getMongoDbBatchWriterConfig(conf);
    final MongoDbBatchWriter<Document> mongoDbBatchWriter = new MongoDbBatchWriter<>(mongoCollectionType, mongoDbBatchWriterConfig);
    mongoDbBatchWriter.start();
    mongoDbBatchWriter.addObjectsToQueue(documents);
    mongoDbBatchWriter.flush();
    Thread.sleep(1_000);
    mongoDbBatchWriter.addObjectsToQueue(documents);
    mongoDbBatchWriter.flush();
    Thread.sleep(1_000);
    mongoDbBatchWriter.shutdown();
    assertEquals(4, getRyaCollection().count());
}
Also used : MongoDbBatchWriter(org.apache.rya.mongodb.batch.MongoDbBatchWriter) RyaStatement(org.apache.rya.api.domain.RyaStatement) MongoDbBatchWriterConfig(org.apache.rya.mongodb.batch.MongoDbBatchWriterConfig) Document(org.bson.Document) SimpleMongoDBStorageStrategy(org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy) MongoCollectionType(org.apache.rya.mongodb.batch.collection.MongoCollectionType) Test(org.junit.Test)

Aggregations

RyaStatement (org.apache.rya.api.domain.RyaStatement)1 MongoDbBatchWriter (org.apache.rya.mongodb.batch.MongoDbBatchWriter)1 MongoDbBatchWriterConfig (org.apache.rya.mongodb.batch.MongoDbBatchWriterConfig)1 MongoCollectionType (org.apache.rya.mongodb.batch.collection.MongoCollectionType)1 SimpleMongoDBStorageStrategy (org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy)1 Document (org.bson.Document)1 Test (org.junit.Test)1