SecondaryStoreCache implements DocumentNodeStateCache, SecondaryStoreRootObserver { @Nullable @Override public AbstractDocumentNodeState getDocumentNodeState(Path path, RevisionVector rootRevision, RevisionVector lastRev) { String p = path.toString(); PathFilter.Result result = pathFilter.filter(p); if (result != PathFilter.Result.INCLUDE) { unknownPaths.mark(); return null; } if (!DelegatingDocumentNodeState.hasMetaProps(store.getRoot())){ return null; } AbstractDocumentNodeState currentRoot = DelegatingDocumentNodeState.wrap(store.getRoot(), differ); if (lastRev.compareTo(currentRoot.getLastRevision()) > 0){ return null; } AbstractDocumentNodeState nodeState = findByMatchingLastRev(currentRoot, path, lastRev); if (nodeState != null){ headRevMatched.mark(); return nodeState; } AbstractDocumentNodeState matchingRoot = findMatchingRoot(rootRevision); if (matchingRoot != null){ NodeState state = NodeStateUtils.getNode(matchingRoot, p); if (state.exists()){ AbstractDocumentNodeState docState = asDocState(state); prevRevMatched.mark(); return docState; } } knownMissed.mark(); return null; } SecondaryStoreCache(NodeStore nodeStore, NodeStateDiffer differ, PathFilter pathFilter,
                               StatisticsProvider statisticsProvider); @Nullable @Override AbstractDocumentNodeState getDocumentNodeState(Path path, RevisionVector rootRevision,
                                                          RevisionVector lastRev); @Override boolean isCached(Path path); @Override void contentChanged(@NotNull AbstractDocumentNodeState root);  }
@Test public void basicTest() throws Exception{ SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty)); NodeBuilder nb = primary.getRoot().builder(); create(nb, "/a/b", "/a/c", "/x/y/z"); merge(nb); RevisionVector rv1 = new RevisionVector(new Revision(1,0,1)); RevisionVector rv2 = new RevisionVector(new Revision(1,0,3)); assertNull(cache.getDocumentNodeState(Path.fromString("/a/b"), rv1, rv2)); assertNull(cache.getDocumentNodeState(Path.fromString("/x"), rv1, rv2)); }
@Test public void updateAndReadAtReadRev() throws Exception{ SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty)); NodeBuilder nb = primary.getRoot().builder(); create(nb, "/a/b", "/a/c", "/x/y/z"); AbstractDocumentNodeState r1 = merge(nb); nb = primary.getRoot().builder(); create(nb, "/a/e/d"); AbstractDocumentNodeState r2 = merge(nb); AbstractDocumentNodeState a_r2 = documentState(r2, "/a/c"); AbstractDocumentNodeState result = cache.getDocumentNodeState(Path.fromString("/a/c"), r2.getRootRevision(), a_r2.getLastRevision()); assertTrue(EqualsDiff.equals(a_r2, result)); assertTrue(result.hasProperty(DelegatingDocumentNodeState.PROP_LAST_REV)); assertFalse(result.hasProperty(DelegatingDocumentNodeState.PROP_REVISION)); assertTrue(secondary.getRoot().hasProperty(DelegatingDocumentNodeState.PROP_LAST_REV)); assertTrue(secondary.getRoot().hasProperty(DelegatingDocumentNodeState.PROP_REVISION)); nb = primary.getRoot().builder(); nb.child("a").child("c").remove(); AbstractDocumentNodeState r3 = merge(nb); result = cache.getDocumentNodeState(Path.fromString("/a/c"), r3.getRootRevision(), a_r2.getLastRevision()); assertNull(result); }
@Test public void updateAndReadAtPrevRevision() throws Exception { SecondaryStoreCache cache = createCache(new PathFilter(of("/a"), empty)); NodeBuilder nb = primary.getRoot().builder(); create(nb, "/a/b", "/a/c"); AbstractDocumentNodeState r0 = merge(nb); AbstractDocumentNodeState a_c_0 = documentState(primary.getRoot(), "/a/c"); nb = primary.getRoot().builder(); create(nb, "/a/c/d"); AbstractDocumentNodeState r1 = merge(nb); AbstractDocumentNodeState a_c_1 = documentState(primary.getRoot(), "/a/c"); AbstractDocumentNodeState result = cache.getDocumentNodeState(Path.fromString("/a/c"), r1.getRootRevision(), a_c_1.getLastRevision()); assertTrue(EqualsDiff.equals(a_c_1, result)); result = cache.getDocumentNodeState(Path.fromString("/a/c"), r0.getRootRevision(), a_c_0.getLastRevision()); assertTrue(EqualsDiff.equals(a_c_0, result)); }