ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort<ActorSelection> { @Override public ListenableFuture<Boolean> canCommit() { LOG.debug("Tx {} canCommit", transactionId); final SettableFuture<Boolean> returnFuture = SettableFuture.create(); Futures.addCallback(resolveCohorts(), new FutureCallback<Void>() { @Override public void onSuccess(final Void notUsed) { finishCanCommit(returnFuture); } @Override public void onFailure(final Throwable failure) { returnFuture.setException(failure); } }, MoreExecutors.directExecutor()); return returnFuture; } ThreePhaseCommitCohortProxy(final ActorUtils actorUtils, final List<CohortInfo> cohorts,
            final TransactionIdentifier transactionId); @Override ListenableFuture<Boolean> canCommit(); @Override ListenableFuture<Void> preCommit(); @Override ListenableFuture<Void> abort(); @Override ListenableFuture<Void> commit();  }
@Test public void testCanCommitYesWithOneCohort() throws Exception { ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.yes(CURRENT_VERSION)))), tx); verifyCanCommit(proxy.canCommit(), true); verifyCohortActors(); }
@Test public void testCanCommitNoWithOneCohort() throws Exception { ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.no(CURRENT_VERSION)))), tx); verifyCanCommit(proxy.canCommit(), false); verifyCohortActors(); }
@Test public void testCanCommitYesWithTwoCohorts() throws Exception { List<CohortInfo> cohorts = Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.yes(CURRENT_VERSION))), newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.yes(CURRENT_VERSION)))); ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); verifyCanCommit(proxy.canCommit(), true); verifyCohortActors(); }
@Test public void testCanCommitNoWithThreeCohorts() throws Exception { List<CohortInfo> cohorts = Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.yes(CURRENT_VERSION))), newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.no(CURRENT_VERSION))), newCohortInfo(new CohortActor.Builder(tx))); ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); verifyCanCommit(proxy.canCommit(), false); verifyCohortActors(); }
@Test(expected = TestException.class) public void testCanCommitWithExceptionFailure() throws Exception { ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit(new TestException()))), tx); propagateExecutionExceptionCause(proxy.canCommit()); }
@Test(expected = IllegalArgumentException.class) public void testCanCommitWithInvalidResponseType() throws Exception { ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit("invalid"))), tx); propagateExecutionExceptionCause(proxy.canCommit()); }
@Test(expected = TestException.class) public void testCanCommitWithFailedCohortFuture() throws Exception { List<CohortInfo> cohorts = Arrays.asList( newCohortInfo(new CohortActor.Builder(tx)), newCohortInfoWithFailedFuture(new TestException()), newCohortInfo(new CohortActor.Builder(tx))); ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); propagateExecutionExceptionCause(proxy.canCommit()); }