use of org.apache.jackrabbit.oak.plugins.document.Revision 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.Revision in project jackrabbit-oak by apache.
the class UtilsTest method alignWithExternalRevisions.
@Test
public void alignWithExternalRevisions() throws Exception {
Clock c = new Clock.Virtual();
c.waitUntil(System.currentTimeMillis());
// past
Revision lastRev1 = new Revision(c.getTime() - 1000, 0, 1);
// future
Revision lastRev2 = new Revision(c.getTime() + 1000, 0, 2);
// create a root document
NodeDocument doc = new NodeDocument(new MemoryDocumentStore(), c.getTime());
UpdateOp op = new UpdateOp(Utils.getIdFromPath("/"), true);
NodeDocument.setLastRev(op, lastRev1);
NodeDocument.setLastRev(op, lastRev2);
UpdateUtils.applyChanges(doc, op);
// must not wait even if revision is in the future
Utils.alignWithExternalRevisions(doc, c, 2);
assertThat(c.getTime(), is(lessThan(lastRev2.getTimestamp())));
// must wait until after lastRev2 timestamp
Utils.alignWithExternalRevisions(doc, c, 1);
assertThat(c.getTime(), is(greaterThan(lastRev2.getTimestamp())));
}
use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.
the class UtilsTest method performance_revisionToStringOne.
private static void performance_revisionToStringOne() {
Revision r = new Revision(System.currentTimeMillis(), 0, 0);
int dummy = 0;
long time = System.currentTimeMillis();
for (int i = 0; i < 30 * 1000 * 1000; i++) {
dummy += r.toString().length();
}
time = System.currentTimeMillis() - time;
System.out.println("time: " + time + " dummy " + dummy);
}
use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.
the class UtilsTest method leafPreviousDoc.
@Test
public void leafPreviousDoc() throws Exception {
Revision r = new Revision(System.currentTimeMillis(), 0, 0);
assertTrue(Utils.isLeafPreviousDocId(Utils.getPreviousIdFor("/", r, 0)));
assertTrue(Utils.isLeafPreviousDocId(Utils.getPreviousIdFor("/a/b/c/d/e/f/g/h/i/j/k/l/m", r, 0)));
assertFalse(Utils.isLeafPreviousDocId(Utils.getPreviousIdFor("/a/b/c/d/e/f/g/h/i/j/k/l/m", r, 3)));
assertFalse(Utils.isLeafPreviousDocId(Utils.getIdFromPath("/a/b")));
assertFalse(Utils.isLeafPreviousDocId("foo"));
assertFalse(Utils.isLeafPreviousDocId("0:"));
assertFalse(Utils.isLeafPreviousDocId(":/0"));
}
use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.
the class RevisionsKeyTest method fromAsString.
@Test
public void fromAsString() {
RevisionsKey k1 = new RevisionsKey(new RevisionVector(new Revision(1, 0, 1)), new RevisionVector(new Revision(2, 1, 2)));
RevisionsKey k2 = RevisionsKey.fromString(k1.asString());
assertEquals(k1, k2);
}
Aggregations