Search in sources :

Example 76 with ObjectId

use of org.locationtech.geogig.api.ObjectId 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 77 with ObjectId

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

the class IndexTest method testAddMultiple.

@Test
public void testAddMultiple() throws Exception {
    ObjectId oId1 = insert(points1);
    ObjectId oId2 = insert(points2);
    assertNotNull(oId1);
    assertNotNull(oId2);
    assertFalse(index.findStaged(appendChild(pointsName, idP1)).isPresent());
    assertFalse(index.findStaged(appendChild(pointsName, idP2)).isPresent());
    assertEquals(oId1, repo.workingTree().findUnstaged(appendChild(pointsName, idP1)).get().getObjectId());
    assertEquals(oId2, repo.workingTree().findUnstaged(appendChild(pointsName, idP2)).get().getObjectId());
    geogig.command(AddOp.class).call();
    assertEquals(oId1, index.findStaged(appendChild(pointsName, idP1)).get().getObjectId());
    assertEquals(oId2, index.findStaged(appendChild(pointsName, idP2)).get().getObjectId());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ObjectId(org.locationtech.geogig.api.ObjectId) Test(org.junit.Test)

Example 78 with ObjectId

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

the class IndexTest method testInsertIdenticalObjects.

// two features with the same content and different fid should point to the same object
@Test
public void testInsertIdenticalObjects() throws Exception {
    ObjectId oId1 = insertAndAdd(points1);
    Feature equalContentFeature = feature(pointsType, "DifferentId", ((SimpleFeature) points1).getAttributes().toArray());
    ObjectId oId2 = insertAndAdd(equalContentFeature);
    // BLOBS.print(repo.getRawObject(insertedId1), System.err);
    // BLOBS.print(repo.getRawObject(insertedId2), System.err);
    assertNotNull(oId1);
    assertNotNull(oId2);
    assertEquals(oId1, oId2);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 79 with ObjectId

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

the class IndexTest method testInsertNonEqualObjects.

// two features with different content should point to different objects
@Test
public void testInsertNonEqualObjects() throws Exception {
    ObjectId oId1 = insertAndAdd(points1);
    ObjectId oId2 = insertAndAdd(points2);
    assertNotNull(oId1);
    assertNotNull(oId2);
    assertFalse(oId1.equals(oId2));
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Test(org.junit.Test)

Example 80 with ObjectId

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

the class RefDatabaseTest method testPutGetRef.

@Test
public void testPutGetRef() {
    byte[] raw = new byte[20];
    Arrays.fill(raw, (byte) 1);
    ObjectId oid = new ObjectId(raw);
    assertEquals(ObjectId.NULL.toString(), refDb.getRef(Ref.MASTER));
    refDb.putRef(Ref.MASTER, oid.toString());
    assertEquals(oid.toString(), refDb.getRef(Ref.MASTER));
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Test(org.junit.Test)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22