Skip to content

Commit e0aa253

Browse files
committed
address comments
1 parent 47e086d commit e0aa253

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ final class DatastoreImpl extends BaseService<DatastoreOptions> implements Datas
4747

4848
private final DatastoreRpc datastoreRpc;
4949
private final RetrySettings retrySettings;
50+
private static final ExceptionHandler TRANSACTION_EXCEPTION_HANDLER =
51+
TransactionExceptionHandler.build();
5052

5153
DatastoreImpl(DatastoreOptions options) {
5254
super(options);
@@ -67,7 +69,6 @@ public Transaction newTransaction() {
6769

6870
@Override
6971
public <T> T runInTransaction(final TransactionCallable<T> callable) {
70-
ExceptionHandler TRANSACTION_EXCEPTION_HANDLER = TransactionExceptionHandler.build();
7172
final DatastoreImpl self = this;
7273
try {
7374
return RetryHelper.runWithRetries(

google-cloud-datastore/src/main/java/com/google/cloud/datastore/TransactionExceptionHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
public class TransactionExceptionHandler {
2323
public static final Interceptor TRANSACTION_EXCEPTION_HANDLER_INTERCEPTOR =
2424
new Interceptor() {
25+
26+
private static final long serialVersionUID = -1240723093072535978L;
27+
2528
private static final int ABORTED_CODE = 10;
2629

2730
@Override

google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,11 @@ public void testDelete() {
735735
public void testRunInTransaction() {
736736
Datastore.TransactionCallable<Integer> callable1 =
737737
new Datastore.TransactionCallable<Integer>() {
738-
private Integer attempts = 0;
738+
private Integer attempts = 1;
739739

740740
public Integer run(DatastoreReaderWriter transaction) {
741741
transaction.get(KEY1);
742-
if (attempts < 1) {
742+
if (attempts < 2) {
743743
++attempts;
744744
throw new DatastoreException(10, "", "ABORTED", false, null);
745745
}
@@ -749,15 +749,15 @@ public Integer run(DatastoreReaderWriter transaction) {
749749
};
750750

751751
int result = DATASTORE.runInTransaction(callable1);
752-
assertEquals(result, 1);
752+
assertEquals(result, 2);
753753

754754
Datastore.TransactionCallable<Integer> callable2 =
755755
new Datastore.TransactionCallable<Integer>() {
756-
private Integer attempts = 0;
756+
private Integer attempts = 1;
757757

758758
public Integer run(DatastoreReaderWriter transaction) {
759759
transaction.get(KEY1);
760-
if (attempts < 1) {
760+
if (attempts < 2) {
761761
++attempts;
762762
throw new DatastoreException(4, "", "DEADLINE_EXCEEDED", false, null);
763763
}

0 commit comments

Comments
 (0)