Search in sources :

Example 11 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class AtomicCounterEditorTest method consolidate.

@Test
public void consolidate() throws CommitFailedException {
    NodeBuilder builder;
    Editor editor;
    builder = EMPTY_NODE.builder();
    builder = setMixin(builder);
    editor = new AtomicCounterEditor(builder, null, null, null, null);
    editor.propertyAdded(INCREMENT_BY_1);
    assertTotalCountersValue(builder.getProperties(), 1);
    editor.propertyAdded(INCREMENT_BY_1);
    assertTotalCountersValue(builder.getProperties(), 2);
    AtomicCounterEditor.consolidateCount(builder);
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER, PREFIX_PROP_REVISION), 2);
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Test(org.junit.Test)

Example 12 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class AtomicCounterEditorTest method noHookInWhiteboard.

@Test
public void noHookInWhiteboard() throws CommitFailedException, InterruptedException, ExecutionException {
    NodeStore store = new MemoryNodeStore();
    MyExecutor exec1 = new MyExecutor();
    Whiteboard board = new DefaultWhiteboard();
    EditorHook hook1 = new EditorHook(new TestableACEProvider(CLUSTER_1, exec1, store, board));
    NodeBuilder builder, root;
    PropertyState p;
    root = store.getRoot().builder();
    builder = root.child("c");
    builder = setMixin(builder);
    builder = incrementBy(builder, INCREMENT_BY_1);
    store.merge(root, hook1, CommitInfo.EMPTY);
    // as we're providing all the information we expect the counter not to be consolidated for
    // as long as the scheduled process has run
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue(builder.exists());
    p = builder.getProperty(PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId());
    assertNotNull(p);
    assertEquals(1, p.getValue(LONG).longValue());
    p = builder.getProperty(PROP_COUNTER);
    assertEquals(1, p.getValue(LONG).longValue());
    assertTrue("without a registered hook it should have fell to sync", exec1.isEmpty());
    // fetching the latest store state to see the changes
    builder = store.getRoot().builder().getChildNode("c");
    assertTrue("the counter node should exists", builder.exists());
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER + CLUSTER_1.getInstanceId(), PREFIX_PROP_REVISION + CLUSTER_1.getInstanceId()), 1);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) LongPropertyState(org.apache.jackrabbit.oak.plugins.memory.LongPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 13 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class AtomicCounterEditorTest method notCluster.

@Test
public void notCluster() throws CommitFailedException {
    NodeBuilder builder;
    NodeState before, after;
    builder = EMPTY_NODE.builder();
    before = builder.getNodeState();
    builder = setMixin(builder);
    builder = incrementBy(builder, INCREMENT_BY_1);
    after = builder.getNodeState();
    builder = HOOK_NO_CLUSTER.processCommit(before, after, EMPTY).builder();
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER, PREFIX_PROP_REVISION), 1);
    before = builder.getNodeState();
    builder = incrementBy(builder, INCREMENT_BY_2);
    after = builder.getNodeState();
    builder = HOOK_NO_CLUSTER.processCommit(before, after, EMPTY).builder();
    assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER, PREFIX_PROP_REVISION), 3);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 14 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class CacheInvalidationIT method testCacheInvalidationHierarchicalNotExist.

@Test
public void testCacheInvalidationHierarchicalNotExist() throws CommitFailedException {
    NodeBuilder b2 = getRoot(c2).builder();
    // we create x/other, so that x is known to have a child node
    b2.child("x").child("other");
    b2.child("y");
    c2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    c2.runBackgroundOperations();
    c1.runBackgroundOperations();
    // we check for the existence of "x/futureX", which
    // should create a negative entry in the cache
    NodeState x = getRoot(c1).getChildNode("x");
    assertTrue(x.exists());
    assertFalse(x.getChildNode("futureX").exists());
    // we don't check for the existence of "y/futureY"
    NodeState y = getRoot(c1).getChildNode("y");
    assertTrue(y.exists());
    // now we add both "futureX" and "futureY"
    // in the other cluster node
    b2.child("x").child("futureX").setProperty("z", "1");
    c2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    b2.child("y").child("futureY").setProperty("z", "2");
    c2.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    c2.runBackgroundOperations();
    c1.runBackgroundOperations();
    // both nodes should now be visible
    assertTrue(getRoot(c1).getChildNode("y").getChildNode("futureY").exists());
    assertTrue(getRoot(c1).getChildNode("x").getChildNode("futureX").exists());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 15 with NodeBuilder

use of org.apache.jackrabbit.oak.spi.state.NodeBuilder in project jackrabbit-oak by apache.

the class CacheInvalidationIT method createScenario.

private int createScenario() throws CommitFailedException {
    //          a
    //        / | \
    //       /  c  \
    //      b       d
    //     /|\      |
    //    / | \     h
    //   e  f  g
    String[] paths = { "/a", "/a/c", "/a/b", "/a/b/e", "/a/b/f", "/a/b/g", "/a/d", "/a/d/h" };
    NodeBuilder root = getRoot(c1).builder();
    createTree(root, paths);
    c1.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertEquals(initialCacheSizeC1 + paths.length, getCurrentCacheSize(c1));
    runBgOps(c1, c2);
    return paths.length;
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Aggregations

NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)948 Test (org.junit.Test)704 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)253 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)84 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)74 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)73 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)70 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)67 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)60 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)52 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)49 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)43 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)31 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)31 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)29 Blob (org.apache.jackrabbit.oak.api.Blob)28 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)24 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)22 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)21 Nonnull (javax.annotation.Nonnull)20