use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class ClusterTest method clusterBranchRebase.
/**
* Test for OAK-1254
*/
@Test
public void clusterBranchRebase() throws Exception {
DocumentMK mk1 = createMK(1, 0);
mk1.commit("/", "+\"test\":{}", null, null);
mk1.runBackgroundOperations();
DocumentMK mk2 = createMK(2, 0);
DocumentMK mk3 = createMK(3, 0);
DocumentNodeStore ns3 = mk3.getNodeStore();
// the next line is required for the test even if it
// just reads from the node store. do not remove!
traverse(ns3.getRoot(), "/");
String b3 = mk3.branch(null);
b3 = mk3.commit("/", "+\"mk3\":{}", b3, null);
assertTrue(mk3.nodeExists("/test", b3));
mk2.commit("/", "+\"test/mk21\":{}", null, null);
mk2.runBackgroundOperations();
// pick up changes from mk2
mk3.runBackgroundOperations();
String base3 = mk3.getHeadRevision();
assertFalse(mk3.nodeExists("/test/mk21", b3));
b3 = mk3.rebase(b3, base3);
mk2.commit("/", "+\"test/mk22\":{}", null, null);
mk2.runBackgroundOperations();
// pick up changes from mk2
mk3.runBackgroundOperations();
DocumentNodeState base = ns3.getNode("/", RevisionVector.fromString(base3));
assertNotNull(base);
NodeState branchHead = ns3.getNode("/", RevisionVector.fromString(b3));
assertNotNull(branchHead);
TrackingDiff diff = new TrackingDiff();
branchHead.compareAgainstBaseState(base, diff);
assertEquals(1, diff.added.size());
assertEquals(Sets.newHashSet("/mk3"), diff.added);
assertEquals(new HashSet<String>(), diff.deleted);
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class ConcurrentReadAndAddTest method concurrentReadAdd.
@Test
public void concurrentReadAdd() throws Exception {
main = Thread.currentThread();
NodeBuilder builder = ns.getRoot().builder();
builder.child("test");
merge(builder);
final Semaphore sem = new Semaphore(0);
Thread u = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
addNode(i);
if (i == 20) {
sem.release();
}
}
}
});
u.setName("writer");
u.start();
sem.acquireUninterruptibly();
readNodes();
u.join();
if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}
NodeState test = ns.getRoot().getChildNode("test");
assertEquals(100, Iterables.size(test.getChildNodeEntries()));
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class ClusterTest method fromExternalChange.
@Test
public void fromExternalChange() throws Exception {
final List<DocumentNodeState> rootStates1 = Lists.newArrayList();
DocumentNodeStore ns1 = createMK(1, 0).getNodeStore();
ns1.addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
rootStates1.add((DocumentNodeState) root);
}
});
final List<DocumentNodeState> rootStates2 = Lists.newArrayList();
DocumentNodeStore ns2 = createMK(2, 0).getNodeStore();
ns2.addObserver(new Observer() {
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
rootStates2.add((DocumentNodeState) root);
}
});
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
rootStates1.clear();
rootStates2.clear();
NodeBuilder builder = ns1.getRoot().builder();
builder.child("foo");
merge(ns1, builder);
assertEquals(1, rootStates1.size());
assertEquals(0, rootStates2.size());
assertFalse(rootStates1.get(0).isFromExternalChange());
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
assertEquals(1, rootStates1.size());
assertEquals(1, rootStates2.size());
assertTrue(rootStates2.get(0).isFromExternalChange());
NodeState foo = rootStates2.get(0).getChildNode("foo");
assertTrue(foo instanceof DocumentNodeState);
assertTrue(((DocumentNodeState) foo).isFromExternalChange());
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class CommitContextTest method attributeAddedByCommitHook.
@Test
public void attributeAddedByCommitHook() throws Exception {
repository = new Oak(store).with(new OpenSecurityProvider()).with(observer).with(new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
CommitContext attrs = (CommitContext) info.getInfo().get(CommitContext.NAME);
assertNotNull(attrs);
attrs.set("foo", "bar");
return after;
}
}).createContentRepository();
session = newSession();
Root root = session.getLatestRoot();
Tree tree = root.getTree("/");
tree.setProperty("a", 1);
root.commit();
assertNotNull(observer.info);
CommitContext attrs = (CommitContext) observer.info.getInfo().get(CommitContext.NAME);
assertNotNull(attrs.get("foo"));
}
use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.
the class AsyncIndexUpdateClusterTestIT method createAsync.
private static AsyncIndexUpdate createAsync(DocumentNodeStore ns, final IndexStatusListener l) {
IndexEditorProvider p = new TestEditorProvider(new PropertyIndexEditorProvider(), l);
AsyncIndexUpdate aiu = new AsyncIndexUpdate("async", ns, p) {
protected boolean updateIndex(NodeState before, String beforeCheckpoint, NodeState after, String afterCheckpoint, String afterTime, AsyncUpdateCallback callback) throws CommitFailedException {
if (MISSING_NODE == before) {
l.reindexing();
}
return super.updateIndex(before, beforeCheckpoint, after, afterCheckpoint, afterTime, callback);
}
};
aiu.setCloseTimeOut(1);
return aiu;
}
Aggregations