Search in sources :

Example 26 with NodeRef

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

the class RevertOpTest method testRevertModifiedFeatureConflictSolveAndContinue.

@Test
public void testRevertModifiedFeatureConflictSolveAndContinue() throws Exception {
    ObjectId oId1 = insertAndAdd(points1);
    RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insertAndAdd(points1_modified);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
    Feature points1_modifiedB = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insertAndAdd(points1_modifiedB);
    RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
    try {
        geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
        fail();
    } catch (RevertConflictsException e) {
        assertTrue(e.getMessage().contains(idP1));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(c3.getId(), ref.get().getObjectId());
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    assertEquals(1, conflicts.size());
    String path = NodeRef.appendChild(pointsName, idP1);
    assertEquals(conflicts.get(0).getPath(), path);
    assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1_modifiedB).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId());
    // solve, and continue
    insert(points1);
    geogig.command(AddOp.class).call();
    geogig.command(RevertOp.class).setContinue(true).call();
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    RevCommit logCommit = log.next();
    assertEquals(c2.getAuthor().getName(), logCommit.getAuthor().getName());
    assertEquals(c2.getCommitter().getName(), logCommit.getCommitter().getName());
    assertEquals("Revert '" + c2.getMessage() + "'\nThis reverts " + c2.getId().toString(), logCommit.getMessage());
    assertNotSame(c2.getCommitter().getTimestamp(), logCommit.getCommitter().getTimestamp());
    assertNotSame(c2.getTreeId(), logCommit.getTreeId());
    final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
    final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
    RevTree headTree = repo.getTree(headTreeId.get());
    Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
    assertTrue(points1Node.isPresent());
    assertEquals(oId1, points1Node.get().getNode().getObjectId());
    assertEquals(c3.getId(), log.next().getId());
    assertEquals(c2.getId(), log.next().getId());
    assertEquals(c1.getId(), log.next().getId());
    assertFalse(log.hasNext());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Feature(org.opengis.feature.Feature) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevertConflictsException(org.locationtech.geogig.api.porcelain.RevertConflictsException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 27 with NodeRef

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

the class RevTreeBuilderTest method testPutIterate.

@Test
public void testPutIterate() throws Exception {
    final int numEntries = 1000 * 100;
    ObjectId treeId;
    Stopwatch sw;
    sw = Stopwatch.createStarted();
    treeId = createAndSaveTree(numEntries, true);
    sw.stop();
    System.err.println("Stored " + numEntries + " tree entries in " + sw + " (" + Math.round(numEntries / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)");
    sw = Stopwatch.createStarted();
    treeId = createAndSaveTree(numEntries, true);
    sw.stop();
    System.err.println("Stored " + numEntries + " tree entries in " + sw + " (" + Math.round(numEntries / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)");
    sw.reset().start();
    final RevTree tree = odb.getTree(treeId);
    sw.stop();
    System.err.println("Retrieved tree in " + sw);
    System.err.println("traversing with DepthTreeIterator...");
    sw.reset().start();
    int counted = 0;
    for (DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN); it.hasNext(); counted++) {
        NodeRef ref = it.next();
        if ((counted + 1) % (numEntries / 10) == 0) {
            System.err.print("#" + (counted + 1));
        } else if ((counted + 1) % (numEntries / 100) == 0) {
            System.err.print('.');
        }
    }
    sw.stop();
    System.err.println("\nTraversed " + counted + " in " + sw + " (" + Math.round(counted / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)\n");
    System.err.println("traversing with DepthTreeIterator...");
    sw.reset().start();
    counted = 0;
    for (DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN); it.hasNext(); counted++) {
        NodeRef ref = it.next();
        if ((counted + 1) % (numEntries / 10) == 0) {
            System.err.print("#" + (counted + 1));
        } else if ((counted + 1) % (numEntries / 100) == 0) {
            System.err.print('.');
        }
    }
    sw.stop();
    System.err.println("\nTraversed " + counted + " in " + sw + " (" + Math.round(counted / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)\n");
    assertEquals(numEntries, counted);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) Stopwatch(com.google.common.base.Stopwatch) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 28 with NodeRef

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

the class RevTreeBuilderTest method testPutRandomGet.

@Test
public void testPutRandomGet() throws Exception {
    final int numEntries = 2 * RevTree.NORMALIZED_SIZE_LIMIT + 1500;
    final ObjectId treeId;
    Stopwatch sw;
    sw = Stopwatch.createStarted();
    treeId = createAndSaveTree(numEntries, true);
    sw.stop();
    System.err.println("Stored " + numEntries + " tree entries in " + sw + " (" + Math.round(numEntries / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)");
    sw.reset().start();
    final RevTree tree = odb.getTree(treeId);
    sw.stop();
    System.err.println("Retrieved tree in " + sw);
    {
        Map<Integer, Node> randomEdits = Maps.newHashMap();
        Random randGen = new Random();
        for (int i = 0; i < tree.size() / 2; i++) {
            int random;
            while (randomEdits.containsKey(random = randGen.nextInt(numEntries))) {
                // $codepro.audit.disable extraSemicolon
                ;
            }
            String name = "Feature." + random;
            ObjectId newid = ObjectId.forString(name + "changed");
            Node ref = Node.create(name, newid, ObjectId.NULL, TYPE.FEATURE, null);
            randomEdits.put(random, ref);
        }
        RevTreeBuilder mutable = tree.builder(odb);
        sw.reset().start();
        for (Node ref : randomEdits.values()) {
            mutable.put(ref);
        }
        mutable.build();
        sw.stop();
        System.err.println(randomEdits.size() + " random modifications in " + sw);
    }
    // CharSequence treeStr =
    // repo.command(CatObject.class).setObject(Suppliers.ofInstance(tree))
    // .call();
    // System.out.println(treeStr);
    final FindTreeChild childFinder = repo.command(FindTreeChild.class).setParent(tree);
    sw.reset().start();
    System.err.println("Reading " + numEntries + " entries....");
    for (int i = 0; i < numEntries; i++) {
        if ((i + 1) % (numEntries / 10) == 0) {
            System.err.print("#" + (i + 1));
        } else if ((i + 1) % (numEntries / 100) == 0) {
            System.err.print('.');
        }
        String key = "Feature." + i;
        // ObjectId oid = ObjectId.forString(key);
        Optional<NodeRef> ref = childFinder.setChildPath(key).call();
        assertTrue(key, ref.isPresent());
    // assertEquals(key, ref.get().getPath());
    // assertEquals(key, oid, ref.get().getObjectId());
    }
    sw.stop();
    System.err.println("\nGot " + numEntries + " in " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms (" + Math.round(numEntries / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000D)) + "/s)\n");
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Random(java.util.Random) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Stopwatch(com.google.common.base.Stopwatch) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Map(java.util.Map) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 29 with NodeRef

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

the class RevTreeBuilderTest method testResultingTreeSize.

private void testResultingTreeSize(int numEntries) {
    RevTreeBuilder builder = createTree(numEntries, true);
    RevTree tree = builder.build();
    final long declaredSize = tree.size();
    Iterator<NodeRef> it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.RECURSIVE_FEATURES_ONLY);
    long itSize = 0;
    while (it.hasNext()) {
        it.next();
        itSize++;
    }
    assertEquals(numEntries, itSize);
    assertEquals(numEntries, declaredSize);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) RevTree(org.locationtech.geogig.api.RevTree)

Example 30 with NodeRef

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

the class WorkingTreeTest method testCreateTypeTree.

@Test
public void testCreateTypeTree() throws Exception {
    NodeRef treeRef = workTree.createTypeTree("points2", pointsType);
    assertNotNull(treeRef);
    assertEquals("points2", treeRef.path());
    assertEquals("", treeRef.getParentPath());
    assertTrue(treeRef.getNode().getMetadataId().isPresent());
    assertSame(treeRef.getMetadataId(), treeRef.getNode().getMetadataId().get());
    RevFeatureType featureType = repo.stagingDatabase().getFeatureType(treeRef.getMetadataId());
    assertEquals(pointsType, featureType.type());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Aggregations

NodeRef (org.locationtech.geogig.api.NodeRef)161 ObjectId (org.locationtech.geogig.api.ObjectId)91 RevTree (org.locationtech.geogig.api.RevTree)67 Test (org.junit.Test)62 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)40 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)27 RevFeature (org.locationtech.geogig.api.RevFeature)25 Node (org.locationtech.geogig.api.Node)24 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)24 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)23 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)22 RevObject (org.locationtech.geogig.api.RevObject)21 RevCommit (org.locationtech.geogig.api.RevCommit)19 Map (java.util.Map)15 SimpleFeature (org.opengis.feature.simple.SimpleFeature)15 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)14 Feature (org.opengis.feature.Feature)13 Optional (com.google.common.base.Optional)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)11 LsTreeOp (org.locationtech.geogig.api.plumbing.LsTreeOp)11