- private final ThreePhaseCommitCohortProxy setupProxy(int nCohorts) throws Exception {
- List<Future<ActorSelection>> cohortFutures = Lists.newArrayList();
- for(int i = 1; i <= nCohorts; i++) {
- cohortFutures.add(newCohort());
- }
-
- return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures, "txn-1");
- }
-
- private ThreePhaseCommitCohortProxy setupProxyWithFailedCohortPath()
- throws Exception {
- List<Future<ActorSelection>> cohortFutures = Lists.newArrayList();
- cohortFutures.add(newCohort());
- cohortFutures.add(Futures.<ActorSelection>failed(new TestException()));
-
- return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures, "txn-1");
- }
-
- private void setupMockActorContext(Class<?> requestType, Object... responses) {
- Stubber stubber = doReturn(responses[0] instanceof Throwable ? Futures
- .failed((Throwable) responses[0]) : Futures
- .successful(((SerializableMessage) responses[0]).toSerializable()));
-
- for(int i = 1; i < responses.length; i++) {
- stubber = stubber.doReturn(responses[i] instanceof Throwable ? Futures
- .failed((Throwable) responses[i]) : Futures
- .successful(((SerializableMessage) responses[i]).toSerializable()));
- }
-
- stubber.when(actorContext).executeOperationAsync(any(ActorSelection.class),
- isA(requestType), any(Timeout.class));
- }
-
- private void verifyCohortInvocations(int nCohorts, Class<?> requestType) {
- verify(actorContext, times(nCohorts)).executeOperationAsync(
- any(ActorSelection.class), isA(requestType), any(Timeout.class));
- }
-
- private void propagateExecutionExceptionCause(ListenableFuture<?> future) throws Throwable {
+ @Test
+ public void testCanCommitYesWithOneCohort() throws Exception {
+ ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList(
+ newCohortInfo(new CohortActor.Builder(tx).expectCanCommit(
+ CanCommitTransactionReply.yes(CURRENT_VERSION)))), tx);