Search in sources :

Example 51 with RevTreeBuilder

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

the class DiffCountConsumerTest method testBucketBucketRemove.

@Test
public void testBucketBucketRemove() {
    RevTreeBuilder builder = new RevTreeBuilder(odb, bucketsFeatureTree);
    RevTree changed;
    changed = builder.remove("3").build();
    assertEquals(1, count(bucketsFeatureTree, changed).featureCount());
    assertEquals(1, count(changed, bucketsFeatureTree).featureCount());
    for (int i = 0; i < RevTree.NORMALIZED_SIZE_LIMIT - 1; i++) {
        builder.remove(String.valueOf(i));
    }
    changed = builder.build();
    assertEquals(RevTree.NORMALIZED_SIZE_LIMIT + 1, changed.size());
    assertTrue(changed.buckets().isPresent());
    assertEquals(RevTree.NORMALIZED_SIZE_LIMIT - 1, count(bucketsFeatureTree, changed).featureCount());
    assertEquals(RevTree.NORMALIZED_SIZE_LIMIT - 1, count(changed, bucketsFeatureTree).featureCount());
    builder.remove(String.valueOf(RevTree.NORMALIZED_SIZE_LIMIT + 1));
    changed = builder.build();
    assertEquals(RevTree.NORMALIZED_SIZE_LIMIT, changed.size());
    assertFalse(changed.buckets().isPresent());
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 52 with RevTreeBuilder

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

the class DiffCountConsumerTest method testBucketBucketAdd.

@Test
public void testBucketBucketAdd() {
    RevTreeBuilder builder = new RevTreeBuilder(odb, bucketsFeatureTree);
    final int initialSize = (int) bucketsFeatureTree.size();
    final int added = 1 + 2 * RevTree.NORMALIZED_SIZE_LIMIT;
    for (int i = initialSize; i < (initialSize + added); i++) {
        builder.put(featureRef("", i));
    }
    RevTree changed = builder.build();
    assertEquals(initialSize + added, changed.size());
    assertEquals(added, count(bucketsFeatureTree, changed).featureCount());
    assertEquals(added, count(changed, bucketsFeatureTree).featureCount());
    assertEquals(added, count(bucketsFeatureTree, changed).getFeaturesAdded());
    assertEquals(0, count(bucketsFeatureTree, changed).getFeaturesChanged());
    assertEquals(0, count(bucketsFeatureTree, changed).getFeaturesRemoved());
    // invert the comparison
    assertEquals(0, count(changed, bucketsFeatureTree).getFeaturesAdded());
    assertEquals(added, count(changed, bucketsFeatureTree).getFeaturesRemoved());
    assertEquals(0, count(changed, bucketsFeatureTree).getFeaturesChanged());
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 53 with RevTreeBuilder

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

the class DiffCountConsumerTest method testBucketBucketChange.

@Test
public void testBucketBucketChange() {
    RevTreeBuilder builder;
    RevTree changed;
    builder = new RevTreeBuilder(odb, bucketsFeatureTree);
    changed = builder.put(Node.create("1023", FAKE_FEATURE_ID_CHANGED, ObjectId.NULL, TYPE.FEATURE, null)).build();
    DiffObjectCount count = count(bucketsFeatureTree, changed);
    assertEquals(1, count.featureCount());
    assertEquals(0, count.treeCount());
    count = count(changed, bucketsFeatureTree);
    assertEquals(1, count.featureCount());
    assertEquals(0, count.treeCount());
    builder = new RevTreeBuilder(odb, bucketsFeatureTree);
    int expected = 0;
    for (int i = 0; i < bucketsFeatureTree.size(); i += 2) {
        changed = builder.put(Node.create(String.valueOf(i), FAKE_FEATURE_ID_CHANGED, ObjectId.NULL, TYPE.FEATURE, null)).build();
        expected++;
    }
    changed = builder.build();
    assertEquals(expected, count(bucketsFeatureTree, changed).featureCount());
    assertEquals(expected, count(changed, bucketsFeatureTree).featureCount());
    assertEquals(expected, count(bucketsFeatureTree, changed).getFeaturesChanged());
    assertEquals(expected, count(changed, bucketsFeatureTree).getFeaturesChanged());
    assertEquals(0, count(changed, bucketsFeatureTree).getFeaturesAdded());
    assertEquals(0, count(changed, bucketsFeatureTree).getFeaturesRemoved());
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 54 with RevTreeBuilder

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

the class DiffCountConsumerTest method setUp.

@Before
public void setUp() {
    odb = new HeapObjectDatabse();
    odb.open();
    {
        RevTreeBuilder builder = createFeaturesTree("", 10);
        this.childrenFeatureTree = builder.build();
    }
    {
        RevTreeBuilder rootBuilder = new RevTreeBuilder(odb);
        childTree1 = createFeaturesTree("tree1", 10);
        createFeatureTypesTree(rootBuilder, "tree1", childTree1);
        childTree2 = createFeaturesTree("tree2", 5);
        createFeatureTypesTree(rootBuilder, "tree2", childTree2);
        childrenFeatureTypesTree = rootBuilder.build();
    }
    {
        RevTreeBuilder builder = createFeaturesTree("", 2 * RevTree.NORMALIZED_SIZE_LIMIT);
        this.bucketsFeatureTree = builder.build();
        assertTrue(bucketsFeatureTree.buckets().isPresent());
    }
}
Also used : HeapObjectDatabse(org.locationtech.geogig.storage.memory.HeapObjectDatabse) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) Before(org.junit.Before)

Example 55 with RevTreeBuilder

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

the class Index method stage.

/**
     * Stages the changes indicated by the {@link DiffEntry} iterator.
     * 
     * @param progress the progress listener for the process
     * @param unstaged an iterator for the unstaged changes
     * @param numChanges number of unstaged changes
     */
@Override
public void stage(final ProgressListener progress, final Iterator<DiffEntry> unstaged, final long numChanges) {
    int i = 0;
    progress.started();
    final RevTree currentIndexHead = getTree();
    Map<String, RevTreeBuilder> parentTress = Maps.newHashMap();
    Map<String, ObjectId> parentMetadataIds = Maps.newHashMap();
    Set<String> removedTrees = Sets.newHashSet();
    StagingDatabase database = getDatabase();
    while (unstaged.hasNext()) {
        final DiffEntry diff = unstaged.next();
        final String fullPath = diff.oldPath() == null ? diff.newPath() : diff.oldPath();
        final String parentPath = NodeRef.parentPath(fullPath);
        /*
             * TODO: revisit, ideally the list of diff entries would come with one single entry for
             * the whole removed tree instead of that one and every single children of it.
             */
        if (removedTrees.contains(parentPath)) {
            continue;
        }
        if (null == parentPath) {
            // it is the root tree that's been changed, update head and ignore anything else
            ObjectId newRoot = diff.newObjectId();
            updateStageHead(newRoot);
            progress.setProgress(100f);
            progress.complete();
            return;
        }
        RevTreeBuilder parentTree = getParentTree(currentIndexHead, parentPath, parentTress, parentMetadataIds);
        i++;
        progress.setProgress((float) (i * 100) / numChanges);
        NodeRef oldObject = diff.getOldObject();
        NodeRef newObject = diff.getNewObject();
        if (newObject == null) {
            // Delete
            parentTree.remove(oldObject.name());
            if (TYPE.TREE.equals(oldObject.getType())) {
                removedTrees.add(oldObject.path());
            }
        } else if (oldObject == null) {
            // Add
            Node node = newObject.getNode();
            parentTree.put(node);
            parentMetadataIds.put(newObject.path(), newObject.getMetadataId());
        } else {
            // Modify
            Node node = newObject.getNode();
            parentTree.put(node);
        }
        database.removeConflict(null, fullPath);
    }
    ObjectId newRootTree = currentIndexHead.getId();
    for (Map.Entry<String, RevTreeBuilder> entry : parentTress.entrySet()) {
        String changedTreePath = entry.getKey();
        RevTreeBuilder changedTreeBuilder = entry.getValue();
        RevTree changedTree = changedTreeBuilder.build();
        ObjectId parentMetadataId = parentMetadataIds.get(changedTreePath);
        if (NodeRef.ROOT.equals(changedTreePath)) {
            // root
            database.put(changedTree);
            newRootTree = changedTree.getId();
        } else {
            // parentMetadataId = parentMetadataId == null ?
            Supplier<RevTreeBuilder> rootTreeSupplier = getTreeSupplier();
            newRootTree = context.command(WriteBack.class).setAncestor(rootTreeSupplier).setChildPath(changedTreePath).setMetadataId(parentMetadataId).setToIndex(true).setTree(changedTree).call();
        }
        updateStageHead(newRootTree);
    }
    progress.complete();
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) WriteBack(org.locationtech.geogig.api.plumbing.WriteBack) NodeRef(org.locationtech.geogig.api.NodeRef) Map(java.util.Map) RevTree(org.locationtech.geogig.api.RevTree) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

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