Search in sources :

Example 31 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class PreOrderDiffWalkTest method testLeafLeafChanged.

@Test
public void testLeafLeafChanged() {
    // two leaf trees
    final RevTree left;
    final RevTree right;
    final Node nodeChange1 = Node.create("f2", ObjectId.forString("forcechange"), ObjectId.NULL, TYPE.FEATURE, null);
    final Node nodeChange2 = Node.create("f3", ObjectId.forString("fakefake"), ObjectId.NULL, TYPE.FEATURE, null);
    {
        left = createFeaturesTree(leftSource, "f", 5).build();
        // change two nodes
        RevTreeBuilder builder = createFeaturesTree(rightSource, "f", 5);
        builder.put(nodeChange1);
        builder.put(nodeChange2);
        right = builder.build();
    }
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(left, right, leftSource, rightSource);
    when(consumer.tree(any(Node.class), any(Node.class))).thenReturn(true);
    visitor.walk(consumer);
    // call of the root tree nodes
    verify(consumer, times(1)).tree(any(Node.class), any(Node.class));
    ArgumentCaptor<Node> larg = ArgumentCaptor.forClass(Node.class);
    ArgumentCaptor<Node> rarg = ArgumentCaptor.forClass(Node.class);
    verify(consumer, times(2)).feature(larg.capture(), rarg.capture());
    assertEquals(2, larg.getAllValues().size());
    assertEquals(2, rarg.getAllValues().size());
    // the two added nodes
    Node n1 = featureNode("f", 2);
    Node n2 = featureNode("f", 3);
    assertTrue(larg.getAllValues().contains(n1));
    assertTrue(larg.getAllValues().contains(n2));
    assertTrue(rarg.getAllValues().contains(nodeChange1));
    assertTrue(rarg.getAllValues().contains(nodeChange2));
    verify(consumer, times(1)).endTree(any(Node.class), any(Node.class));
    verifyNoMoreInteractions(consumer);
}
Also used : Node(org.locationtech.geogig.api.Node) TreeTestSupport.featureNode(org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 32 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class DepthTreeIteratorTest method testRecursive.

@Test
public void testRecursive() {
    assertEquals(0, list(emptyTree, Strategy.RECURSIVE).size());
    assertEquals(100, list(featuresLeafTree, Strategy.RECURSIVE).size());
    assertEquals(treesLeafTree.size() + treesLeafTree.numTrees(), list(treesLeafTree, Strategy.RECURSIVE).size());
    assertEquals(mixedLeafTree.size() + mixedLeafTree.numTrees(), list(mixedLeafTree, Strategy.RECURSIVE).size());
    assertEquals(featuresBucketsTree.size(), list(featuresBucketsTree, Strategy.RECURSIVE).size());
    int numSubTrees = RevTree.NORMALIZED_SIZE_LIMIT + 1;
    int featuresPerTree = RevTree.NORMALIZED_SIZE_LIMIT + 1;
    RevTreeBuilder builder = createTreesTree(source, numSubTrees, featuresPerTree, metadataId);
    for (int i = 0; i < 25000; i++) {
        builder.put(featureNode("f", i));
    }
    RevTree mixedBucketsTree = builder.build();
    assertEquals(mixedBucketsTree.size() + mixedBucketsTree.numTrees(), list(mixedBucketsTree, Strategy.RECURSIVE).size());
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 33 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class DepthTreeIteratorTest method testRecursiveFeaturesOnly.

@Test
public void testRecursiveFeaturesOnly() {
    assertEquals(0, list(emptyTree, Strategy.RECURSIVE_FEATURES_ONLY).size());
    assertEquals(100, list(featuresLeafTree, Strategy.RECURSIVE_FEATURES_ONLY).size());
    assertEquals(treesLeafTree.size(), list(treesLeafTree, Strategy.RECURSIVE_FEATURES_ONLY).size());
    assertEquals(mixedLeafTree.size(), list(mixedLeafTree, Strategy.RECURSIVE_FEATURES_ONLY).size());
    assertEquals(featuresBucketsTree.size(), list(featuresBucketsTree, Strategy.RECURSIVE_FEATURES_ONLY).size());
    int numSubTrees = RevTree.NORMALIZED_SIZE_LIMIT + 1;
    int featuresPerTree = RevTree.NORMALIZED_SIZE_LIMIT + 1;
    RevTreeBuilder builder = createTreesTree(source, numSubTrees, featuresPerTree, metadataId);
    for (int i = 0; i < 25000; i++) {
        builder.put(featureNode("f", i));
    }
    RevTree mixedBucketsTree = builder.build();
    assertEquals(mixedBucketsTree.size(), list(mixedBucketsTree, Strategy.RECURSIVE_FEATURES_ONLY).size());
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 34 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class DepthTreeIteratorTest method setUp.

@Before
public void setUp() {
    source = new HeapObjectDatabse();
    source.open();
    metadataId = ObjectId.forString("fake id");
    treePath = "";
    emptyTree = RevTree.EMPTY;
    featuresLeafTree = createFeaturesTree(source, "featuresLeafTree", 100).build();
    assertTrue(featuresLeafTree.features().isPresent());
    treesLeafTree = createTreesTree(source, 100, 10, metadataId).build();
    assertTrue(treesLeafTree.trees().isPresent());
    RevTreeBuilder builder = createTreesTree(source, 10, 10, metadataId);
    for (int i = 0; i < 100; i++) {
        builder.put(featureNode("feature.", i));
    }
    mixedLeafTree = builder.build();
    featuresBucketsTree = createFeaturesTree(source, "feature.", 25000).build();
}
Also used : HeapObjectDatabse(org.locationtech.geogig.storage.memory.HeapObjectDatabse) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) Before(org.junit.Before)

Example 35 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class DiffCountConsumerTest method testChildrenChildren.

@Test
public void testChildrenChildren() {
    RevTreeBuilder builder = new RevTreeBuilder(odb, childrenFeatureTree);
    RevTree changed = builder.remove("3").build();
    assertEquals(1, count(childrenFeatureTree, changed).featureCount());
    assertEquals(1, count(changed, childrenFeatureTree).featureCount());
    changed = builder.put(Node.create("new", FAKE_FEATURE_ID, ObjectId.NULL, TYPE.FEATURE, null)).build();
    assertEquals(2, count(childrenFeatureTree, changed).featureCount());
    assertEquals(2, count(changed, childrenFeatureTree).featureCount());
    changed = builder.put(Node.create("1", FAKE_FEATURE_ID_CHANGED, ObjectId.NULL, TYPE.FEATURE, null)).build();
    assertEquals(3, count(childrenFeatureTree, changed).featureCount());
    assertEquals(3, count(changed, childrenFeatureTree).featureCount());
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Aggregations

RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)58 RevTree (org.locationtech.geogig.api.RevTree)47 ObjectId (org.locationtech.geogig.api.ObjectId)27 Test (org.junit.Test)25 NodeRef (org.locationtech.geogig.api.NodeRef)24 Node (org.locationtech.geogig.api.Node)14 DepthSearch (org.locationtech.geogig.repository.DepthSearch)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)5 Stopwatch (com.google.common.base.Stopwatch)4 Envelope (com.vividsolutions.jts.geom.Envelope)4 Map (java.util.Map)4 Context (org.locationtech.geogig.api.Context)4 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)4 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)4 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)4 Before (org.junit.Before)3 FindOrCreateSubtree (org.locationtech.geogig.api.plumbing.FindOrCreateSubtree)3 WriteBack (org.locationtech.geogig.api.plumbing.WriteBack)3 DepthTreeIterator (org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator)3 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3