Search in sources :

Example 26 with Revision

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);
}
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 27 with Revision

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())));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Test(org.junit.Test)

Example 28 with Revision

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);
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision)

Example 29 with Revision

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"));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) Test(org.junit.Test)

Example 30 with Revision

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);
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) Test(org.junit.Test)

Aggregations

Revision (org.apache.jackrabbit.oak.plugins.document.Revision)32 Test (org.junit.Test)17 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)13 BasicDBObject (com.mongodb.BasicDBObject)4 DBObject (com.mongodb.DBObject)4 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)4 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)4 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)4 DBCollection (com.mongodb.DBCollection)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 TreeMap (java.util.TreeMap)2 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 AbstractMongoConnectionTest (org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)2 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)2 Key (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key)2 Operation (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation)2