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"));
}
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();
}
}
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();
}
}
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);
}
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);
}
Aggregations