Search in sources :

Example 11 with MemoryDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.

the class ClusterInfoTest method readWriteMode.

@Test
public void readWriteMode() throws InterruptedException {
    MemoryDocumentStore mem = new MemoryDocumentStore();
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    ClusterNodeInfo.setClock(clock);
    DocumentNodeStore ns1 = new DocumentMK.Builder().setDocumentStore(mem).setAsyncDelay(0).setLeaseCheck(false).setClusterId(1).getNodeStore();
    DocumentNodeStore ns2 = new DocumentMK.Builder().setDocumentStore(mem).setAsyncDelay(0).setLeaseCheck(false).setClusterId(2).getNodeStore();
    // Bring the current time forward to after the leaseTime which would have been 
    // updated in the DocumentNodeStore initialization.
    clock.waitUntil(clock.getTime() + ns1.getClusterInfo().getLeaseTime());
    ns1.getClusterInfo().setLeaseTime(0);
    ns1.getClusterInfo().setLeaseUpdateInterval(0);
    ns2.getClusterInfo().setLeaseTime(0);
    ns2.getClusterInfo().setLeaseUpdateInterval(0);
    List<ClusterNodeInfoDocument> list = mem.query(Collection.CLUSTER_NODES, "0", "a", Integer.MAX_VALUE);
    assertEquals(2, list.size());
    assertNull(mem.getReadPreference());
    assertNull(mem.getWriteConcern());
    mem.setReadWriteMode("read:primary, write:majority");
    assertEquals(ReadPreference.primary(), mem.getReadPreference());
    assertEquals(WriteConcern.MAJORITY, mem.getWriteConcern());
    UpdateOp op;
    // unknown modes: ignore
    op = new UpdateOp(list.get(0).getId(), false);
    op.set("readWriteMode", "read:xyz, write:abc");
    mem.findAndUpdate(Collection.CLUSTER_NODES, op);
    ns1.renewClusterIdLease();
    assertEquals(ReadPreference.primary(), mem.getReadPreference());
    assertEquals(WriteConcern.MAJORITY, mem.getWriteConcern());
    op = new UpdateOp(list.get(0).getId(), false);
    op.set("readWriteMode", "read:nearest, write:fsynced");
    mem.findAndUpdate(Collection.CLUSTER_NODES, op);
    ns1.renewClusterIdLease();
    assertEquals(ReadPreference.nearest(), mem.getReadPreference());
    assertEquals(WriteConcern.FSYNCED, mem.getWriteConcern());
    ns1.dispose();
    ns2.dispose();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) Test(org.junit.Test)

Example 12 with MemoryDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.

the class ClusterInfoTest method renewLease.

@Test
public void renewLease() throws InterruptedException {
    MemoryDocumentStore mem = new MemoryDocumentStore();
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    ClusterNodeInfo.setClock(clock);
    DocumentNodeStore ns = new DocumentMK.Builder().setDocumentStore(mem).setAsyncDelay(0).setLeaseCheck(false).getNodeStore();
    ClusterNodeInfo info = ns.getClusterInfo();
    assertNotNull(info);
    // current lease end
    long leaseEnd = getLeaseEndTime(ns);
    // wait a bit, 1sec less than leaseUpdateTime (10sec-1sec by default)
    clock.waitUntil(clock.getTime() + ClusterNodeInfo.DEFAULT_LEASE_UPDATE_INTERVAL_MILLIS - 1000);
    // must not renew lease right now
    ns.renewClusterIdLease();
    assertEquals(leaseEnd, getLeaseEndTime(ns));
    // wait some more time
    clock.waitUntil(clock.getTime() + 2000);
    // now the lease must be renewed
    ns.renewClusterIdLease();
    assertTrue(getLeaseEndTime(ns) > leaseEnd);
    ns.dispose();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Clock(org.apache.jackrabbit.oak.stats.Clock) Test(org.junit.Test)

Example 13 with MemoryDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.

the class ConcurrentConflictTest method initDocumentMK.

@Before
@Override
public void initDocumentMK() {
    logBuffer.setLength(0);
    this.store = new MemoryDocumentStore();
    DocumentMK mk = openDocumentMK(1);
    for (int i = 0; i < NUM_NODES; i++) {
        mk.commit("/", "+\"node-" + i + "\":{\"value\":100}", null, null);
    }
    mk.dispose();
    for (int i = 0; i < NUM_WRITERS; i++) {
        kernels.add(openDocumentMK(i + 2));
    }
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Before(org.junit.Before)

Example 14 with MemoryDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.

the class VersionGCSupportTest method fixtures.

@Parameterized.Parameters(name = "{0}")
public static java.util.Collection<Object[]> fixtures() {
    List<Object[]> fixtures = Lists.newArrayList();
    if (RDB_H2.isAvailable()) {
        RDBDocumentStore store = (RDBDocumentStore) RDB_H2.createDocumentStore();
        fixtures.add(new Object[] { RDB_H2, store, new RDBVersionGCSupport(store) });
    }
    if (MONGO.isAvailable()) {
        MongoDocumentStore store = (MongoDocumentStore) MONGO.createDocumentStore();
        fixtures.add(new Object[] { MONGO, store, new MongoVersionGCSupport(store) });
    }
    if (MEMORY.isAvailable()) {
        DocumentStore store = new MemoryDocumentStore();
        fixtures.add(new Object[] { MEMORY, store, new VersionGCSupport(store) });
    }
    return fixtures;
}
Also used : RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MongoVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport) RDBVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport) RDBVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.rdb.RDBVersionGCSupport) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MongoVersionGCSupport(org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore)

Example 15 with MemoryDocumentStore

use of org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore in project jackrabbit-oak by apache.

the class RandomizedClusterTest method createMK.

private DocumentMK createMK(int clusterId) {
    DocumentMK.Builder builder = new DocumentMK.Builder();
    builder.setAsyncDelay(0);
    if (MONGO_DB) {
        DB db = connectionFactory.getConnection().getDB();
        MongoUtils.dropCollections(db);
        builder.setMongoDB(db);
    } else {
        if (ds == null) {
            ds = new MemoryDocumentStore();
        }
        if (bs == null) {
            bs = new MemoryBlobStore();
        }
        builder.setDocumentStore(ds).setBlobStore(bs);
    }
    return builder.setClusterId(clusterId + 1).open();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) DB(com.mongodb.DB)

Aggregations

MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)132 Test (org.junit.Test)113 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)72 Clock (org.apache.jackrabbit.oak.stats.Clock)21 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)19 Before (org.junit.Before)13 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)11 MemoryBlobStore (org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Utils.getRootDocument (org.apache.jackrabbit.oak.plugins.document.util.Utils.getRootDocument)9 Random (java.util.Random)8 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)8 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)7 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)6 ArrayList (java.util.ArrayList)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 StringSort (org.apache.jackrabbit.oak.commons.sort.StringSort)5 List (java.util.List)4 Semaphore (java.util.concurrent.Semaphore)4 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)4