Search in sources :

Example 6 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)

Example 7 with PathRev

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

the class PersistentCacheTest method runTest.

@Override
protected void runTest() throws Exception {
    for (int i = 0; i < ITEMS_TO_ADD; i++) {
        PathRev key = PathRev.fromString("/" + timestamp.getAndIncrement() + "@" + new Revision(timestamp.getAndIncrement(), 0, 0));
        nodesCache.put(key, dns.getRoot());
        // read, so the entry is marked as used
        nodesCache.getIfPresent(key);
    }
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev)

Example 8 with PathRev

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

the class AsyncQueueTest method setup.

@Before
public void setup() throws IOException {
    FileUtils.deleteDirectory(new File("target/cacheTest"));
    pCache = new PersistentCache("target/cacheTest");
    final AtomicReference<NodeCache<PathRev, StringValue>> nodeCacheRef = new AtomicReference<NodeCache<PathRev, StringValue>>();
    CacheLIRS<PathRev, StringValue> cache = new CacheLIRS.Builder<PathRev, StringValue>().maximumSize(1).evictionCallback(new CacheLIRS.EvictionCallback<PathRev, StringValue>() {

        @Override
        public void evicted(@Nonnull PathRev key, @Nullable StringValue value, @Nonnull RemovalCause cause) {
            if (nodeCacheRef.get() != null) {
                nodeCacheRef.get().evicted(key, value, cause);
            }
        }
    }).build();
    nodeCache = (NodeCache<PathRev, StringValue>) pCache.wrap(builderProvider.newBuilder().getNodeStore(), null, cache, CacheType.NODE);
    nodeCacheRef.set(nodeCache);
    CacheWriteQueueWrapper writeQueue = new CacheWriteQueueWrapper(nodeCache.writeQueue);
    nodeCache.writeQueue = writeQueue;
    this.putActions = writeQueue.putActions;
    this.invalidateActions = writeQueue.invalidateActions;
    this.id = 0;
}
Also used : Nonnull(javax.annotation.Nonnull) AtomicReference(java.util.concurrent.atomic.AtomicReference) CacheLIRS(org.apache.jackrabbit.oak.cache.CacheLIRS) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) File(java.io.File) Nullable(javax.annotation.Nullable) RemovalCause(com.google.common.cache.RemovalCause) Before(org.junit.Before)

Example 9 with PathRev

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

the class CacheTest method recoverIfCorrupt.

@Test
public void recoverIfCorrupt() throws Exception {
    FileUtils.deleteDirectory(new File("target/cacheTest"));
    new File("target/cacheTest").mkdirs();
    FileOutputStream out = new FileOutputStream("target/cacheTest/cache-0.data");
    out.write("corrupt".getBytes());
    out.close();
    PersistentCache pCache = new PersistentCache("target/cacheTest");
    CacheLIRS<PathRev, StringValue> cache = new CacheLIRS.Builder<PathRev, StringValue>().maximumSize(1).build();
    Cache<PathRev, StringValue> map = pCache.wrap(null, null, cache, CacheType.DIFF);
    String largeString = new String(new char[1024 * 1024]);
    for (int counter = 0; counter < 10; counter++) {
        long end = System.currentTimeMillis() + 100;
        while (System.currentTimeMillis() < end) {
            Thread.yield();
        }
        for (int i = 0; i < 100; i++) {
            PathRev k = new PathRev("/" + counter, new RevisionVector(new Revision(0, 0, i)));
            map.getIfPresent(k);
            map.put(k, new StringValue(largeString));
        }
    }
    assertTrue("Exceptions: " + pCache.getExceptionCount(), pCache.getExceptionCount() < 100);
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) FileOutputStream(java.io.FileOutputStream) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) File(java.io.File) Test(org.junit.Test)

Example 10 with PathRev

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

the class NodeCacheTest method assertPathRevs.

private static <V> void assertPathRevs(NodeCache<PathRev, V> cache, String path, boolean contains) {
    List<PathRev> revs = getPathRevs(cache, path);
    List<PathRev> matchingRevs = Lists.newArrayList();
    for (PathRev pr : revs) {
        if (cache.getGenerationalMap().containsKey(pr)) {
            matchingRevs.add(pr);
        }
    }
    if (contains && matchingRevs.isEmpty()) {
        fail(String.format("Expecting entry for [%s]. Did not found in %s", path, matchingRevs));
    }
    if (!contains && !matchingRevs.isEmpty()) {
        fail(String.format("Expecting entry for [%s]. Found %s", path, revs));
    }
}
Also used : PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev)

Aggregations

PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)11 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 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 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)1 Counting (org.apache.jackrabbit.oak.stats.Counting)1 Before (org.junit.Before)1