Search in sources :

Example 21 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class RevisionsCommandTest method sweep.

@Test
public void sweep() throws Exception {
    int clusterId = ns.getClusterId();
    String output = captureSystemErr(new Sweep(clusterId));
    assertThat(output, containsString("cannot sweep revisions for active clusterId"));
    output = captureSystemErr(new Sweep(0));
    assertThat(output, containsString("clusterId option is required"));
    output = captureSystemErr(new Sweep(99));
    assertThat(output, containsString("store does not have changes with clusterId"));
    ns.dispose();
    output = captureSystemOut(new Sweep(clusterId));
    assertThat(output, containsString("Revision sweep not needed for clusterId"));
    // remove the sweep revision to force a sweep run
    MongoConnection c = connectionFactory.getConnection();
    DocumentMK.Builder builder = builderProvider.newBuilder().setMongoDB(c.getDB());
    DocumentStore store = builder.getDocumentStore();
    UpdateOp op = new UpdateOp(getIdFromPath("/"), false);
    op.removeMapEntry("_sweepRev", new Revision(0, 0, clusterId));
    assertNotNull(store.findAndUpdate(Collection.NODES, op));
    output = captureSystemOut(new Sweep(clusterId));
    assertThat(output, containsString("Updated sweep revision to"));
}
Also used : DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Test(org.junit.Test)

Example 22 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class RevisionsCommandTest method createDocumentNodeStore.

private DocumentNodeStore createDocumentNodeStore() {
    MongoConnection c = connectionFactory.getConnection();
    MongoUtils.dropCollections(c.getDB().getName());
    return builderProvider.newBuilder().setMongoDB(c.getDB()).getNodeStore();
}
Also used : MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 23 with MongoConnection

use of org.apache.jackrabbit.oak.plugins.document.util.MongoConnection in project jackrabbit-oak by apache.

the class Utils method createDocumentMKBuilder.

@CheckForNull
static DocumentMK.Builder createDocumentMKBuilder(NodeStoreOptions options, Closer closer) throws IOException {
    String src = options.getStoreArg();
    if (src == null || src.length() == 0) {
        options.printHelpOn(System.err);
        System.exit(1);
    }
    DocumentMK.Builder builder = new DocumentMK.Builder();
    if (src.startsWith(MongoURI.MONGODB_PREFIX)) {
        MongoClientURI uri = new MongoClientURI(src);
        if (uri.getDatabase() == null) {
            System.err.println("Database missing in MongoDB URI: " + uri.getURI());
            System.exit(1);
        }
        MongoConnection mongo = new MongoConnection(uri.getURI());
        closer.register(asCloseable(mongo));
        builder.setMongoDB(mongo.getDB());
    } else if (src.startsWith("jdbc")) {
        DataSource ds = RDBDataSourceFactory.forJdbcUrl(src, options.getRDBJDBCUser(), options.getRDBJDBCPassword());
        builder.setRDBConnection(ds);
    } else {
        return null;
    }
    builder.setLeaseCheck(false).setClusterId(options.getClusterId());
    if (options.disableBranchesSpec()) {
        builder.disableBranches();
    }
    int cacheSize = options.getCacheSize();
    if (cacheSize != 0) {
        builder.memoryCacheSize(cacheSize * MB);
    }
    return builder;
}
Also used : DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) MongoClientURI(com.mongodb.MongoClientURI) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) DataSource(javax.sql.DataSource) CheckForNull(javax.annotation.CheckForNull)

Aggregations

MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)23 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)8 Test (org.junit.Test)6 MongoClientURI (com.mongodb.MongoClientURI)5 DB (com.mongodb.DB)3 DBCollection (com.mongodb.DBCollection)3 DataSource (javax.sql.DataSource)3 DocumentStore (org.apache.jackrabbit.oak.plugins.document.DocumentStore)3 DBObject (com.mongodb.DBObject)2 MongoDocumentStore (org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Before (org.junit.Before)2 BasicDBObject (com.mongodb.BasicDBObject)1 MongoClientOptions (com.mongodb.MongoClientOptions)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 CheckForNull (javax.annotation.CheckForNull)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1