Search in sources :

Example 6 with StringValue

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

the class CacheChangesTrackerTest method createCache.

private NodeDocumentCache createCache() {
    Cache<CacheValue, NodeDocument> nodeDocumentsCache = new CacheLIRS<CacheValue, NodeDocument>(10);
    Cache<StringValue, NodeDocument> prevDocumentsCache = new CacheLIRS<StringValue, NodeDocument>(10);
    CacheStats nodeDocumentsCacheStats = Mockito.mock(CacheStats.class);
    CacheStats prevDocumentsCacheStats = Mockito.mock(CacheStats.class);
    NodeDocumentLocks locks = new StripedNodeDocumentLocks();
    return new NodeDocumentCache(nodeDocumentsCache, nodeDocumentsCacheStats, prevDocumentsCache, prevDocumentsCacheStats, locks);
}
Also used : NodeDocumentLocks(org.apache.jackrabbit.oak.plugins.document.locks.NodeDocumentLocks) StripedNodeDocumentLocks(org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks) StripedNodeDocumentLocks(org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks) CacheValue(org.apache.jackrabbit.oak.cache.CacheValue) CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) StringValue(org.apache.jackrabbit.oak.plugins.document.util.StringValue) CacheLIRS(org.apache.jackrabbit.oak.cache.CacheLIRS)

Example 7 with StringValue

use of org.apache.jackrabbit.oak.plugins.document.util.StringValue 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 8 with StringValue

use of org.apache.jackrabbit.oak.plugins.document.util.StringValue 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)

Aggregations

StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)8 File (java.io.File)4 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)4 Revision (org.apache.jackrabbit.oak.plugins.document.Revision)3 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)3 Callable (java.util.concurrent.Callable)2 Nonnull (javax.annotation.Nonnull)2 CacheLIRS (org.apache.jackrabbit.oak.cache.CacheLIRS)2 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)2 RemovalCause (com.google.common.cache.RemovalCause)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Lock (java.util.concurrent.locks.Lock)1 CheckForNull (javax.annotation.CheckForNull)1 Nullable (javax.annotation.Nullable)1 CacheStats (org.apache.jackrabbit.oak.cache.CacheStats)1 CacheValue (org.apache.jackrabbit.oak.cache.CacheValue)1 NodeDocumentLocks (org.apache.jackrabbit.oak.plugins.document.locks.NodeDocumentLocks)1