Search in sources :

Example 1 with Bucket

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

the class PreOrderDiffWalkTest method testLeafBucketSimple.

@Test
public void testLeafBucketSimple() {
    final int rightsize = 1 + RevTree.NORMALIZED_SIZE_LIMIT;
    RevTree left = createFeaturesTree(leftSource, "f", 1).build();
    RevTree right = createFeaturesTree(rightSource, "f", rightsize).build();
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(left, right, leftSource, rightSource);
    // consume all
    when(consumer.tree(any(Node.class), any(Node.class))).thenReturn(true);
    when(consumer.bucket(anyInt(), anyInt(), any(Bucket.class), any(Bucket.class))).thenReturn(true);
    visitor.walk(consumer);
    // there's only the root tree
    verify(consumer, times(1)).tree(any(Node.class), any(Node.class));
    // there's only one feature on the right tree, so all right trees features fall on a single
    // bucket
    final int leftBucketCount = right.buckets().get().size();
    final int expectedBucketCalls = leftBucketCount - 1;
    verify(consumer, times(expectedBucketCalls)).bucket(anyInt(), eq(0), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(rightsize - 1)).feature((Node) isNull(), any(Node.class));
    verify(consumer, times(expectedBucketCalls)).endBucket(anyInt(), eq(0), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(1)).endTree(any(Node.class), any(Node.class));
    verifyNoMoreInteractions(consumer);
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) TreeTestSupport.featureNode(org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 2 with Bucket

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

the class PreOrderDiffWalkTest method testBucketLeafSeveral.

@Test
public void testBucketLeafSeveral() {
    final int leftsize = 1 + RevTree.NORMALIZED_SIZE_LIMIT;
    RevTree left = createFeaturesTree(leftSource, "f", leftsize).build();
    RevTree right = createFeaturesTree(rightSource, "f", 1).build();
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(left, right, leftSource, rightSource);
    // consume all
    when(consumer.tree(any(Node.class), any(Node.class))).thenReturn(true);
    when(consumer.bucket(anyInt(), anyInt(), any(Bucket.class), any(Bucket.class))).thenReturn(true);
    visitor.walk(consumer);
    // there's only the root tree
    verify(consumer, times(1)).tree(any(Node.class), any(Node.class));
    // there's only one feature on the right tree, so all right trees features fall on a single
    // bucket
    final int leftBucketCount = left.buckets().get().size();
    final int expectedBucketCalls = leftBucketCount - 1;
    verify(consumer, times(expectedBucketCalls)).bucket(anyInt(), eq(0), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(leftsize - 1)).feature(any(Node.class), (Node) isNull());
    verify(consumer, times(expectedBucketCalls)).endBucket(anyInt(), eq(0), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(1)).endTree(any(Node.class), any(Node.class));
    verifyNoMoreInteractions(consumer);
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) TreeTestSupport.featureNode(org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 3 with Bucket

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

the class PreOrderDiffWalkTest method getTreeDepth.

/**
     *
     */
private int getTreeDepth(RevTree tree, ObjectDatabase source, final int depth) {
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(tree, RevTree.EMPTY, source, source);
    final AtomicInteger maxDepth = new AtomicInteger();
    visitor.walk(new Consumer() {

        @Override
        public boolean tree(Node left, Node right) {
            return true;
        }

        @Override
        public void feature(Node left, Node right) {
        //
        }

        @Override
        public boolean bucket(int bucketIndex, int bucketDepth, Bucket left, Bucket right) {
            // use +1 cause we want the
            maxDepth.set(Math.max(maxDepth.get(), bucketDepth + 1));
            // zero-based level index
            return true;
        }

        @Override
        public void endTree(Node left, Node right) {
        // TODO Auto-generated method stub
        }

        @Override
        public void endBucket(int bucketIndex, int bucketDepth, Bucket left, Bucket right) {
        // TODO Auto-generated method stub
        }
    });
    return maxDepth.get();
}
Also used : Consumer(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk.Consumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) TreeTestSupport.featureNode(org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)

Example 4 with Bucket

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

the class PreOrderDiffWalkTest method testBucketBucketFlatMoreDepth.

@Test
public void testBucketBucketFlatMoreDepth() {
    RevTree left = createFeaturesTree(leftSource, "f", RevTree.MAX_BUCKETS * RevTree.NORMALIZED_SIZE_LIMIT).build();
    RevTree right = createFeaturesTree(rightSource, "f", RevTree.MAX_BUCKETS * RevTree.NORMALIZED_SIZE_LIMIT + 1).build();
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(left, right, leftSource, rightSource);
    when(consumer.tree(any(Node.class), any(Node.class))).thenReturn(true);
    when(consumer.bucket(anyInt(), anyInt(), any(Bucket.class), any(Bucket.class))).thenReturn(true);
    visitor.walk(consumer);
    verify(consumer, times(1)).tree(any(Node.class), any(Node.class));
    // consumer.bucket should be called for depth 0 and then 1
    verify(consumer, times(1)).bucket(anyInt(), eq(0), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(1)).bucket(anyInt(), eq(1), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(1)).feature((Node) isNull(), any(Node.class));
    verify(consumer, times(1)).endBucket(anyInt(), eq(0), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(1)).endBucket(anyInt(), eq(1), any(Bucket.class), any(Bucket.class));
    verify(consumer, times(1)).endTree(any(Node.class), any(Node.class));
    verifyNoMoreInteractions(consumer);
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) TreeTestSupport.featureNode(org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 5 with Bucket

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

the class ResponseWriter method writeTree.

public void writeTree(RevTree tree, String tag) throws XMLStreamException {
    out.writeStartElement(tag);
    writeElement("id", tree.getId().toString());
    writeElement("size", Long.toString(tree.size()));
    writeElement("numtrees", Integer.toString(tree.numTrees()));
    if (tree.trees().isPresent()) {
        ImmutableList<Node> trees = tree.trees().get();
        for (Node ref : trees) {
            writeNode(ref, "tree");
        }
    }
    if (tree.features().isPresent()) {
        ImmutableList<Node> features = tree.features().get();
        for (Node ref : features) {
            writeNode(ref, "feature");
        }
    } else if (tree.buckets().isPresent()) {
        Map<Integer, Bucket> buckets = tree.buckets().get();
        for (Entry<Integer, Bucket> entry : buckets.entrySet()) {
            Integer bucketIndex = entry.getKey();
            Bucket bucket = entry.getValue();
            out.writeStartElement("bucket");
            writeElement("bucketindex", bucketIndex.toString());
            writeElement("bucketid", bucket.id().toString());
            Envelope env = new Envelope();
            env.setToNull();
            bucket.expand(env);
            out.writeStartElement("bbox");
            writeElement("minx", Double.toString(env.getMinX()));
            writeElement("maxx", Double.toString(env.getMaxX()));
            writeElement("miny", Double.toString(env.getMinY()));
            writeElement("maxy", Double.toString(env.getMaxY()));
            out.writeEndElement();
            out.writeEndElement();
        }
    }
    out.writeEndElement();
}
Also used : DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Entry(java.util.Map.Entry) Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) Map(java.util.Map)

Aggregations

Bucket (org.locationtech.geogig.api.Bucket)23 Node (org.locationtech.geogig.api.Node)18 RevTree (org.locationtech.geogig.api.RevTree)15 Test (org.junit.Test)8 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)8 ObjectId (org.locationtech.geogig.api.ObjectId)6 Envelope (com.vividsolutions.jts.geom.Envelope)3 TreeMap (java.util.TreeMap)3 Bounded (org.locationtech.geogig.api.Bounded)3 Predicate (com.google.common.base.Predicate)2 ImmutableList (com.google.common.collect.ImmutableList)2 Builder (com.google.common.collect.ImmutableList.Builder)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)2 RevObject (org.locationtech.geogig.api.RevObject)2 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1