Search in sources :

Example 21 with CommitBuilder

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

the class HashObjectTest method setUpInternal.

@Override
protected void setUpInternal() throws Exception {
    featureType1 = RevFeatureTypeImpl.build(pointsType);
    featureType2 = RevFeatureTypeImpl.build(linesType);
    featureType1Duplicate = RevFeatureTypeImpl.build(pointsType);
    pointFeature1 = RevFeatureBuilder.build(points1);
    pointFeature2 = RevFeatureBuilder.build(points2);
    pointFeature1Duplicate = RevFeatureBuilder.build(points1);
    CommitBuilder b = new CommitBuilder();
    b.setAuthor("groldan");
    b.setAuthorEmail("groldan@boundlessgeo.com");
    b.setCommitter("jdeolive");
    b.setCommitterEmail("jdeolive@boundlessgeo.com");
    b.setMessage("cool this works");
    b.setCommitterTimestamp(1000);
    b.setCommitterTimeZoneOffset(5);
    ObjectId treeId = ObjectId.forString("fake tree content");
    b.setTreeId(treeId);
    ObjectId parentId1 = ObjectId.forString("fake parent content 1");
    ObjectId parentId2 = ObjectId.forString("fake parent content 2");
    List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2);
    b.setParentIds(parentIds);
    commit1 = b.build();
    commit1Duplicate = b.build();
    b.setMessage(null);
    b.setAuthor(null);
    b.setAuthorEmail(null);
    b.setCommitterTimestamp(-1000);
    b.setCommitterTimeZoneOffset(-5);
    b.setParentIds(ImmutableList.of(parentId1, ObjectId.NULL));
    commit2 = b.build();
    Object boolArray = new boolean[] { true, false, true, true, false };
    Object byteArray = new byte[] { 100, 127, -110, 26, 42 };
    Object charArray = new char[] { 'a', 'b', 'c', 'd', 'e' };
    Object doubleArray = new double[] { 1.5, 1.6, 1.7, 1.8 };
    Object floatArray = new float[] { 1.1f, 3.14f, 6.0f, 0.0f };
    Object intArray = new int[] { 5, 7, 9, 11, 32 };
    Object longArray = new long[] { 100, 200, 300, 400 };
    TestSerializableObject serializableObject = new TestSerializableObject();
    serializableObject.words = "words to serialize";
    SimpleFeatureType coverageFeatureType = DataUtilities.createType("http://geoserver.org/test", "TestType", "str:String," + "str2:String," + "bool:Boolean," + "byte:java.lang.Byte," + "doub:Double," + "bdec:java.math.BigDecimal," + "flt:Float," + "int:Integer," + "bint:java.math.BigInteger," + "boolArray:java.lang.Object," + "byteArray:java.lang.Object," + "charArray:java.lang.Object," + "doubleArray:java.lang.Object," + "floatArray:java.lang.Object," + "intArray:java.lang.Object," + "longArray:java.lang.Object," + "serialized:java.io.Serializable," + "randomClass:java.lang.Object," + "pp:Point:srid=4326," + "lng:java.lang.Long," + "uuid:java.util.UUID");
    coverageRevFeatureType = RevFeatureTypeImpl.build(coverageFeatureType);
    Feature coverageFeature = feature(coverageFeatureType, "TestType.Coverage.1", "StringProp1_1", null, Boolean.TRUE, Byte.valueOf("18"), new Double(100.01), new BigDecimal("1.89e1021"), new Float(12.5), new Integer(1000), new BigInteger("90000000"), boolArray, byteArray, charArray, doubleArray, floatArray, intArray, longArray, serializableObject, new SomeRandomClass(), "POINT(1 1)", new Long(800000), UUID.fromString("bd882d24-0fe9-11e1-a736-03b3c0d0d06d"));
    coverageRevFeature = RevFeatureBuilder.build(coverageFeature);
    hashCommand = new HashObject();
    Context mockCommandLocator = mock(Context.class);
    hashCommand.setContext(mockCommandLocator);
    when(mockCommandLocator.command(eq(DescribeFeatureType.class))).thenReturn(new DescribeFeatureType());
}
Also used : Context(org.locationtech.geogig.api.Context) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) BigInteger(java.math.BigInteger)

Example 22 with CommitBuilder

use of org.locationtech.geogig.api.CommitBuilder 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

CommitBuilder (org.locationtech.geogig.api.CommitBuilder)22 ObjectId (org.locationtech.geogig.api.ObjectId)18 RevCommit (org.locationtech.geogig.api.RevCommit)16 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)8 Test (org.junit.Test)7 RevTree (org.locationtech.geogig.api.RevTree)7 Ref (org.locationtech.geogig.api.Ref)6 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)6 SymRef (org.locationtech.geogig.api.SymRef)4 WriteTree2 (org.locationtech.geogig.api.plumbing.WriteTree2)4 Repository (org.locationtech.geogig.repository.Repository)4 Platform (org.locationtech.geogig.api.Platform)3 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3 Optional (com.google.common.base.Optional)2 ImmutableList (com.google.common.collect.ImmutableList)2 File (java.io.File)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Context (org.locationtech.geogig.api.Context)2