public TestData startTransaction() { checkState(transaction == null, "There's a transaction already running"); GeogigTransaction tx = getContext().command(TransactionBegin.class).call(); setTransaction(tx); return this; }
/** * Runs the command and builds the appropriate response. * * @param context - the context to use for this command * * @throws CommandSpecException */ @Override protected void runInternal(CommandContext context) { if (this.getTransactionId() != null) { throw new CommandSpecException("Tried to start a transaction within a transaction."); } final Repository geogig = context.getRepository(); final GeogigTransaction transaction = geogig.command(TransactionBegin.class).call(); context.setResponseContent(new CommandResponse() { @Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeTransactionId(transaction.getTransactionId()); out.finish(); } }); }
/** * Creates a transaction on the given repository and stores the transaction id in the given * variable for later use. * * @param variableName the variable name to store the transaction id. * @param repoName the repository on which to create the transaction. */ @Given("^I have a transaction as \"([^\"]*)\" on the \"([^\"]*)\" repo$") public void beginTransactionAsVariable(final String variableName, final String repoName) { GeogigTransaction transaction = context.getRepo(repoName).command(TransactionBegin.class) .call(); context.setVariable(variableName, transaction.getTransactionId().toString()); // add the repo to the set so it can be closed openedRepos.add(repoName); }
@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(); }
@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(); }
@Test public void testResolveTransaction() throws Exception { GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); Optional<GeogigTransaction> txNew = geogig.command(TransactionResolve.class) .setId(tx.getTransactionId()).call(); assertTrue(txNew.isPresent()); }
private PR prepare(PR pr) { Preconditions.checkNotNull(pr.getTransactionId()); Preconditions.checkNotNull(pr.getId()); getProgressListener().setDescription("Initializing pull request " + pr); com.google.common.base.Optional<GeogigTransaction> tx = command(TransactionResolve.class) .setId(pr.getTransactionId()).call(); if (!tx.isPresent()) { PRStatus status = command(PRHealthCheckOp.class).setRequest(pr).call(); checkState(!status.isMerged(), "Cannot re open pull request %s because it's already merged", pr.getId()); // reinitialize a transaction, pr was closes final GeogigTransaction txContext = command(TransactionBegin.class).call(); final UUID txId = txContext.getTransactionId(); pr.setTransactionId(txId); } if (remoteURI != null) pr.setRemote(remoteURI); if (remoteBranch != null) pr.setRemoteBranch(remoteBranch); if (targetBranch != null) pr.setTargetBranch(targetBranch); if (title != null) pr.setTitle(title); if (description != null) pr.setDescription(description); return pr; }
@Test public void testResolveTransaction() throws Exception { GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); Optional<GeogigTransaction> txNew = geogig.command(TransactionResolve.class) .setId(tx.getTransactionId()).call(); assertTrue(txNew.isPresent()); }
@Test public void testCancelTransaction() throws Exception { LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>(); // make a commit insertAndAdd(points1); RevCommit commit = geogig.command(CommitOp.class).call(); expectedMain.addFirst(commit); // start a transaction GeogigTransaction t = geogig.command(TransactionBegin.class).call(); // perform a commit in the transaction insertAndAdd(t, points2); commit = t.command(CommitOp.class).call(); // 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); // Cancel the transaction geogig.command(TransactionEnd.class).setCancel(true).setTransaction(t).call(); // Verify that the base repository is unchanged logs = geogig.command(LogOp.class).call(); logged = new ArrayList<RevCommit>(); for (; logs.hasNext();) { logged.add(logs.next()); } assertEquals(expectedMain, logged); }
private PR build() { final GeogigTransaction txContext = command(TransactionBegin.class).call(); final UUID txId = txContext.getTransactionId(); final PR pr; pr = PR.builder()// .id(id)// .transactionId(txId).remote(remoteURI)// .remoteBranch(remoteBranch)// .targetBranch(targetBranch)// .title(title)// .description(description)// .build(); getProgressListener().setDescription("Creating pull request " + pr); return pr; }
@Test public void testEndTransactionFromTransactionId() throws Exception { GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); // Use transaction id from the TransactionBegin to create another transaction that // can be used to perform other actions such as pull, push, and end. The web api // for example needs a way to retrieve/recreate a transaction object using a transactionId // without calling GeogigTransaction.create() since the transaction was previously created. Optional<GeogigTransaction> txNew = geogig.command(TransactionResolve.class) .setId(tx.getTransactionId()).call(); assertTrue(txNew.isPresent()); TransactionEnd endTransaction = geogig.command(TransactionEnd.class); boolean closed = endTransaction.setCancel(false).setTransaction(txNew.get()).call(); assertTrue(closed); } }
@Test public void testEndTransactionFromTransactionId() throws Exception { GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); // Use transaction id from the TransactionBegin to create another transaction that // can be used to perform other actions such as pull, push, and end. The web api // for example needs a way to retrieve/recreate a transaction object using a transactionId // without calling GeogigTransaction.create() since the transaction was previously created. Optional<GeogigTransaction> txNew = geogig.command(TransactionResolve.class) .setId(tx.getTransactionId()).call(); assertTrue(txNew.isPresent()); TransactionEnd endTransaction = geogig.command(TransactionEnd.class); boolean closed = endTransaction.setCancel(false).setTransaction(txNew.get()).call(); assertTrue(closed); } }
@Test public void testEndWithinTransaction() throws Exception { // make a commit insertAndAdd(points1); geogig.command(CommitOp.class).call(); // start a transaction GeogigTransaction t = geogig.command(TransactionBegin.class).call(); // perform a commit in the transaction insertAndAdd(t, points2); t.command(CommitOp.class).call(); // End the transaction exception.expect(IllegalStateException.class); t.command(TransactionEnd.class).setTransaction(t).call(); }
@Test public void testEndWithinTransaction() throws Exception { // make a commit insertAndAdd(points1); geogig.command(CommitOp.class).call(); // start a transaction GeogigTransaction t = geogig.command(TransactionBegin.class).call(); // perform a commit in the transaction insertAndAdd(t, points2); t.command(CommitOp.class).call(); // End the transaction exception.expect(IllegalStateException.class); t.command(TransactionEnd.class).setTransaction(t).call(); }
IndexInfo indexInfo = createIndex(true, "x"); GeogigTransaction transaction = geogig.command(TransactionBegin.class).call();
IndexInfo indexInfo = createIndex(true, "x"); GeogigTransaction transaction = geogig.command(TransactionBegin.class).call();
@Test public void testCommitUpdatesRemoteRefs() throws Exception { // make a commit insertAndAdd(points1); RevCommit headCommit = geogig.command(CommitOp.class).call(); final String remoteRef = "refs/remotes/upstream/master"; final String unchangedRemoteRef = "refs/remotes/upstream/testbranch"; Ref remoteHead = geogig.command(UpdateRef.class).setName(remoteRef) .setNewValue(headCommit.getId()).call().get(); assertEquals(headCommit.getId(), remoteHead.getObjectId()); geogig.command(UpdateRef.class).setName(unchangedRemoteRef).setNewValue(headCommit.getId()) .call().get(); // start a transaction GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); // make a commit insertAndAdd(tx, points2); RevCommit newcommit = tx.command(CommitOp.class).call(); // upadte remote Ref txRemoteHead = tx.command(UpdateRef.class).setName(remoteRef) .setNewValue(newcommit.getId()).call().get(); assertEquals(newcommit.getId(), txRemoteHead.getObjectId()); // commit transaction tx.commit(); txRemoteHead = geogig.command(RefParse.class).setName(remoteRef).call().get(); assertEquals(newcommit.getId(), txRemoteHead.getObjectId()); txRemoteHead = geogig.command(RefParse.class).setName(unchangedRemoteRef).call().get(); assertEquals(headCommit.getId(), txRemoteHead.getObjectId()); }
@Test public void testCommitUpdatesRemoteRefs() throws Exception { // make a commit insertAndAdd(points1); RevCommit headCommit = geogig.command(CommitOp.class).call(); final String remoteRef = "refs/remotes/upstream/master"; final String unchangedRemoteRef = "refs/remotes/upstream/testbranch"; Ref remoteHead = geogig.command(UpdateRef.class).setName(remoteRef) .setNewValue(headCommit.getId()).call().get(); assertEquals(headCommit.getId(), remoteHead.getObjectId()); geogig.command(UpdateRef.class).setName(unchangedRemoteRef).setNewValue(headCommit.getId()) .call().get(); // start a transaction GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); // make a commit insertAndAdd(tx, points2); RevCommit newcommit = tx.command(CommitOp.class).call(); // upadte remote Ref txRemoteHead = tx.command(UpdateRef.class).setName(remoteRef) .setNewValue(newcommit.getId()).call().get(); assertEquals(newcommit.getId(), txRemoteHead.getObjectId()); // commit transaction tx.commit(); txRemoteHead = geogig.command(RefParse.class).setName(remoteRef).call().get(); assertEquals(newcommit.getId(), txRemoteHead.getObjectId()); txRemoteHead = geogig.command(RefParse.class).setName(unchangedRemoteRef).call().get(); assertEquals(headCommit.getId(), txRemoteHead.getObjectId()); }
@Test public void testConflictIsolation() throws Exception { insertAndAdd(points2); geogig.command(CommitOp.class).setMessage("foo").call(); geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call(); insertAndAdd(points1); RevCommit mainCommit = geogig.command(CommitOp.class).setMessage("Commit1").call(); geogig.command(CheckoutOp.class).setSource("master").call(); insertAndAdd(points1_modified); RevCommit modifiedCommit = geogig.command(CommitOp.class).setMessage("Commit2").call(); GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); try { tx.command(MergeOp.class).addCommit(mainCommit.getId()).call(); fail("Expected a merge conflict!"); } catch (org.locationtech.geogig.porcelain.MergeConflictsException e) { // expected. } long txConflicts = tx.command(ConflictsCountOp.class).call().longValue(); long baseConflicts = geogig.command(ConflictsCountOp.class).call().longValue(); assertTrue("There should be no conflicts outside the transaction", baseConflicts == 0); assertTrue("There should be conflicts in the transaction", txConflicts > 0); }
@Test public void testConflictIsolation() throws Exception { insertAndAdd(points2); geogig.command(CommitOp.class).setMessage("foo").call(); geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call(); insertAndAdd(points1); RevCommit mainCommit = geogig.command(CommitOp.class).setMessage("Commit1").call(); geogig.command(CheckoutOp.class).setSource("master").call(); insertAndAdd(points1_modified); RevCommit modifiedCommit = geogig.command(CommitOp.class).setMessage("Commit2").call(); assertNotNull(modifiedCommit); GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); try { tx.command(MergeOp.class).addCommit(mainCommit.getId()).call(); fail("Expected a merge conflict!"); } catch (org.locationtech.geogig.porcelain.MergeConflictsException e) { // expected. } long txConflicts = tx.command(ConflictsCountOp.class).call().longValue(); long baseConflicts = geogig.command(ConflictsCountOp.class).call().longValue(); assertTrue("There should be no conflicts outside the transaction", baseConflicts == 0); assertTrue("There should be conflicts in the transaction", txConflicts > 0); }