@Nonnull @Override public synchronized NodeState merge(@Nonnull NodeBuilder builder, @Nonnull CommitHook commitHook, @Nonnull CommitInfo info) throws CommitFailedException { return memoryNodeStore.merge(builder, commitHook, info); }
@NotNull @Override public synchronized NodeState merge(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info) throws CommitFailedException { return memoryNodeStore.merge(builder, commitHook, info); }
@NotNull @Override public synchronized NodeState merge(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info) throws CommitFailedException { return memoryNodeStore.merge(builder, commitHook, info); }
@NotNull @Override public NodeState merge(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info) throws CommitFailedException { Semaphore s = locks.get(Thread.currentThread()); if (s != null) { s.acquireUninterruptibly(); } return super.merge(builder, commitHook, info); } };
@Override public synchronized NodeState merge(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info) throws CommitFailedException { if (info.getSessionId().equals(OakInitializer.SESSION_ID)) { this.infos.add(info); } return super.merge(builder, commitHook, info); }
private void addBundlorConfigForAsset() throws CommitFailedException { NodeBuilder builder = nodeStore.getRoot().builder(); NodeBuilder bundlor = builder.child("jcr:system").child(DOCUMENT_NODE_STORE).child(BUNDLOR); bundlor.child("app:Asset").setProperty(DocumentBundlor.PROP_PATTERN, singletonList("metadata"), Type.STRINGS); nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); }
@Test public void validNamespacePrefix() throws Exception { NodeBuilder builder = mount.getRoot().builder(); builder.child("libs").setProperty("jcr:prop", "value"); mount.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); check("/libs/jcr:prop"); }
@Test public void noNamespacePrefix() throws Exception { NodeBuilder builder = mount.getRoot().builder(); builder.child("libs").setProperty("prop", "value"); mount.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); check("/libs"); } }
@Test public void commitContext() throws Exception{ MemoryNodeStore store = new MemoryNodeStore(); IndexEditorProvider provider = new PropertyIndexEditorProvider(); NodeBuilder builder = store.getRoot().builder(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null) .setProperty(ASYNC_PROPERTY_NAME, "async"); builder.child("testRoot").setProperty("foo", "abc"); // merge it back in store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); CommitInfoCollector infoCollector = new CommitInfoCollector(); store.addObserver(infoCollector); async.run(); assertFalse(infoCollector.infos.isEmpty()); assertNotNull(infoCollector.infos.get(0).getInfo().get(CommitContext.NAME)); }
@Test public void invalidNamespacePrefix_node() throws Exception { NodeBuilder builder = mount.getRoot().builder(); builder.child("libs").child("foo:first"); mount.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); exception.expect(IllegalRepositoryStateException.class); exception.expectMessage("1 errors were found"); exception.expectMessage("invalid namespace prefix foo"); check("/libs/foo:first"); }
@Test public void invalidNamespacePrefix_property() throws Exception { NodeBuilder builder = mount.getRoot().builder(); builder.child("libs").setProperty("foo:prop", "value"); mount.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); exception.expect(IllegalRepositoryStateException.class); exception.expectMessage("1 errors were found"); exception.expectMessage("invalid namespace prefix foo"); check("/libs"); }
@Test public void startTimePresentInCommitInfo() throws Exception{ MemoryNodeStore store = new MemoryNodeStore(); NodeBuilder builder = store.getRoot().builder(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null) .setProperty(ASYNC_PROPERTY_NAME, "async"); builder.child("testRoot1").setProperty("foo", "abc"); // merge it back in store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); IndexingContextCapturingProvider provider = new IndexingContextCapturingProvider(); AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); async.run(); assertNotNull(provider.lastIndexingContext); CommitInfo info = provider.lastIndexingContext.getCommitInfo(); String indexStartTime = (String) info.getInfo().get(IndexConstants.CHECKPOINT_CREATION_TIME); assertNotNull(indexStartTime); }
@Test public void validatorProviderInvocation() throws Exception{ MemoryNodeStore store = new MemoryNodeStore(); IndexEditorProvider provider = new PropertyIndexEditorProvider(); NodeBuilder builder = store.getRoot().builder(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null) .setProperty(ASYNC_PROPERTY_NAME, "async"); builder.child("testRoot").setProperty("foo", "abc"); // merge it back in store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); CollectingValidatorProvider v = new CollectingValidatorProvider(); async.setValidatorProviders(ImmutableList.<ValidatorProvider>of(v)); async.run(); assertFalse(v.visitedPaths.isEmpty()); assertThat(v.visitedPaths, hasItem("/:async")); assertThat(v.visitedPaths, hasItem("/oak:index/rootIndex")); }
@Test(expected = IllegalRepositoryStateException.class) public void referenceableNodeIsDetected() throws CommitFailedException { MemoryNodeStore root = new MemoryNodeStore(); MemoryNodeStore mount = new MemoryNodeStore(); NodeBuilder builder = mount.getRoot().builder(); builder.child("first") .setProperty(PropertyStates.createProperty(JcrConstants.JCR_MIXINTYPES, Collections.singletonList(JcrConstants.MIX_REFERENCEABLE), Type.NAMES)) .setProperty(JcrConstants.JCR_UUID, UUID.randomUUID().toString()); mount.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); MountInfoProvider mip = Mounts.newBuilder() .readOnlyMount("first", "/first") .build(); NodeTypeMountedNodeStoreChecker checker = new NodeTypeMountedNodeStoreChecker(JcrConstants.MIX_REFERENCEABLE, "test error"); Context context = checker.createContext(root, mip); ErrorHolder errorHolder = new ErrorHolder(); checker.check(new MountedNodeStore(mip.getMountByName("first"), mount), TreeFactory.createReadOnlyTree(mount.getRoot()).getChild("first"), errorHolder, context); errorHolder.end(); }
@Before public void prepareRepository() throws Exception { MemoryNodeStore root = new MemoryNodeStore(); mount = new MemoryNodeStore(); NodeBuilder rootBuilder = root.getRoot().builder(); new InitialContent().initialize(rootBuilder); root.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); mip = Mounts.newBuilder() .readOnlyMount("first", "/first") .build(); checker = new NamespacePrefixNodestoreChecker(); context = checker.createContext(root, mip); }
@Test(expected = IllegalRepositoryStateException.class) public void versionableNode() throws CommitFailedException { MemoryNodeStore root = new MemoryNodeStore(); MemoryNodeStore mount = new MemoryNodeStore(); // create a child node that is versionable // note that we won't cover all checks here, we are only interested in seeing that at least one check is triggered NodeBuilder rootBuilder = mount.getRoot().builder(); NodeBuilder childNode = rootBuilder.setChildNode("readOnly").setChildNode("second").setChildNode("third"); childNode.setProperty(JcrConstants.JCR_ISCHECKEDOUT, false); childNode.setProperty(PropertyStates.createProperty(JcrConstants.JCR_MIXINTYPES , Collections.singletonList(JcrConstants.MIX_VERSIONABLE), Type.NAMES)); mount.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); MountInfoProvider mip = Mounts.newBuilder() .readOnlyMount("readOnly", "/readOnly") .build(); new CompositeNodeStore.Builder(mip, root) .addMount("readOnly", mount) .with(new NodeStoreChecksService(mip, Collections.singletonList(new NodeTypeMountedNodeStoreChecker(JcrConstants.MIX_VERSIONABLE, "test error")))) .build(); } }
@Before public void createFixture() throws CommitFailedException { globalStore = new MemoryNodeStore(); mountedStore = new MemoryNodeStore(); NodeBuilder rootBuilder = mountedStore.getRoot().builder(); rootBuilder.setChildNode("first").setChildNode("second").setChildNode("third"); rootBuilder.setChildNode("not-covered"); mountedStore.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); mip = Mounts.newBuilder() .readOnlyMount("first", "/first") .build(); mount = mip.getMountByName("first"); }
@Test public void asyncStateChanged() throws Exception{ AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider); async.run(); AsyncIndexUpdate async2 = new AsyncIndexUpdate("foo-async", store, provider); async2.run(); NodeState root = store.getRoot(); assertFalse(service.hasIndexerUpdatedForAnyLane(root, root)); NodeBuilder builder = store.getRoot().builder(); builder.child(":async").setProperty(AsyncIndexUpdate.lastIndexedTo("async"), 42L); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); assertTrue(service.hasIndexerUpdatedForAnyLane(root, store.getRoot())); }
public void run() throws CommitFailedException { MemoryNodeStore root = new MemoryNodeStore(INITIAL_CONTENT); MemoryNodeStore mount = new MemoryNodeStore(); NodeBuilder mountBuilder = mount.getRoot().builder(); initMountContent(mountBuilder); mount.merge(mountBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); MountInfoProvider mip = Mounts.newBuilder() .readOnlyMount("first", "/first") .build(); NodeTypeDefinitionNodeStoreChecker checker = new NodeTypeDefinitionNodeStoreChecker(); Context context = checker.createContext(root, mip); ErrorHolder errorHolder = new ErrorHolder(); checker.check(new MountedNodeStore(mip.getMountByName("first"), mount), TreeFactory.createReadOnlyTree(mount.getRoot()), errorHolder, context); errorHolder.end(); }
private void setLargeSubtree(String... path) throws CommitFailedException { MemoryNodeStore memStore = new MemoryNodeStore(); NodeBuilder builder = memStore.getRoot().builder(); NodeBuilder test = builder.child("test"); for (int i = 0; i < DocumentMK.UPDATE_LIMIT * 3; i++) { test.child("child-" + i); } memStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); DocumentNodeStore ns = new DocumentMK.Builder() .setUseSimpleRevision(true).getNodeStore(); builder = ns.getRoot().builder(); for (String name : path) { builder = builder.child(name); } Revision r1 = ns.newRevision(); // must trigger branch commit builder.setChildNode("test", memStore.getRoot().getChildNode("test")); Revision r2 = ns.newRevision(); assertTrue("setting a large subtree must trigger branch commits", r2.getTimestamp() - r1.getTimestamp() > 1); ns.dispose(); } }