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