Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ interface AsyncTransactionFunction<I, O> {
/** Returns the state of the transaction. */
TransactionState getState();

/** Returns the {@link CommitResponse} of this transaction. */
/**
* Returns the {@link CommitResponse} of this transaction. This method may only be called after
* committing the transaction.
*/
ApiFuture<CommitResponse> getCommitResponse();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ public TransactionState getState() {

@Override
public ApiFuture<CommitResponse> getCommitResponse() {
Preconditions.checkState(
txnState == TransactionState.COMMITTED,
"getCommitResponse can only be invoked if the transaction was successfully committed");
return commitResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ public void asyncTransactionManager_shouldRollbackOnCloseAsync() throws Exceptio
0L);
}

@Test
public void testAsyncTransactionManager_getCommitResponseReturnsErrorBeforeCommit() {
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
assertThrows(IllegalStateException.class, manager::getCommitResponse);
}
}

@Test
public void testAsyncTransactionManager_returnsCommitStats() throws Exception {
try (AsyncTransactionManager manager =
Expand Down
Loading