Search in sources :

Example 16 with GeogigTransaction

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

the class GeogigTransactionTest method testBeginWithinTransaction.

@Test
public void testBeginWithinTransaction() throws Exception {
    // make a commit
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    // start a transaction
    GeogigTransaction t = geogig.command(TransactionBegin.class).call();
    // start a transaction within the transaction
    exception.expect(IllegalStateException.class);
    t.command(TransactionBegin.class).call();
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Test(org.junit.Test)

Example 17 with GeogigTransaction

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

the class GeogigTransactionTest method testTransactionAuthor.

@Test
public void testTransactionAuthor() throws Exception {
    LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>();
    LinkedList<RevCommit> expectedTransaction = new LinkedList<RevCommit>();
    // make a commit
    insertAndAdd(points1);
    RevCommit firstCommit = geogig.command(CommitOp.class).call();
    expectedMain.addFirst(firstCommit);
    expectedTransaction.addFirst(firstCommit);
    // start a transaction
    GeogigTransaction t = geogig.command(TransactionBegin.class).call();
    t.setAuthor("Transaction Author", "transaction@author.com");
    // perform a commit in the transaction
    insertAndAdd(t, points2);
    RevCommit transactionCommit = t.command(CommitOp.class).call();
    expectedTransaction.addFirst(transactionCommit);
    // perform a commit on the repo
    insertAndAdd(points3);
    RevCommit repoCommit = geogig.command(CommitOp.class).call();
    expectedMain.addFirst(repoCommit);
    // Verify that the base repository is unchanged
    Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedMain, logged);
    // Verify that the transaction has the commit
    logs = t.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedTransaction, logged);
    // Commit the transaction
    t.commitSyncTransaction();
    // Verify that a merge commit was created
    logs = geogig.command(LogOp.class).call();
    RevCommit lastCommit = logs.next();
    assertFalse(lastCommit.equals(repoCommit));
    assertTrue(lastCommit.getMessage().contains("Merge commit"));
    assertEquals(lastCommit.getParentIds().get(0), transactionCommit.getId());
    assertEquals(lastCommit.getParentIds().get(1), repoCommit.getId());
    assertEquals("Transaction Author", lastCommit.getAuthor().getName().get());
    assertEquals("transaction@author.com", lastCommit.getAuthor().getEmail().get());
    assertEquals(logs.next(), repoCommit);
    assertEquals(logs.next(), transactionCommit);
    assertEquals(logs.next(), firstCommit);
    assertFalse(logs.hasNext());
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) LinkedList(java.util.LinkedList) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 18 with GeogigTransaction

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

the class GeogigTransactionTest method testMultipleTransaction.

@Test
public void testMultipleTransaction() throws Exception {
    // make a commit
    insertAndAdd(points1);
    RevCommit mainCommit = geogig.command(CommitOp.class).setMessage("Commit1").call();
    // start the first transaction
    GeogigTransaction transaction1 = geogig.command(TransactionBegin.class).call();
    // perform a commit in the transaction
    insertAndAdd(transaction1, points2);
    RevCommit transaction1Commit = transaction1.command(CommitOp.class).setMessage("Commit2").call();
    // Verify that the base repository is unchanged
    Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
    assertEquals(mainCommit, logs.next());
    assertFalse(logs.hasNext());
    // Verify that the transaction has the commit
    logs = transaction1.command(LogOp.class).call();
    assertEquals(transaction1Commit, logs.next());
    assertEquals(mainCommit, logs.next());
    assertFalse(logs.hasNext());
    // start the second transaction
    GeogigTransaction transaction2 = geogig.command(TransactionBegin.class).call();
    // perform a commit in the transaction
    insertAndAdd(transaction2, points3);
    RevCommit transaction2Commit = transaction2.command(CommitOp.class).setMessage("Commit3").call();
    // Verify that the base repository is unchanged
    logs = geogig.command(LogOp.class).call();
    assertEquals(mainCommit, logs.next());
    assertFalse(logs.hasNext());
    // Verify that the transaction has the commit
    logs = transaction2.command(LogOp.class).call();
    assertEquals(transaction2Commit, logs.next());
    assertEquals(mainCommit, logs.next());
    assertFalse(logs.hasNext());
    // Commit the first transaction
    geogig.command(TransactionEnd.class).setTransaction(transaction1).setRebase(true).call();
    // Verify that the base repository has the changes from the transaction
    logs = geogig.command(LogOp.class).call();
    assertEquals(transaction1Commit, logs.next());
    assertEquals(mainCommit, logs.next());
    assertFalse(logs.hasNext());
    // Now try to commit the second transaction
    geogig.command(TransactionEnd.class).setTransaction(transaction2).setRebase(true).call();
    // Verify that the base repository has the changes from the transaction
    logs = geogig.command(LogOp.class).call();
    RevCommit lastCommit = logs.next();
    assertFalse(lastCommit.equals(transaction2Commit));
    assertEquals(lastCommit.getMessage(), transaction2Commit.getMessage());
    assertEquals(lastCommit.getAuthor(), transaction2Commit.getAuthor());
    assertEquals(lastCommit.getCommitter().getName(), transaction2Commit.getCommitter().getName());
    assertFalse(lastCommit.getCommitter().getTimestamp() == transaction2Commit.getCommitter().getTimestamp());
    assertEquals(logs.next(), transaction1Commit);
    assertEquals(logs.next(), mainCommit);
    assertFalse(logs.hasNext());
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RevCommit(org.locationtech.geogig.api.RevCommit) TransactionEnd(org.locationtech.geogig.api.plumbing.TransactionEnd) Test(org.junit.Test)

Example 19 with GeogigTransaction

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

the class TransactionalResource method getContext.

protected Context getContext(Request request) {
    Optional<GeoGIG> geogig = getGeogig(request);
    checkState(geogig.isPresent());
    Context geogigContext = geogig.get().getContext();
    Form options = getRequest().getResourceRef().getQueryAsForm();
    String txId = options.getFirstValue("transactionId");
    if (txId != null) {
        UUID transactionId = UUID.fromString(txId);
        GeogigTransaction tx = new GeogigTransaction(geogigContext, transactionId);
        geogigContext = tx;
    }
    return geogigContext;
}
Also used : Context(org.locationtech.geogig.api.Context) GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) Form(org.restlet.data.Form) UUID(java.util.UUID) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Aggregations

GeogigTransaction (org.locationtech.geogig.api.GeogigTransaction)19 TransactionBegin (org.locationtech.geogig.api.plumbing.TransactionBegin)14 Test (org.junit.Test)10 RevCommit (org.locationtech.geogig.api.RevCommit)10 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)7 LogOp (org.locationtech.geogig.api.porcelain.LogOp)6 TransactionEnd (org.locationtech.geogig.api.plumbing.TransactionEnd)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 Optional (com.google.common.base.Optional)3 Context (org.locationtech.geogig.api.Context)3 GeoGIG (org.locationtech.geogig.api.GeoGIG)3 Ref (org.locationtech.geogig.api.Ref)3 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)3 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)3 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)3 ObjectId (org.locationtech.geogig.api.ObjectId)2 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)2 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)2 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)2