Search in sources :

Example 1 with JsopDiff

use of org.apache.jackrabbit.oak.json.JsopDiff in project jackrabbit-oak by apache.

the class DocumentNodeStoreIT method modifiedResetWithDiff.

@Test
public void modifiedResetWithDiff() throws Exception {
    Clock clock = new Clock.Virtual();
    clock.waitUntil(System.currentTimeMillis());
    Revision.setClock(clock);
    DocumentStore docStore = new TimingDocumentStoreWrapper(ds) {

        @Override
        public void dispose() {
        // do not dispose yet
        }
    };
    DocumentNodeStore ns1 = new DocumentMK.Builder().setDocumentStore(docStore).setClusterId(1).setAsyncDelay(0).clock(clock).setDiffCache(AmnesiaDiffCache.INSTANCE).getNodeStore();
    NodeBuilder builder1 = ns1.getRoot().builder();
    builder1.child("node");
    removeMe.add(getIdFromPath("/node"));
    for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD; i++) {
        builder1.child("node-" + i);
        removeMe.add(getIdFromPath("/node/node-" + i));
    }
    ns1.merge(builder1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // make sure commit is visible to other node store instance
    ns1.runBackgroundOperations();
    DocumentNodeStore ns2 = new DocumentMK.Builder().setDocumentStore(docStore).setClusterId(2).setAsyncDelay(0).clock(clock).getNodeStore();
    NodeBuilder builder2 = ns2.getRoot().builder();
    builder2.child("node").child("child-a");
    removeMe.add(getIdFromPath("/node/child-a"));
    ns2.merge(builder2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // wait at least _modified resolution. in reality the wait may
    // not be necessary. e.g. when the clock passes the resolution boundary
    // exactly at this time
    clock.waitUntil(System.currentTimeMillis() + SECONDS.toMillis(MODIFIED_IN_SECS_RESOLUTION + 1));
    builder1 = ns1.getRoot().builder();
    builder1.child("node").child("child-b");
    removeMe.add(getIdFromPath("/node/child-b"));
    ns1.merge(builder1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // remember root for diff
    DocumentNodeState root1 = ns1.getRoot();
    builder1 = root1.builder();
    builder1.child("node").child("child-c");
    removeMe.add(getIdFromPath("/node/child-c"));
    ns1.merge(builder1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // remember root for diff
    DocumentNodeState root2 = ns1.getRoot();
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    JsopDiff diff = new JsopDiff("", 0);
    ns1.compare(root2, root1, diff);
    // must report /node as changed
    assertEquals("^\"node\":{}", diff.toString());
    ns1.dispose();
    ns2.dispose();
}
Also used : TimingDocumentStoreWrapper(org.apache.jackrabbit.oak.plugins.document.util.TimingDocumentStoreWrapper) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) JsopDiff(org.apache.jackrabbit.oak.json.JsopDiff) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with JsopDiff

use of org.apache.jackrabbit.oak.json.JsopDiff in project jackrabbit-oak by apache.

the class DocumentMK method diff.

public String diff(String fromRevisionId, String toRevisionId, String path, int depth) throws DocumentStoreException {
    if (depth != 0) {
        throw new DocumentStoreException("Only depth 0 is supported, depth is " + depth);
    }
    if (path == null || path.equals("")) {
        path = "/";
    }
    RevisionVector fromRev = RevisionVector.fromString(fromRevisionId);
    RevisionVector toRev = RevisionVector.fromString(toRevisionId);
    final DocumentNodeState before = nodeStore.getNode(path, fromRev);
    final DocumentNodeState after = nodeStore.getNode(path, toRev);
    if (before == null || after == null) {
        String msg = String.format("Diff is only supported if the node exists in both cases. " + "Node [%s], fromRev [%s] -> %s, toRev [%s] -> %s", path, fromRev, before != null, toRev, after != null);
        throw new DocumentStoreException(msg);
    }
    JsopDiff diff = new JsopDiff(path, depth);
    after.compareAgainstBaseState(before, diff);
    return diff.toString();
}
Also used : JsopDiff(org.apache.jackrabbit.oak.json.JsopDiff)

Example 3 with JsopDiff

use of org.apache.jackrabbit.oak.json.JsopDiff in project jackrabbit-oak by apache.

the class LuceneIndexMBeanImpl method diffStoredIndexDefinition.

@Override
public String diffStoredIndexDefinition(@Name("indexPath") String indexPath) {
    NodeState stored = NodeStateUtils.getNode(indexTracker.getRoot(), indexPath + "/" + INDEX_DEFINITION_NODE);
    NodeState current = NodeStateUtils.getNode(indexTracker.getRoot(), indexPath);
    if (stored.exists()) {
        current = NodeStateCloner.cloneVisibleState(current);
        JsopDiff diff = new JsopDiff();
        current.compareAgainstBaseState(stored, diff);
        return JsopBuilder.prettyPrint(diff.toString());
    }
    return "No stored index definition found at given path";
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) JsopDiff(org.apache.jackrabbit.oak.json.JsopDiff)

Aggregations

JsopDiff (org.apache.jackrabbit.oak.json.JsopDiff)3 TimingDocumentStoreWrapper (org.apache.jackrabbit.oak.plugins.document.util.TimingDocumentStoreWrapper)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 Clock (org.apache.jackrabbit.oak.stats.Clock)1 Test (org.junit.Test)1