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();
}
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());
}
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());
}
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;
}
Aggregations