@Override public Oak getOak(int clusterId) throws Exception { NodeStore nodeStore = getNodeStore(); Mounts.Builder mip = Mounts.newBuilder(); for (int i = 0; i < mounts; i++) { String[] paths = new String[pathsPerMount]; for (int j = 0; j < pathsPerMount; j++) { paths[j] = String.format("/mount-%d-path-%d", i, j); } mip.readOnlyMount("custom-mount-" + i, paths); } CompositeNodeStore.Builder builder = new CompositeNodeStore.Builder(mip.build(), nodeStore); for (int i = 0; i < mounts; i++) { builder.addMount("custom-mount-" + i, nodeStore); } return new Oak(builder.build()); }
@Override public Oak getOak(int clusterId) throws Exception { NodeStore nodeStore = getNodeStore(); Mounts.Builder mip = Mounts.newBuilder(); for (int i = 0; i < mounts; i++) { String[] paths = new String[pathsPerMount]; for (int j = 0; j < pathsPerMount; j++) { paths[j] = String.format("/mount-%d-path-%d", i, j); } mip.readOnlyMount("custom-mount-" + i, paths); } CompositeNodeStore.Builder builder = new CompositeNodeStore.Builder(mip.build(), nodeStore); for (int i = 0; i < mounts; i++) { builder.addMount("custom-mount-" + i, nodeStore); } return new Oak(builder.build()); }
/** * Verifies that a minimally-configured <tt>CompositeNodeStore</tt> can be registered successfully */ @Test public void bootstrap() { MemoryNodeStore mount = new MemoryNodeStore(); MemoryNodeStore global = new MemoryNodeStore(); MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("libs", "/libs", "/apps").build(); ctx.registerService(MountInfoProvider.class, mip); ctx.registerService(StatisticsProvider.class, StatisticsProvider.NOOP); ctx.registerService(NodeStoreProvider.class, new SimpleNodeStoreProvider(global), ImmutableMap.of("role", "composite-global", "registerDescriptors", Boolean.TRUE)); ctx.registerService(NodeStoreProvider.class, new SimpleNodeStoreProvider(mount), ImmutableMap.of("role", "composite-mount-libs")); ctx.registerInjectActivateService(new NodeStoreChecksService()); ctx.registerInjectActivateService(new CompositeNodeStoreService()); assertThat("No NodeStore registered", ctx.getService(NodeStore.class), notNullValue()); }
@Test public void referenceableNodeInWhitelistIsSkipped() throws CommitFailedException { MemoryNodeStore root = new MemoryNodeStore(); MemoryNodeStore mount = new MemoryNodeStore(); NodeBuilder builder = mount.getRoot().builder(); builder.child("first") .setProperty(PropertyStates.createProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_RESOURCE, Type.NAME)) .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", JcrConstants.NT_RESOURCE); 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(); } }
@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(); } }
@Test public void contributingStoreReturnsInfinity() { MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("libs", "/libs", "/libs1", "/libs2", "/libs3", "/libs4").build(); NodeStore globalStore = new MemoryNodeStore(); NodeStore libsStore = new MemoryNodeStore(); List<MountedNodeStore> mounts = Lists.newArrayList(); mounts.add(new MountedNodeStore(mip.getMountByName("libs"), libsStore)); CompositeNodeStore compositeNodeStore = new CompositeNodeStore(mip, globalStore, mounts); CompositeNodeStoreBuilder b = new CompositeNodeStoreBuilder(compositeNodeStore.ctx); TestingNodeState globalTestingNS = b.configureMount("/", 5); TestingNodeState libsTestingNS = b.configureMount("/libs", MAX_VALUE); CompositeNodeState mns = b.getNodeState(); assertEquals(MAX_VALUE, mns.getChildNodeCount(100)); assertEquals(5, globalTestingNS.fetchedChildren); assertEquals(0, libsTestingNS.fetchedChildren); globalTestingNS.fetchedChildren = 0; libsTestingNS.fetchedChildren = 0; assertEquals(MAX_VALUE, mns.builder().getChildNodeCount(100)); assertEquals(5, globalTestingNS.fetchedChildren); assertEquals(0, libsTestingNS.fetchedChildren); }
@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(); }
/** * Verifies that a missing mount will result in the node store not being registered */ @Test public void bootstrap_missingMount() { MemoryNodeStore mount = new MemoryNodeStore(); MemoryNodeStore global = new MemoryNodeStore(); MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("libs", "/libs", "/apps").readOnlyMount("missing", "/missing").build(); ctx.registerService(MountInfoProvider.class, mip); ctx.registerService(StatisticsProvider.class, StatisticsProvider.NOOP); ctx.registerService(NodeStoreProvider.class, new SimpleNodeStoreProvider(global), ImmutableMap.of("role", "composite-global", "registerDescriptors", Boolean.TRUE)); ctx.registerService(NodeStoreProvider.class, new SimpleNodeStoreProvider(mount), ImmutableMap.of("role", "composite-mount-libs")); ctx.registerInjectActivateService(new NodeStoreChecksService()); ctx.registerInjectActivateService(new CompositeNodeStoreService()); assertThat("NodeStore registered, but it should not have been", ctx.getService(NodeStore.class), nullValue()); }
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(); }
/** * Verifies that a missing global mount will result in the node store not being registered */ @Test public void bootstrap_missingGlobalMount() { MemoryNodeStore mount = new MemoryNodeStore(); MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("libs", "/libs", "/apps").build(); ctx.registerService(MountInfoProvider.class, mip); ctx.registerService(StatisticsProvider.class, StatisticsProvider.NOOP); ctx.registerService(NodeStoreProvider.class, new SimpleNodeStoreProvider(mount), ImmutableMap.of("role", "composite-mount-libs")); ctx.registerInjectActivateService(new NodeStoreChecksService()); ctx.registerInjectActivateService(new CompositeNodeStoreService()); assertThat("NodeStore registered, but it should not have been", ctx.getService(NodeStore.class), nullValue()); }
@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); }
@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"); }
@Override public NodeStore createNodeStore() { try { MountInfoProvider mip = Mounts.newBuilder() .readOnlyMount("temp", MOUNT_PATH) .build(); NodeStore globalStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build(); NodeStore tempMount = SegmentNodeStoreBuilders.builder(new MemoryStore()).build(); return new CompositeNodeStore.Builder(mip, globalStore).addMount("temp", tempMount).build(); } catch (IOException e) { throw new RuntimeException(); } }
@Before public void prepare() { mip = Mounts.newBuilder(). readOnlyMount("libs", "/libs", "/libs2"). readOnlyMount("apps", "/apps", "/apps2"). build(); }
@Test public void builderAcceptsMultipleReadOnlyStores() { MountInfoProvider mip = Mounts.newBuilder() .readOnlyMount("readOnly", "/readOnly") .readOnlyMount("readOnly2", "/readOnly2") .build(); new CompositeNodeStore.Builder(mip, new MemoryNodeStore()) .addMount("readOnly", new MemoryNodeStore()) .addMount("readOnly2", new MemoryNodeStore()) .build(); }
@Test public void clusterable() { MemoryNodeStore mount = new MemoryNodeStore(); DocumentNodeStore global = builderProvider.newBuilder().getNodeStore(); // DocumentNodeStore is clusterable assertNotNull(global.getInstanceId()); MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("libs", "/libs", "/apps").build(); CompositeNodeStore cns = new CompositeNodeStore.Builder(mip, global) .addMount("libs", mount).build(); assertTrue(cns instanceof Clusterable); }
@Override public NodeStore createNodeStore() { MountInfoProvider mip = Mounts.newBuilder() .readOnlyMount("temp", MOUNT_PATH) .build(); NodeStore globalStore = new MemoryNodeStore(); NodeStore tempMount = new MemoryNodeStore(); return new CompositeNodeStore.Builder(mip, globalStore).addMount("temp", tempMount).build(); }
@Test(expected = IllegalArgumentException.class) public void builderRejectsTooManyReadWriteStores_mixed() { MountInfoProvider mip = Mounts.newBuilder() .mount("temp", "/tmp") .readOnlyMount("readOnly", "/readOnly") .build(); new CompositeNodeStore.Builder(mip, new MemoryNodeStore()) .addMount("temp", new MemoryNodeStore()) .addMount("readOnly", new MemoryNodeStore()) .build(); }
private MountInfoProvider createMountInfoProvider(String... readOnlyPaths) { MountInfoProvider mountInfoProvider = Mounts.defaultMountInfoProvider(); if (readOnlyPaths.length > 0) { mountInfoProvider = Mounts.newBuilder().readOnlyMount("readOnly", readOnlyPaths).build(); } return mountInfoProvider; } }
@Test public void readOnlyMounting() throws Exception{ MountInfoProvider mip = Mounts.newBuilder() .mount("foo", "/a", "/b") .readOnlyMount("bar", "/x", "/y") .build(); assertTrue(mip.getMountByName("bar").isReadOnly()); assertFalse(mip.getMountByName("foo").isReadOnly()); }