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