Search in sources :

Example 6 with DepthTreeIterator

use of org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator in project GeoGig by boundlessgeo.

the class RevTreeBuilderTest method testRemove.

@Test
public void testRemove() throws Exception {
    final int numEntries = 1000;
    ObjectId treeId = createAndSaveTree(numEntries, true);
    final RevTree tree = odb.getTree(treeId);
    // collect some keys to remove
    final Set<String> removedKeys = new HashSet<String>();
    {
        int i = 0;
        DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN);
        for (; it.hasNext(); i++) {
            NodeRef entry = it.next();
            if (i % 10 == 0) {
                removedKeys.add(entry.path());
            }
        }
        assertEquals(100, removedKeys.size());
    }
    final RevTreeBuilder builder = tree.builder(odb);
    for (String key : removedKeys) {
        assertTrue(builder.get(key).isPresent());
        builder.remove(key);
        assertFalse(builder.get(key).isPresent());
    }
    final RevTree tree2 = builder.build();
    for (String key : removedKeys) {
        assertFalse(repo.getTreeChild(tree2, key).isPresent());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NodeRef (org.locationtech.geogig.api.NodeRef)6 DepthTreeIterator (org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator)6 ObjectId (org.locationtech.geogig.api.ObjectId)5 RevTree (org.locationtech.geogig.api.RevTree)5 Test (org.junit.Test)3 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)3 HashSet (java.util.HashSet)2 Function (com.google.common.base.Function)1 Stopwatch (com.google.common.base.Stopwatch)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)1 Ref (org.locationtech.geogig.api.Ref)1 RevCommit (org.locationtech.geogig.api.RevCommit)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1 RevObject (org.locationtech.geogig.api.RevObject)1 TYPE (org.locationtech.geogig.api.RevObject.TYPE)1 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)1 Feature (org.opengis.feature.Feature)1