Search in sources :

Example 1 with PathRev

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

the class BroadcastTest method benchmark.

private static void benchmark() throws IOException {
    FileUtils.deleteDirectory(new File("target/broadcastTest"));
    new File("target/broadcastTest").mkdirs();
    String type = "tcp:key 1;ports 9700 9800";
    ArrayList<PersistentCache> nodeList = new ArrayList<PersistentCache>();
    for (int nodes = 1; nodes < 20; nodes++) {
        PersistentCache pc = new PersistentCache("target/broadcastTest/p" + nodes + ",broadcast=" + type);
        Cache<PathRev, StringValue> cache = openCache(pc);
        String key = "/test" + Math.random();
        PathRev k = new PathRev(key, new RevisionVector(new Revision(0, 0, 0)));
        long time = System.currentTimeMillis();
        for (int i = 0; i < 2000; i++) {
            cache.put(k, new StringValue("Hello World " + i));
            cache.invalidate(k);
            cache.getIfPresent(k);
        }
        time = System.currentTimeMillis() - time;
        System.out.println("nodes: " + nodes + " time: " + time);
        nodeList.add(pc);
    }
    for (PersistentCache c : nodeList) {
        c.close();
    }
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) ArrayList(java.util.ArrayList) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) File(java.io.File)

Example 2 with PathRev

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

the class BroadcastTest method broadcastTry.

private static boolean broadcastTry(String type, int minPercentCorrect, boolean tryOnly) throws Exception {
    FileUtils.deleteDirectory(new File("target/broadcastTest"));
    new File("target/broadcastTest").mkdirs();
    PersistentCache p1 = new PersistentCache("target/broadcastTest/p1,broadcast=" + type);
    PersistentCache p2 = new PersistentCache("target/broadcastTest/p2,broadcast=" + type);
    Cache<PathRev, StringValue> c1 = openCache(p1);
    Cache<PathRev, StringValue> c2 = openCache(p2);
    String key = "/test" + Math.random();
    PathRev k = new PathRev(key, new RevisionVector(new Revision(0, 0, 0)));
    int correct = 0;
    for (int i = 0; i < 50; i++) {
        c1.put(k, new StringValue("Hello World " + i));
        waitFor(c2, k, 10000);
        StringValue v2 = c2.getIfPresent(k);
        if (v2 != null && v2.toString().equals("Hello World " + i)) {
            correct++;
        }
        c2.invalidate(k);
        assertNull(c2.getIfPresent(k));
        waitFor(c1, k, null, 10000);
        StringValue v1 = c1.getIfPresent(k);
        if (v1 == null) {
            correct++;
        }
    }
    p1.close();
    p2.close();
    if (correct >= minPercentCorrect) {
        return true;
    }
    if (tryOnly) {
        return false;
    }
    Assert.fail("min: " + minPercentCorrect + " got: " + correct);
    return false;
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) File(java.io.File)

Example 3 with PathRev

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

the class NodeCacheTest method initializeNodeStore.

private void initializeNodeStore(boolean asyncCache, Consumer<DocumentMK.Builder> processor) {
    store = new MemoryDocumentStore();
    DocumentMK.Builder builder = builderProvider.newBuilder().setDocumentStore(store).setAsyncDelay(0).setStatisticsProvider(statsProvider);
    if (asyncCache) {
        builder.setPersistentCache("target/persistentCache,time");
    } else {
        builder.setPersistentCache("target/persistentCache,time,-async");
    }
    processor.accept(builder);
    ns = builder.getNodeStore();
    nodeCache = (NodeCache<PathRev, DocumentNodeState>) ns.getNodeCache();
    nodeChildren = (NodeCache<PathRev, DocumentNodeState.Children>) ns.getNodeChildrenCache();
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)

Example 4 with PathRev

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

the class DocumentBundlingTest method bundledNodeAndNodeChildrenCache.

@Test
public void bundledNodeAndNodeChildrenCache() throws Exception {
    NodeBuilder builder = store.getRoot().builder();
    NodeBuilder appNB = newNode("app:Asset");
    createChild(appNB, "jcr:content", // not bundled
    "jcr:content/comments", "jcr:content/metadata", // not bundled
    "jcr:content/metadata/xmp", // includes all
    "jcr:content/renditions", "jcr:content/renditions/original", "jcr:content/renditions/original/jcr:content");
    builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
    merge(builder);
    Set<PathRev> cachedPaths = store.getNodeChildrenCache().asMap().keySet();
    for (PathRev pr : cachedPaths) {
        assertFalse(pr.getPath().contains("jcr:content/renditions"));
    }
}
Also used : PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with PathRev

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

the class AsyncQueueTest method readItemsShouldntBePersistedAgain.

@Test
public void readItemsShouldntBePersistedAgain() {
    PathRev k = generatePathRev();
    nodeCache.put(k, VAL);
    nodeCache.getIfPresent(k);
    flush();
    assertEquals(asList(k), putActions);
    putActions.clear();
    // k should be loaded from persisted cache
    nodeCache.getIfPresent(k);
    flush();
    // k is not persisted again
    assertEquals(emptyList(), putActions);
}
Also used : PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) Test(org.junit.Test)

Aggregations

PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)12 Test (org.junit.Test)6 File (java.io.File)4 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)4 StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)4 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)3 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 RemovalCause (com.google.common.cache.RemovalCause)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 CacheLIRS (org.apache.jackrabbit.oak.cache.CacheLIRS)1 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)1 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)1 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)1 Counting (org.apache.jackrabbit.oak.stats.Counting)1 Before (org.junit.Before)1