@Test public void testSkipAddedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = testSupport.createTreesTree(leftSource, 2, 10, metadataId); RevTree right = testSupport.createTreesTree(rightSource, 3, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the added tree when(consumer.tree((NodeRef) isNull(), any(NodeRef.class))).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the new subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Before public void setUp() { source = new HeapObjectDatabase(); source.open(); metadataId = RevObjectTestSupport.hashString("fake id"); treePath = ""; emptyTree = RevTree.EMPTY; featuresLeafTree = RevObjectTestSupport.INSTANCE.createFeaturesTree(source, "featuresLeafTree", 100); assertFalse(featuresLeafTree.features().isEmpty()); treesLeafTree = RevObjectTestSupport.INSTANCE.createTreesTree(source, 100, 10, metadataId); assertFalse(treesLeafTree.trees().isEmpty()); RevTreeBuilder builder = RevObjectTestSupport.INSTANCE.createTreesTreeBuilder(source, 10, 10, metadataId); for (int i = 0; i < 100; i++) { builder.put(featureNode("feature.", i)); } mixedLeafTree = builder.build(); source.put(mixedLeafTree); featuresBucketsTree = RevObjectTestSupport.INSTANCE.createFeaturesTree(source, "feature.", 25000); }
@Test public void testSkipRemovedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = createTreesTree(leftSource, 3, 10, metadataId); RevTree right = createTreesTree(rightSource, 2, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the removed tree when(consumer.tree(any(NodeRef.class), (NodeRef) isNull())).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the removed subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Before public void setUp() { source = new HeapObjectDatabase(); source.open(); metadataId = RevObjectTestSupport.hashString("fake id"); treePath = ""; emptyTree = RevTree.EMPTY; featuresLeafTree = createFeaturesTree(source, "featuresLeafTree", 100); assertFalse(featuresLeafTree.features().isEmpty()); treesLeafTree = createTreesTree(source, 100, 10, metadataId); assertFalse(treesLeafTree.trees().isEmpty()); RevTreeBuilder builder = createTreesTreeBuilder(source, 10, 10, metadataId); for (int i = 0; i < 100; i++) { builder.put(featureNode("feature.", i)); } mixedLeafTree = builder.build(); source.put(mixedLeafTree); featuresBucketsTree = createFeaturesTree(source, "feature.", 25000); }
@Test public void testSkipAddedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = RevObjectTestSupport.INSTANCE.createTreesTree(leftSource, 2, 10, metadataId); RevTree right = RevObjectTestSupport.INSTANCE.createTreesTree(rightSource, 3, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the added tree when(consumer.tree((NodeRef) isNull(), any(NodeRef.class))).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the new subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipRemovedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = RevObjectTestSupport.INSTANCE.createTreesTree(leftSource, 3, 10, metadataId); RevTree right = RevObjectTestSupport.INSTANCE.createTreesTree(rightSource, 2, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the removed tree when(consumer.tree(any(NodeRef.class), (NodeRef) isNull())).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the removed subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipAddedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = createTreesTree(leftSource, 2, 10, metadataId); RevTree right = createTreesTree(rightSource, 3, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the added tree when(consumer.tree((NodeRef) isNull(), any(NodeRef.class))).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the new subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testSkipRemovedTree() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = testSupport.createTreesTree(leftSource, 3, 10, metadataId); RevTree right = testSupport.createTreesTree(rightSource, 2, 10, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume the root tree when(consumer.tree(eq(lroot), eq(rroot))).thenReturn(true); // but skip the removed tree when(consumer.tree(any(NodeRef.class), (NodeRef) isNull())).thenReturn(false); visitor.walk(consumer); // one call to tree() for the root tree, and another for the removed subtree verify(consumer, times(2)).tree(any(NodeRef.class), any(NodeRef.class)); // but no calls to feature() as we returned false on the second call to tree() verify(consumer, times(0)).feature(any(NodeRef.class), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testLeafLeafWithSubStrees() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = RevObjectTestSupport.INSTANCE.createTreesTree(leftSource, 2, 100, metadataId); RevTree right = RevObjectTestSupport.INSTANCE.createTreesTree(rightSource, 3, 100, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume any tree diff when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); visitor.walk(consumer); // capture calls to consumer.tree(node, node) ArgumentCaptor<NodeRef> larg = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rarg = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(2)).tree(larg.capture(), rarg.capture()); assertEquals(2, larg.getAllValues().size()); assertEquals("left side arg for the first tree() call is not the left root", lroot, larg.getAllValues().get(0)); assertNull("left side arg for the second tree() call should be null", larg.getAllValues().get(1)); assertEquals(2, rarg.getAllValues().size()); assertEquals(rroot, rarg.getAllValues().get(0)); assertNotNull(rarg.getAllValues().get(1)); verify(consumer, times(100)).feature((NodeRef) isNull(), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testLeafLeafWithSubStrees() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = testSupport.createTreesTree(leftSource, 2, 100, metadataId); RevTree right = testSupport.createTreesTree(rightSource, 3, 100, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume any tree diff when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); visitor.walk(consumer); // capture calls to consumer.tree(node, node) ArgumentCaptor<NodeRef> larg = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rarg = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(2)).tree(larg.capture(), rarg.capture()); assertEquals(2, larg.getAllValues().size()); assertEquals("left side arg for the first tree() call is not the left root", lroot, larg.getAllValues().get(0)); assertNull("left side arg for the second tree() call should be null", larg.getAllValues().get(1)); assertEquals(2, rarg.getAllValues().size()); assertEquals(rroot, rarg.getAllValues().get(0)); assertNotNull(rarg.getAllValues().get(1)); verify(consumer, times(100)).feature((NodeRef) isNull(), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Test public void testLeafLeafWithSubStrees() { // two leaf trees ObjectId metadataId = RevObjectTestSupport.hashString("fake"); RevTree left = createTreesTree(leftSource, 2, 100, metadataId); RevTree right = createTreesTree(rightSource, 3, 100, metadataId); PreOrderDiffWalk visitor = newVisitor(left, right); final NodeRef lroot = nodeFor(left); final NodeRef rroot = nodeFor(right); // consume any tree diff when(consumer.tree(any(NodeRef.class), any(NodeRef.class))).thenReturn(true); visitor.walk(consumer); // capture calls to consumer.tree(node, node) ArgumentCaptor<NodeRef> larg = ArgumentCaptor.forClass(NodeRef.class); ArgumentCaptor<NodeRef> rarg = ArgumentCaptor.forClass(NodeRef.class); verify(consumer, times(2)).tree(larg.capture(), rarg.capture()); assertEquals(2, larg.getAllValues().size()); assertEquals("left side arg for the first tree() call is not the left root", lroot, larg.getAllValues().get(0)); assertNull("left side arg for the second tree() call should be null", larg.getAllValues().get(1)); assertEquals(2, rarg.getAllValues().size()); assertEquals(rroot, rarg.getAllValues().get(0)); assertNotNull(rarg.getAllValues().get(1)); verify(consumer, times(100)).feature((NodeRef) isNull(), any(NodeRef.class)); verify(consumer, times(2)).endTree(any(NodeRef.class), any(NodeRef.class)); verifyNoMoreInteractions(consumer); }
@Before public void before() { ObjectStore store = new HeapObjectStore(); store.open(); cache = mock(TreeCache.class); featuresTree = createFeaturesTree(store, "f", 512); treesTree = createTreesTree(store, 2, 200, RevObjectTestSupport.hashString("test")); }
final int totalFeatures = numSubTrees * featuresPerSubtre; final ObjectId metadataId = hashString("fakeid"); final RevTree tree = RevObjectTestSupport.INSTANCE.createTreesTree(db, numSubTrees, featuresPerSubtre, metadataId); final List<NodeRef> treeNodes;
final int totalFeatures = numSubTrees * featuresPerSubtre; final ObjectId metadataId = hashString("fakeid"); final RevTree tree = createTreesTree(db, numSubTrees, featuresPerSubtre, metadataId); final List<NodeRef> treeNodes; final List<NodeRef> featureNodes;