Search in sources :

Example 1 with Builder

use of org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder in project jackrabbit-oak by apache.

the class DocumentNodeStoreBranchesTest method commitHookChangesOnBranchWithInterference.

@Test
public void commitHookChangesOnBranchWithInterference() throws Exception {
    Clock c = new Clock.Virtual();
    c.waitUntil(System.currentTimeMillis());
    Revision.setClock(c);
    ClusterNodeInfo.setClock(c);
    // enough nodes that diffManyChildren() is called
    final int NUM_NODES = DocumentMK.MANY_CHILDREN_THRESHOLD * 2;
    LOG.info("create new dns");
    Builder nsBuilder = builderProvider.newBuilder();
    nsBuilder.setAsyncDelay(0).clock(c);
    final DocumentNodeStore ns = nsBuilder.getNodeStore();
    // 0) initialization
    {
        LOG.info("initialization");
        NodeBuilder initBuilder = ns.getRoot().builder();
        for (int i = 0; i < NUM_NODES; i++) {
            initBuilder.child("child" + i);
        }
        ns.merge(initBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
    // 1) do more than UPDATE_LIMIT changes
    LOG.info("starting doing many changes to force a branch commit");
    NodeBuilder rootBuilder = ns.getRoot().builder();
    int totalUpdates = 5 * DocumentMK.UPDATE_LIMIT;
    int updateShare = totalUpdates / NUM_NODES;
    for (int i = 0; i < NUM_NODES; i++) {
        NodeBuilder childBuilder = rootBuilder.child("child" + i);
        childBuilder.child("grandChild" + i);
        childBuilder.setProperty("p1", "originalValue");
        for (int j = 0; j < updateShare; j++) {
            childBuilder.setProperty("someProperty" + j, "sameValue");
        }
    }
    // 2) wait 6 sec
    LOG.info("after purge was triggered above, 'waiting' 6sec");
    c.waitUntil(c.getTime() + 6000);
    // 3) now in another 'session', do another merge - to change the head
    LOG.info("in another session, do some unrelated changes to change the head");
    NodeBuilder parallelBuilder = ns.getRoot().builder();
    parallelBuilder.child("unrelated").setProperty("anyProp", "anywhere");
    ns.merge(parallelBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // 4) now merge the first session - this should now fail
    LOG.info("now merge the original builder - this should cause not all children to be visited");
    ns.merge(rootBuilder, CompositeHook.compose(Arrays.<CommitHook>asList(new TestHook("p"), new TestHook("q"))), CommitInfo.EMPTY);
    DocumentNodeState root = ns.getRoot();
    for (int i = 0; i < NUM_NODES; i++) {
        NodeState child = root.getChildNode("child" + i);
        assertTrue(child.exists());
        assertEquals("test", child.getProperty("p1").getValue(Type.STRING));
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Builder(org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) Clock(org.apache.jackrabbit.oak.stats.Clock) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with Builder

use of org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder in project jackrabbit-oak by apache.

the class CacheConsistencyRDBTest method setUpConnection.

@Before
@Override
public void setUpConnection() throws Exception {
    dataSource = RDBDataSourceFactory.forJdbcUrl(URL, USERNAME, PASSWD);
    DocumentMK.Builder builder = new DocumentMK.Builder().clock(getTestClock()).setAsyncDelay(0);
    RDBOptions opt = new RDBOptions().tablePrefix("T" + Long.toHexString(System.currentTimeMillis())).dropTablesOnClose(true);
    store = new TestStore(dataSource, builder, opt);
    mk = builder.setDocumentStore(store).setLeaseCheck(false).open();
}
Also used : Builder(org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder) Builder(org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder) RDBOptions(org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions) Before(org.junit.Before)

Aggregations

Builder (org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder)2 RDBOptions (org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions)1 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 Clock (org.apache.jackrabbit.oak.stats.Clock)1 Before (org.junit.Before)1 Test (org.junit.Test)1