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