Skip to content

Commit 0ee880f

Browse files
committed
Add timeout to Datastore ITs and verify exceptions
1 parent 199bd61 commit 0ee880f

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
import org.junit.After;
6363
import org.junit.AfterClass;
6464
import org.junit.Before;
65+
import org.junit.Rule;
6566
import org.junit.Test;
67+
import org.junit.rules.Timeout;
6668

6769
import java.util.Collections;
6870
import java.util.Iterator;
@@ -124,6 +126,9 @@ public class ITDatastoreTest {
124126
private static final Entity ENTITY3 = Entity.builder(ENTITY1).key(KEY3).remove("str")
125127
.set("null", NULL_VALUE).set("partial1", PARTIAL_ENTITY2).set("partial2", ENTITY2).build();
126128

129+
@Rule
130+
public Timeout globalTimeout = Timeout.seconds(100);
131+
127132
@AfterClass
128133
public static void afterClass() {
129134
HELPER.deleteNamespace();
@@ -150,6 +155,7 @@ public void testNewTransactionCommit() {
150155
transaction.update(entity2);
151156
transaction.delete(KEY1);
152157
transaction.commit();
158+
assertFalse(transaction.active());
153159

154160
List<Entity> list = DATASTORE.fetch(KEY1, KEY2, KEY3);
155161
assertNull(list.get(0));
@@ -160,15 +166,15 @@ public void testNewTransactionCommit() {
160166
try {
161167
transaction.commit();
162168
fail("Expecting a failure");
163-
} catch (DatastoreException ex) {
164-
// expected to fail
169+
} catch (DatastoreException expected) {
170+
assertEquals("FAILED_PRECONDITION", expected.reason());
165171
}
166172

167173
try {
168174
transaction.rollback();
169175
fail("Expecting a failure");
170-
} catch (DatastoreException ex) {
171-
// expected to fail
176+
} catch (DatastoreException expected) {
177+
assertEquals("FAILED_PRECONDITION", expected.reason());
172178
}
173179
}
174180

@@ -249,8 +255,8 @@ public void testNewTransactionRollback() {
249255
try {
250256
transaction.commit();
251257
fail("Expecting a failure");
252-
} catch (DatastoreException ex) {
253-
// expected to fail
258+
} catch (DatastoreException expected) {
259+
assertEquals("FAILED_PRECONDITION", expected.reason());
254260
}
255261

256262
List<Entity> list = DATASTORE.fetch(KEY1, KEY2, KEY3);
@@ -300,8 +306,8 @@ public void testNewBatch() {
300306
try {
301307
batch.submit();
302308
fail("Expecting a failure");
303-
} catch (DatastoreException ex) {
304-
// expected to fail
309+
} catch (DatastoreException expected) {
310+
assertEquals("FAILED_PRECONDITION", expected.reason());
305311
}
306312

307313
batch = DATASTORE.newBatch();

0 commit comments

Comments
 (0)