Search in sources :

Example 16 with MongoConnection

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

the class MongoUtilsTest method checkArguments.

@Test(expected = IllegalArgumentException.class)
public void checkArguments() {
    MongoConnection c = connectionFactory.getConnection();
    DBCollection collection = c.getDB().getCollection("test");
    MongoUtils.createIndex(collection, new String[] { "foo", "bar" }, new boolean[] { true }, false, true);
}
Also used : DBCollection(com.mongodb.DBCollection) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Test(org.junit.Test)

Example 17 with MongoConnection

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

the class MongoUtilsTest method createPartialIndex.

@Test
public void createPartialIndex() {
    MongoConnection c = connectionFactory.getConnection();
    c.getDB().dropDatabase();
    MongoStatus status = new MongoStatus(c.getDB());
    assumeTrue(status.isVersion(3, 2));
    DBCollection collection = c.getDB().getCollection("test");
    MongoUtils.createPartialIndex(collection, new String[] { "foo", "bar" }, new boolean[] { true, true }, "{foo:true}");
    assertTrue(MongoUtils.hasIndex(collection, "_id"));
    assertTrue(MongoUtils.hasIndex(collection, "foo", "bar"));
    assertEquals(2, collection.getIndexInfo().size());
    for (DBObject info : collection.getIndexInfo()) {
        DBObject key = (DBObject) info.get("key");
        assertNotNull(key);
        if (key.keySet().contains("foo")) {
            assertEquals(2, key.keySet().size());
            assertEquals(1, key.get("foo"));
            assertEquals(1, key.get("bar"));
            DBObject filter = (DBObject) info.get("partialFilterExpression");
            assertNotNull(filter);
            assertEquals(Boolean.TRUE, filter.get("foo"));
        }
    }
    c.getDB().dropDatabase();
}
Also used : DBCollection(com.mongodb.DBCollection) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 18 with MongoConnection

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

the class MongoUtilsTest method createIndex.

@Test
public void createIndex() {
    MongoConnection c = connectionFactory.getConnection();
    c.getDB().dropDatabase();
    DBCollection collection = c.getDB().getCollection("test");
    MongoUtils.createIndex(collection, "foo", true, false, true);
    MongoUtils.createIndex(collection, "bar", false, true, false);
    MongoUtils.createIndex(collection, new String[] { "baz", "qux" }, new boolean[] { true, false }, false, false);
    assertTrue(MongoUtils.hasIndex(collection, "_id"));
    assertTrue(MongoUtils.hasIndex(collection, "foo"));
    assertFalse(MongoUtils.hasIndex(collection, "foo", "bar"));
    assertTrue(MongoUtils.hasIndex(collection, "baz", "qux"));
    assertEquals(4, collection.getIndexInfo().size());
    for (DBObject info : collection.getIndexInfo()) {
        DBObject key = (DBObject) info.get("key");
        if (key.keySet().contains("foo")) {
            assertEquals(1, key.keySet().size());
            assertEquals(1, key.get("foo"));
            assertEquals(Boolean.TRUE, info.get("sparse"));
        } else if (key.keySet().contains("bar")) {
            assertEquals(1, key.keySet().size());
            assertEquals(-1, key.get("bar"));
            assertEquals(Boolean.TRUE, info.get("unique"));
        } else if (key.keySet().contains("baz")) {
            assertEquals(2, key.keySet().size());
            assertEquals(1, key.get("baz"));
            assertEquals(-1, key.get("qux"));
        }
    }
    c.getDB().dropDatabase();
}
Also used : DBCollection(com.mongodb.DBCollection) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 19 with MongoConnection

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

the class ReadPreferenceIT method setUpConnection.

@Override
public void setUpConnection() throws Exception {
    clock = new Clock.Virtual();
    setRevisionClock(clock);
    setClusterNodeInfoClock(clock);
    mongoConnection = connectionFactory.getConnection();
    MongoUtils.dropCollections(mongoConnection.getDB());
    replica = ReplicaSetInfoMock.create(clock);
    mk = new DocumentMK.Builder().clock(clock).setClusterId(1).setMongoDB(mongoConnection.getDB()).setLeaseCheck(false).open();
    mongoDS = (MongoDocumentStore) mk.getDocumentStore();
    // use a separate connection for cluster node 2
    MongoConnection mongoConnection2 = connectionFactory.getConnection();
    mk2 = new DocumentMK.Builder().clock(clock).setClusterId(2).setMongoDB(mongoConnection2.getDB()).setLeaseCheck(false).open();
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Clock(org.apache.jackrabbit.oak.stats.Clock) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 20 with MongoConnection

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

the class ConcurrentAddNodesClusterIT method initRepository.

private static void initRepository() throws Exception {
    MongoConnection con = createConnection();
    DocumentMK mk = new DocumentMK.Builder().setMongoDB(con.getDB()).setClusterId(1).open();
    Repository repository = new Jcr(mk.getNodeStore()).createRepository();
    Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    session.logout();
    dispose(repository);
    // closes connection as well
    mk.dispose();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Session(javax.jcr.Session)

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