Search in sources :

Example 51 with MemoryDocumentStore

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

the class LastRevRecoveryRandomizedIT method checkStore.

private void checkStore() {
    MemoryDocumentStore s = store.copy();
    // force lease expire
    UpdateOp op = new UpdateOp(String.valueOf(ns.getClusterId()), false);
    op.set(ClusterNodeInfo.LEASE_END_KEY, clock.getTime() - 1000);
    if (s.findAndUpdate(Collection.CLUSTER_NODES, op) == null) {
        fail("failed to set lease end");
    }
    // will trigger recovery on startup
    DocumentNodeStore dns = new DocumentMK.Builder().setClusterId(ns.getClusterId()).clock(clock).setLeaseCheck(false).setDocumentStore(s).setAsyncDelay(0).getNodeStore();
    Map<String, NodeState> states = Maps.newHashMap(currentState);
    NodeState root = dns.getRoot().getChildNode("root");
    compareAndTraverse(root, "/root", states);
    assertTrue("missing nodes: " + states.keySet() + " (seed=" + SEED + ")", states.isEmpty());
    dns.dispose();
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 52 with MemoryDocumentStore

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

the class FormatVersionTest method versionOf.

@Test
public void versionOf() throws Exception {
    DocumentStore store = new MemoryDocumentStore();
    FormatVersion v = FormatVersion.versionOf(store);
    assertSame(V0, v);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 53 with MemoryDocumentStore

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

the class FormatVersionTest method activeClusterNodes.

@Test(expected = DocumentStoreException.class)
public void activeClusterNodes() throws Exception {
    DocumentStore store = new MemoryDocumentStore();
    V1_0.writeTo(store);
    ClusterNodeInfo info = ClusterNodeInfo.getInstance(store, 1);
    info.renewLease();
    V1_2.writeTo(store);
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 54 with MemoryDocumentStore

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

the class DocumentNodeStoreTest method updateClusterState.

@Test
public void updateClusterState() {
    DocumentStore docStore = new MemoryDocumentStore();
    DocumentNodeStore ns1 = builderProvider.newBuilder().setAsyncDelay(0).setClusterId(1).setDocumentStore(docStore).getNodeStore();
    int cId1 = ns1.getClusterId();
    DocumentNodeStore ns2 = builderProvider.newBuilder().setAsyncDelay(0).setClusterId(2).setDocumentStore(docStore).getNodeStore();
    int cId2 = ns2.getClusterId();
    ns1.updateClusterState();
    ns2.updateClusterState();
    assertEquals(0, ns1.getMBean().getInactiveClusterNodes().length);
    assertEquals(0, ns2.getMBean().getInactiveClusterNodes().length);
    assertEquals(2, ns1.getMBean().getActiveClusterNodes().length);
    assertEquals(2, ns2.getMBean().getActiveClusterNodes().length);
    ns1.dispose();
    ns2.updateClusterState();
    String[] inactive = ns2.getMBean().getInactiveClusterNodes();
    String[] active = ns2.getMBean().getActiveClusterNodes();
    assertEquals(1, inactive.length);
    assertTrue(inactive[0].startsWith(cId1 + "="));
    assertEquals(1, active.length);
    assertTrue(active[0].startsWith(cId2 + "="));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) Test(org.junit.Test)

Example 55 with MemoryDocumentStore

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

the class DocumentNodeStoreTest method ignoreUncommitted.

// OAK-3474
@Test
public void ignoreUncommitted() throws Exception {
    final AtomicLong numPreviousFinds = new AtomicLong();
    MemoryDocumentStore store = new MemoryDocumentStore() {

        @Override
        public <T extends Document> T find(Collection<T> collection, String key) {
            if (Utils.getPathFromId(key).startsWith("p")) {
                numPreviousFinds.incrementAndGet();
            }
            return super.find(collection, key);
        }
    };
    DocumentNodeStore ns = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).getNodeStore();
    String id = Utils.getIdFromPath("/test");
    NodeBuilder b = ns.getRoot().builder();
    b.child("test").setProperty("p", "a");
    merge(ns, b);
    NodeDocument doc;
    int i = 0;
    do {
        b = ns.getRoot().builder();
        b.child("test").setProperty("q", i++);
        merge(ns, b);
        doc = store.find(NODES, id);
        assertNotNull(doc);
        if (i % 100 == 0) {
            ns.runBackgroundOperations();
        }
    } while (doc.getPreviousRanges().isEmpty());
    Revision r = ns.newRevision();
    UpdateOp op = new UpdateOp(id, false);
    NodeDocument.setCommitRoot(op, r, 0);
    op.setMapEntry("p", r, "b");
    assertNotNull(store.findAndUpdate(NODES, op));
    doc = store.find(NODES, id);
    numPreviousFinds.set(0);
    doc.getNodeAtRevision(ns, ns.getHeadRevision(), null);
    assertEquals(0, numPreviousFinds.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

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