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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations