Search in sources :

Example 1 with OakFongo

use of com.mongodb.OakFongo in project jackrabbit-oak by apache.

the class MongoCacheConsistencyTest method getFixture.

@Override
public DocumentStoreFixture getFixture() throws Exception {
    Fongo fongo = new OakFongo("fongo") {

        private String suppressedEx = null;

        @Override
        protected void afterInsert(WriteResult result) {
            maybeThrow();
        }

        @Override
        protected void afterFindAndModify(DBObject result) {
            maybeThrow();
        }

        @Override
        protected void afterUpdate(WriteResult result) {
            maybeThrow();
        }

        @Override
        protected void afterRemove(WriteResult result) {
            maybeThrow();
        }

        @Override
        protected void beforeExecuteBulkWriteOperation(boolean ordered, Boolean bypassDocumentValidation, List<?> writeRequests, WriteConcern aWriteConcern) {
            // suppress potentially set exception message because
            // fongo bulk writes call other update methods
            suppressedEx = exceptionMsg;
            exceptionMsg = null;
        }

        @Override
        protected void afterExecuteBulkWriteOperation(BulkWriteResult result) {
            exceptionMsg = suppressedEx;
            suppressedEx = null;
            maybeThrow();
        }

        private void maybeThrow() {
            if (exceptionMsg != null) {
                throw new MongoException(exceptionMsg);
            }
        }
    };
    DocumentMK.Builder builder = provider.newBuilder().setAsyncDelay(0);
    final DocumentStore store = new MongoDocumentStore(fongo.getMongo(), "oak", builder);
    return new DocumentStoreFixture() {

        @Override
        public String getName() {
            return "MongoDB";
        }

        @Override
        public DocumentStore createDocumentStore(DocumentMK.Builder builder) {
            return store;
        }
    };
}
Also used : Fongo(com.github.fakemongo.Fongo) OakFongo(com.mongodb.OakFongo) MongoException(com.mongodb.MongoException) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) OakFongo(com.mongodb.OakFongo) DBObject(com.mongodb.DBObject) BulkWriteResult(com.mongodb.BulkWriteResult) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) WriteResult(com.mongodb.WriteResult) BulkWriteResult(com.mongodb.BulkWriteResult) DocumentStoreFixture(org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture) WriteConcern(com.mongodb.WriteConcern) List(java.util.List)

Example 2 with OakFongo

use of com.mongodb.OakFongo in project jackrabbit-oak by apache.

the class MongoDBExceptionTest method before.

@Before
public void before() throws Exception {
    OakFongo fongo = new OakFongo("fongo") {

        @Override
        protected void beforeExecuteBulkWriteOperation(boolean ordered, Boolean bypassDocumentValidation, List<?> writeRequests, WriteConcern aWriteConcern) {
            maybeThrow();
        }

        @Override
        protected void beforeFindAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert) {
            maybeThrow();
        }

        @Override
        protected void beforeUpdate(DBObject q, DBObject o, boolean upsert, boolean multi, WriteConcern concern, DBEncoder encoder) {
            maybeThrow();
        }

        @Override
        protected void beforeFind(DBObject query, DBObject projection) {
            maybeThrow();
        }

        private void maybeThrow() {
            if (exceptionMsg != null) {
                throw new MongoException(exceptionMsg);
            }
        }
    };
    store = new MongoDocumentStore(fongo.getMongo(), "oak", new DocumentMK.Builder());
}
Also used : MongoException(com.mongodb.MongoException) WriteConcern(com.mongodb.WriteConcern) OakFongo(com.mongodb.OakFongo) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DBEncoder(com.mongodb.DBEncoder) DBObject(com.mongodb.DBObject) Before(org.junit.Before)

Aggregations

DBObject (com.mongodb.DBObject)2 MongoException (com.mongodb.MongoException)2 OakFongo (com.mongodb.OakFongo)2 WriteConcern (com.mongodb.WriteConcern)2 List (java.util.List)2 Fongo (com.github.fakemongo.Fongo)1 BulkWriteResult (com.mongodb.BulkWriteResult)1 DBEncoder (com.mongodb.DBEncoder)1 WriteResult (com.mongodb.WriteResult)1 Collections.singletonList (java.util.Collections.singletonList)1 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)1 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)1 DocumentStoreFixture (org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture)1 Before (org.junit.Before)1