Search in sources :

Example 6 with NodeBuilder

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

the class CheckpointsTest method crossClusterNodeCheckpoint.

@Test
public void crossClusterNodeCheckpoint() throws Exception {
    // use an async delay to ensure DocumentNodeStore.suspendUntil() works
    // but set it to a high value and control background ops manually in
    // this test
    final int asyncDelay = (int) TimeUnit.MINUTES.toMillis(1);
    DocumentStore store = new MemoryDocumentStore();
    final DocumentNodeStore ns1 = builderProvider.newBuilder().setClusterId(1).setDocumentStore(store).setAsyncDelay(asyncDelay).getNodeStore();
    final DocumentNodeStore ns2 = builderProvider.newBuilder().setClusterId(2).setDocumentStore(store).setAsyncDelay(asyncDelay).getNodeStore();
    // create node on ns1
    NodeBuilder builder = ns1.getRoot().builder();
    builder.child("foo");
    ns1.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // make visible on ns2
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    // create checkpoint on ns1
    String cp1 = ns1.checkpoint(Long.MAX_VALUE);
    // retrieve checkpoint on ns2
    NodeState root = ns2.retrieve(cp1);
    assertNotNull(root);
    assertTrue(root.hasChildNode("foo"));
    ns2.release(cp1);
    // create node on ns1
    builder = ns1.getRoot().builder();
    builder.child("bar");
    ns1.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // create checkpoint when 'bar' is not yet visible to ns2
    final String cp2 = ns1.checkpoint(Long.MAX_VALUE);
    // retrieve checkpoint on ns2
    final NodeState[] state = new NodeState[1];
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            state[0] = ns2.retrieve(cp2);
        }
    });
    t.start();
    ns1.runBackgroundOperations();
    ns2.runBackgroundOperations();
    t.join();
    assertNotNull(state[0]);
    assertTrue(state[0].hasChildNode("bar"));
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 7 with NodeBuilder

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

the class AbstractJournalTest method getOrCreate.

protected void getOrCreate(DocumentNodeStore ns, List<String> paths, boolean runBgOpsAfterCreation) throws CommitFailedException {
    NodeBuilder rootBuilder = ns.getRoot().builder();
    for (String path : paths) {
        doGetOrCreate(rootBuilder, path);
    }
    ns.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    if (runBgOpsAfterCreation) {
        ns.runBackgroundOperations();
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 8 with NodeBuilder

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

the class AbstractJournalTest method getOrCreate.

protected void getOrCreate(DocumentNodeStore ns, String path, boolean runBgOpsAfterCreation) throws CommitFailedException {
    NodeBuilder rootBuilder = ns.getRoot().builder();
    doGetOrCreate(rootBuilder, path);
    ns.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    if (runBgOpsAfterCreation) {
        ns.runBackgroundOperations();
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 9 with NodeBuilder

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

the class AtomicCounterEditorTest method singleNodeAsync.

@Test
public void singleNodeAsync() 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;
    board.register(CommitHook.class, EmptyHook.INSTANCE, null);
    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);
    assertNull(p);
    // executing the consolidation
    exec1.execute();
    // 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 10 with NodeBuilder

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

the class AtomicCounterEditorTest method increment.

@Test
public void increment() throws CommitFailedException {
    NodeBuilder builder;
    Editor editor;
    builder = EMPTY_NODE.builder();
    editor = new AtomicCounterEditor(builder, null, null, null, null);
    editor.propertyAdded(INCREMENT_BY_1);
    assertNoCounters(builder.getProperties());
    builder = EMPTY_NODE.builder();
    builder = setMixin(builder);
    editor = new AtomicCounterEditor(builder, null, null, null, null);
    editor.propertyAdded(INCREMENT_BY_1);
    assertNull("the oak:increment should never be set", builder.getProperty(PROP_INCREMENT));
    assertTotalCountersValue(builder.getProperties(), 1);
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Test(org.junit.Test)

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