- private Future<ActorSelection> newCohort() {
- ActorPath path = getSystem().actorOf(Props.create(DoNothingActor.class)).path();
- ActorSelection actorSelection = getSystem().actorSelection(path);
- return Futures.successful(actorSelection);
- }
-
- 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));
-
- doReturn(new Timeout(Duration.apply(1000, TimeUnit.MILLISECONDS)))
- .when(actorContext).getTransactionCommitOperationTimeout();
- }
+ @Test
+ public void testCanCommitYesWithOneCohort() throws Exception {
+ ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList(
+ newCohortInfo(new CohortActor.Builder("txn-1").expectCanCommit(
+ CanCommitTransactionReply.yes(CURRENT_VERSION)))), "txn-1");