Search in sources :

Example 1 with PathFilter

use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.

the class NodeCacheTest method cachePredicateSync.

@Test
public void cachePredicateSync() throws Exception {
    PathFilter pf = new PathFilter(asList("/a"), emptyList());
    Predicate<String> p = path -> pf.filter(path) == PathFilter.Result.INCLUDE;
    initializeNodeStore(false, b -> b.setNodeCachePredicate(p));
    NodeBuilder builder = ns.getRoot().builder();
    builder.child("a").child("c1");
    builder.child("b").child("c2");
    ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // Do a read again
    ns.getRoot().getChildNode("a").getChildNode("c1");
    ns.getRoot().getChildNode("b").getChildNode("c2");
    assertNotContains(nodeCache, "/b");
    assertNotContains(nodeCache, "/b/c2");
    assertContains(nodeCache, "/a");
    assertContains(nodeCache, "/a/c1");
}
Also used : CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) StatsOptions(org.apache.jackrabbit.oak.stats.StatsOptions) Collections.singletonList(java.util.Collections.singletonList) EmptyHook(org.apache.jackrabbit.oak.spi.commit.EmptyHook) Lists(com.google.common.collect.Lists) DocumentMKBuilderProvider(org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider) DocumentNodeStateCache(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStateCache) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Assert.fail(org.junit.Assert.fail) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) JsopDiff(org.apache.jackrabbit.oak.json.JsopDiff) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Collections.emptyList(java.util.Collections.emptyList) Counting(org.apache.jackrabbit.oak.stats.Counting) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) File(java.io.File) Executors(java.util.concurrent.Executors) Consumer(java.util.function.Consumer) List(java.util.List) Rule(org.junit.Rule) Predicate(com.google.common.base.Predicate) RemovalCause(com.google.common.cache.RemovalCause) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) DocumentNodeState(org.apache.jackrabbit.oak.plugins.document.DocumentNodeState) DefaultStatisticsProvider(org.apache.jackrabbit.oak.stats.DefaultStatisticsProvider) PathRev(org.apache.jackrabbit.oak.plugins.document.PathRev) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) MeterStats(org.apache.jackrabbit.oak.stats.MeterStats) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with PathFilter

use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.

the class SecondaryStoreObserverTest method childNodeDeleted.

@Test
public void childNodeDeleted() throws Exception {
    PathFilter pathFilter = new PathFilter(of("/a"), empty);
    SecondaryStoreObserver observer = createBuilder(pathFilter).buildObserver();
    primary.addObserver(observer);
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/b", "/a/c", "/x/y/z");
    primary.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    nb = primary.getRoot().builder();
    nb.child("a").child("c").remove();
    primary.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertFalse(NodeStateUtils.getNode(secondaryRoot(), "/a/c").exists());
}
Also used : PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 3 with PathFilter

use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.

the class SecondaryStoreObserverTest method childNodeAdded.

@Test
public void childNodeAdded() throws Exception {
    PathFilter pathFilter = new PathFilter(of("/a"), empty);
    SecondaryStoreObserver observer = createBuilder(pathFilter).buildObserver();
    primary.addObserver(observer);
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/b", "/a/c", "/x/y/z");
    primary.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    nb = primary.getRoot().builder();
    create(nb, "/a/d");
    primary.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertMetaState(primary.getRoot(), secondaryRoot(), "/a/d");
    assertMetaState(primary.getRoot(), secondaryRoot(), "/a");
}
Also used : PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 4 with PathFilter

use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.

the class SecondaryStoreObserverTest method childNodeChangedAndExclude.

@Test
public void childNodeChangedAndExclude() throws Exception {
    PathFilter pathFilter = new PathFilter(of("/a"), of("a/b"));
    SecondaryStoreObserver observer = createBuilder(pathFilter).buildObserver();
    primary.addObserver(observer);
    NodeBuilder nb = primary.getRoot().builder();
    create(nb, "/a/b", "/a/c", "/x/y/z");
    primary.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    nb = primary.getRoot().builder();
    create(nb, "/a/d", "/a/b/e");
    primary.merge(nb, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    assertMetaState(primary.getRoot(), secondaryRoot(), "/a/d");
}
Also used : PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with PathFilter

use of org.apache.jackrabbit.oak.spi.filter.PathFilter in project jackrabbit-oak by apache.

the class SecondaryStoreCacheTest method bundledNodes.

@Test
public void bundledNodes() throws Exception {
    SecondaryStoreCache cache = createCache(new PathFilter(of("/"), empty));
    primary.setNodeStateCache(cache);
    NodeBuilder builder = primary.getRoot().builder();
    new InitialContent().initialize(builder);
    BundlingConfigInitializer.INSTANCE.initialize(builder);
    merge(builder);
    BundledTypesRegistry registry = BundledTypesRegistry.from(NodeStateUtils.getNode(primary.getRoot(), BundlingConfigHandler.CONFIG_PATH));
    assertNotNull("DocumentBundling not found to be enabled for nt:file", registry.getBundlor(newNode("nt:file").getNodeState()));
    // 1. Create a file node
    builder = primary.getRoot().builder();
    NodeBuilder fileNode = newNode("nt:file");
    fileNode.child("jcr:content").setProperty("jcr:data", "foo");
    builder.child("test").setChildNode("book.jpg", fileNode.getNodeState());
    merge(builder);
    // 2. Assert that bundling is working
    assertNull(getNodeDocument("/test/book.jpg/jcr:content"));
    // 3. Now update the file node
    builder = primary.getRoot().builder();
    builder.getChildNode("test").getChildNode("book.jpg").getChildNode("jcr:content").setProperty("foo", "bar");
    merge(builder);
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) BundledTypesRegistry(org.apache.jackrabbit.oak.plugins.document.bundlor.BundledTypesRegistry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

PathFilter (org.apache.jackrabbit.oak.spi.filter.PathFilter)16 Test (org.junit.Test)13 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)12 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)6 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)4 Predicate (com.google.common.base.Predicate)3 Collections.emptyList (java.util.Collections.emptyList)3 StatisticsProvider (org.apache.jackrabbit.oak.stats.StatisticsProvider)3 RemovalCause (com.google.common.cache.RemovalCause)2 Lists (com.google.common.collect.Lists)2 File (java.io.File)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Executors (java.util.concurrent.Executors)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Consumer (java.util.function.Consumer)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Predicates (com.google.common.base.Predicates)1 Strings (com.google.common.base.Strings)1