Search in sources :

Example 1 with ObjectInserter

use of org.locationtech.geogig.storage.ObjectInserter in project GeoGig by boundlessgeo.

the class IndexTest method testWriteTree.

@Test
public void testWriteTree() throws Exception {
    insertAndAdd(points1);
    insertAndAdd(lines1);
    // this new root tree must exist on the repo db, but is not set as the current head. In
    // fact, it is headless, as there's no commit pointing to it. CommitOp does that.
    ObjectId newRootTreeId = geogig.command(WriteTree.class).setOldRoot(tree(repo.getHead().get().getObjectId())).call();
    assertNotNull(newRootTreeId);
    assertFalse(repo.getRootTreeId().equals(newRootTreeId));
    // but the index staged root shall be pointing to it
    // assertEquals(newRootTreeId, index.getStaged().getId());
    RevTree tree = repo.getTree(newRootTreeId);
    // assertEquals(2, tree.size().intValue());
    String path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
    // simulate a commit so the repo head points to this new tree
    ObjectInserter objectInserter = repo.newObjectInserter();
    List<ObjectId> parents = ImmutableList.of();
    RevCommit commit = new CommitBuilder(geogig.getPlatform()).setTreeId(newRootTreeId).setParentIds(parents).build();
    ObjectId commitId = commit.getId();
    objectInserter.insert(commit);
    Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
    assertTrue(newHead.isPresent());
    WorkingTree workTree = repo.workingTree();
    workTree.delete(linesName, lines1.getIdentifier().getID());
    geogig.command(AddOp.class).call();
    // newRootTreeId
    newRootTreeId = geogig.command(WriteTree2.class).setOldRoot(tree(newRootTreeId)).call();
    // =
    // index.writeTree(newRootTreeId,
    // new
    // NullProgressListener());
    assertNotNull(newRootTreeId);
    assertFalse(repo.getRootTreeId().equals(newRootTreeId));
    tree = repo.getTree(newRootTreeId);
    path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertFalse(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) WorkingTree(org.locationtech.geogig.repository.WorkingTree) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectInserter(org.locationtech.geogig.storage.ObjectInserter) RevTree(org.locationtech.geogig.api.RevTree) WriteTree2(org.locationtech.geogig.api.plumbing.WriteTree2) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 2 with ObjectInserter

use of org.locationtech.geogig.storage.ObjectInserter in project GeoGig by boundlessgeo.

the class IndexTest method testWriteTree2.

@Test
public void testWriteTree2() throws Exception {
    // insert and commit feature1_1
    final ObjectId oId1_1 = insertAndAdd(points1);
    final ObjectId newRepoTreeId1;
    {
        newRepoTreeId1 = geogig.command(WriteTree2.class).setOldRoot(tree(repo.getHead().get().getObjectId())).call();
        // assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId1);
        RevTree newRepoTree = repo.getTree(newRepoTreeId1);
        System.err.println("++++++++++ new repo tree 1: " + newRepoTreeId1 + " ++++++++++++");
        // check feature1_1 is there
        assertEquals(oId1_1, repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)).get().getObjectId());
    }
    // insert and add (stage) points2, points3, and lines1
    final ObjectId oId1_2 = insertAndAdd(points2);
    final ObjectId oId1_3 = insertAndAdd(points3);
    final ObjectId oId2_1 = insertAndAdd(lines1);
    {
        // simulate a commit so the repo head points to this new tree
        ObjectInserter objectInserter = repo.newObjectInserter();
        List<ObjectId> parents = ImmutableList.of();
        RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId1).setParentIds(parents).build();
        ObjectId commitId = commit.getId();
        objectInserter.insert(commit);
        Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
        assertTrue(newHead.isPresent());
    }
    final ObjectId newRepoTreeId2;
    {
        // write comparing the the previously generated tree instead of the repository HEAD, as
        // it was not updated (no commit op was performed)
        newRepoTreeId2 = geogig.command(WriteTree2.class).setOldRoot(tree(newRepoTreeId1)).call();
        // assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId2);
        System.err.println("++++++++ new root 2:" + newRepoTreeId2 + " ++++++++++");
        RevTree newRepoTree = repo.getTree(newRepoTreeId2);
        // check feature1_2, feature1_2 and feature2_1
        Optional<Node> treeChild;
        assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP2)));
        assertEquals(oId1_2, treeChild.get().getObjectId());
        assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP3)));
        assertEquals(oId1_3, treeChild.get().getObjectId());
        assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(linesName, idL1)));
        assertEquals(oId2_1, treeChild.get().getObjectId());
        // as well as feature1_1 from the previous commit
        assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)));
        assertEquals(oId1_1, treeChild.get().getObjectId());
    }
    {
        // simulate a commit so the repo head points to this new tree
        ObjectInserter objectInserter = repo.newObjectInserter();
        List<ObjectId> parents = ImmutableList.of();
        RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId2).setParentIds(parents).build();
        ObjectId commitId = commit.getId();
        objectInserter.insert(commit);
        Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
        assertTrue(newHead.isPresent());
    }
    // delete feature1_1, feature1_3, and feature2_1
    assertTrue(deleteAndAdd(points1));
    assertTrue(deleteAndAdd(points3));
    assertTrue(deleteAndAdd(lines1));
    // and insert feature2_2
    final ObjectId oId2_2 = insertAndAdd(lines2);
    final ObjectId newRepoTreeId3;
    {
        // write comparing the the previously generated tree instead of the repository HEAD, as
        // it was not updated (no commit op was performed)
        newRepoTreeId3 = geogig.command(WriteTree2.class).setOldRoot(tree(newRepoTreeId2)).call();
        // assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId3);
        System.err.println("++++++++ new root 3:" + newRepoTreeId3 + " ++++++++++");
        RevTree newRepoTree = repo.getTree(newRepoTreeId3);
        // and check only feature1_2 and feature2_2 remain
        assertFalse(repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)).isPresent());
        assertFalse(repo.getTreeChild(newRepoTree, appendChild(pointsName, idP3)).isPresent());
        assertFalse(repo.getTreeChild(newRepoTree, appendChild(linesName, idL3)).isPresent());
        assertEquals(oId1_2, repo.getTreeChild(newRepoTree, appendChild(pointsName, idP2)).get().getObjectId());
        assertEquals(oId2_2, repo.getTreeChild(newRepoTree, appendChild(linesName, idL2)).get().getObjectId());
    }
}
Also used : ObjectInserter(org.locationtech.geogig.storage.ObjectInserter) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)2 ObjectId (org.locationtech.geogig.api.ObjectId)2 RevCommit (org.locationtech.geogig.api.RevCommit)2 RevTree (org.locationtech.geogig.api.RevTree)2 ObjectInserter (org.locationtech.geogig.storage.ObjectInserter)2 Optional (com.google.common.base.Optional)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 Ref (org.locationtech.geogig.api.Ref)1 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)1 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)1 WriteTree2 (org.locationtech.geogig.api.plumbing.WriteTree2)1 AddOp (org.locationtech.geogig.api.porcelain.AddOp)1 WorkingTree (org.locationtech.geogig.repository.WorkingTree)1