Search in sources :

Example 51 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class HybridIndexTest method createRepository.

@Override
protected ContentRepository createRepository() {
    IndexCopier copier;
    try {
        copier = new IndexCopier(executorService, temporaryFolder.getRoot());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    MountInfoProvider mip = defaultMountInfoProvider();
    NRTIndexFactory nrtIndexFactory = new NRTIndexFactory(copier, clock, TimeUnit.MILLISECONDS.toSeconds(refreshDelta), StatisticsProvider.NOOP);
    LuceneIndexReaderFactory indexReaderFactory = new DefaultIndexReaderFactory(mip, copier);
    IndexTracker tracker = new IndexTracker(indexReaderFactory, nrtIndexFactory);
    LuceneIndexProvider provider = new LuceneIndexProvider(tracker);
    queue = new DocumentQueue(100, tracker, sameThreadExecutor());
    LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(copier, tracker, null, null, mip);
    editorProvider.setIndexingQueue(queue);
    LocalIndexObserver localIndexObserver = new LocalIndexObserver(queue, StatisticsProvider.NOOP);
    nodeStore = new MemoryNodeStore();
    Oak oak = new Oak(nodeStore).with(new InitialContent()).with(new OpenSecurityProvider()).with((QueryIndexProvider) provider).with((Observer) provider).with(localIndexObserver).with(editorProvider).with(new PropertyIndexEditorProvider()).with(new NodeTypeIndexProvider()).with(optionalEditorProvider).with(new NodeCounterEditorProvider()).withAsyncIndexing("async", TimeUnit.DAYS.toSeconds(1));
    wb = oak.getWhiteboard();
    return oak.createContentRepository();
}
Also used : NodeTypeIndexProvider(org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider) IndexTracker(org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) IOException(java.io.IOException) LuceneIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory) IndexCopier(org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopier) InitialContent(org.apache.jackrabbit.oak.InitialContent) LuceneIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) Oak(org.apache.jackrabbit.oak.Oak) DefaultIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory) LuceneIndexProvider(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider) Mounts.defaultMountInfoProvider(org.apache.jackrabbit.oak.spi.mount.Mounts.defaultMountInfoProvider) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) NodeCounterEditorProvider(org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider)

Example 52 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class CompositeChildrenCountTest method contributingStoreReturnsInfinity.

@Test
public void contributingStoreReturnsInfinity() {
    MountInfoProvider mip = Mounts.newBuilder().mount("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);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 53 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class CompositeChildrenCountTest method singleContributingStore.

@Test
public void singleContributingStore() {
    MountInfoProvider mip = Mounts.newBuilder().build();
    NodeStore globalStore = new MemoryNodeStore();
    CompositeNodeStore compositeNodeStore = new CompositeNodeStore.Builder(mip, globalStore).build();
    CompositeNodeStoreBuilder b = new CompositeNodeStoreBuilder(compositeNodeStore.ctx);
    b.configureMount("/", MAX_VALUE);
    assertEquals(MAX_VALUE, b.getNodeState().getChildNodeCount(123));
    b.clear().configureMount("/", 10);
    assertEquals(10, b.getNodeState().getChildNodeCount(200));
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) Test(org.junit.Test)

Example 54 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class CompositeCompareTest method nodesOutsideTheMountsAreIgnored.

@Test
public void nodesOutsideTheMountsAreIgnored() throws CommitFailedException {
    MountInfoProvider mip = Mounts.newBuilder().mount("libs", "/libs").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);
    NodeState empty = compositeNodeStore.getRoot();
    NodeBuilder builder = globalStore.getRoot().builder();
    builder.child("global-child-1");
    builder.child("global-child-2");
    globalStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    NodeBuilder libsBuilder = libsStore.getRoot().builder();
    libsBuilder.child("libs");
    libsBuilder.child("libs-child-1");
    libsBuilder.child("libs-child-2");
    libsStore.merge(libsBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    NodeState modified = compositeNodeStore.getRoot();
    final Set<String> addedChildren = newHashSet();
    modified.compareAgainstBaseState(empty, new DefaultNodeStateDiff() {

        @Override
        public boolean childNodeAdded(String name, NodeState after) {
            addedChildren.add(name);
            return true;
        }
    });
    assertEquals(ImmutableSet.of("global-child-1", "global-child-2", "libs"), addedChildren);
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) DefaultNodeStateDiff(org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 55 with MemoryNodeStore

use of org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore in project jackrabbit-oak by apache.

the class S3DataStoreStatsTest method testIsFileSyncedDifferentPaths.

@Test
public void testIsFileSyncedDifferentPaths() throws Exception {
    final String path1 = "path/to/node/1";
    final String path2 = "path/to/node/2";
    final String path3 = "shortpath";
    final String path4 = "a/very/very/long/path/leads/to/node/4";
    final List<String> paths = Lists.newArrayList(path1, path2, path3, path4);
    final String leadingSlashPath = "/" + path1;
    final List<String> blobContents = Lists.newArrayList("1", "2", "3", "4");
    final List<Blob> blobs = Lists.newArrayList(mock(Blob.class), mock(Blob.class), mock(Blob.class), mock(Blob.class));
    final List<String> blobIds = Lists.newArrayList(getIdForInputStream(getStream(blobContents.get(0))), getIdForInputStream(getStream(blobContents.get(1))), getIdForInputStream(getStream(blobContents.get(2))), getIdForInputStream(getStream(blobContents.get(3))));
    when(blobs.get(0).getContentIdentity()).thenReturn(blobIds.get(0));
    when(blobs.get(1).getContentIdentity()).thenReturn(blobIds.get(1));
    when(blobs.get(2).getContentIdentity()).thenReturn(blobIds.get(2));
    when(blobs.get(3).getContentIdentity()).thenReturn(blobIds.get(3));
    final NodeStore nodeStore = new MemoryNodeStore();
    final NodeBuilder rootBuilder = nodeStore.getRoot().builder();
    final List<NodeBuilder> builders = Lists.newArrayList();
    for (final String path : paths) {
        NodeBuilder builder = rootBuilder;
        for (final String nodeName : PathUtils.elements(path)) {
            builder = builder.child(nodeName);
        }
        builders.add(builder);
    }
    builders.get(0).setProperty("blob1", blobs.get(0));
    builders.get(1).setProperty("blob2", blobs.get(1));
    builders.get(2).setProperty("blob3", blobs.get(2));
    builders.get(3).setProperty("blob4", blobs.get(3));
    nodeStore.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    stats = new S3DataStoreStats();
    stats.nodeStore = nodeStore;
    stats.s3ds = autoSyncMockS3ds;
    final List<DataRecord> records = Lists.newArrayList();
    try {
        for (final String s : blobContents) {
            records.add(autoSyncMockS3ds.addRecord(getStream(s)));
        }
        for (final String path : Lists.newArrayList(path1, path2, path3, path4, leadingSlashPath)) {
            assertTrue(stats.isFileSynced(path));
        }
        for (final String invalidPath : Lists.newArrayList(path1 + "/", "/" + path1 + "/", "/path//to/node///1")) {
            try {
                stats.isFileSynced(invalidPath);
                // shouldn't get here on an invalid path
                assertFalse(false);
            } catch (AssertionError e) {
            // expected
            }
        }
    } finally {
        delete(autoSyncMockS3ds, records);
    }
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)92 Test (org.junit.Test)66 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)58 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)37 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)35 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)33 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)19 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)14 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)13 Oak (org.apache.jackrabbit.oak.Oak)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)7 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)7 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)7 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)6 InitialContent (org.apache.jackrabbit.oak.InitialContent)6 PropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup)6 Validator (org.apache.jackrabbit.oak.spi.commit.Validator)6 ApplyDiff (org.apache.jackrabbit.oak.spi.state.ApplyDiff)6 Semaphore (java.util.concurrent.Semaphore)5