Skip to content

Commit 9db0341

Browse files
committed
test: unflake ReadAsyncTest
1 parent e62f5ab commit 9db0341

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/ReadAsyncTest.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ public void before() {
112112

113113
@After
114114
public void after() {
115-
spanner.close();
116115
mockSpanner.removeAllExecutionTimes();
116+
spanner.close();
117117
}
118118

119119
@Test
120-
public void readAsyncPropagatesError() throws Exception {
120+
public void readAsyncPropagatesError() {
121121
ApiFuture<Void> result;
122122
try (AsyncResultSet resultSet =
123123
client
@@ -156,6 +156,8 @@ public void emptyReadAsync() throws Exception {
156156
case DONE:
157157
assertThat(rs.getType()).isEqualTo(READ_TABLE_TYPE);
158158
return CallbackResponse.DONE;
159+
default:
160+
fail("unknown cursor state");
159161
}
160162
}
161163
});
@@ -189,21 +191,26 @@ public void invalidDatabase() {
189191
SimulatedExecutionTime.stickyDatabaseNotFoundException("invalid-database"));
190192
mockSpanner.setBatchCreateSessionsExecutionTime(
191193
SimulatedExecutionTime.stickyDatabaseNotFoundException("invalid-database"));
192-
mockSpanner.freeze();
193-
DatabaseClient invalidClient =
194-
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, "invalid-database"));
195-
ApiFuture<Struct> row =
196-
invalidClient
197-
.singleUse(TimestampBound.strong())
198-
.readRowAsync(READ_TABLE_NAME, Key.of("k99"), READ_COLUMN_NAMES);
199-
mockSpanner.unfreeze();
200-
assertThrows(DatabaseNotFoundException.class, () -> get(row));
194+
try {
195+
mockSpanner.freeze();
196+
DatabaseClient invalidClient =
197+
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, "invalid-database"));
198+
ApiFuture<Struct> row =
199+
invalidClient
200+
.singleUse(TimestampBound.strong())
201+
.readRowAsync(READ_TABLE_NAME, Key.of("k99"), READ_COLUMN_NAMES);
202+
mockSpanner.unfreeze();
203+
assertThrows(DatabaseNotFoundException.class, () -> get(row));
204+
} finally {
205+
mockSpanner.removeAllExecutionTimes();
206+
mockSpanner.unfreeze();
207+
}
201208
}
202209

203210
@Test
204-
public void tableNotFound() throws Exception {
211+
public void tableNotFound() {
205212
mockSpanner.setStreamingReadExecutionTime(
206-
SimulatedExecutionTime.ofException(
213+
SimulatedExecutionTime.ofStickyException(
207214
Status.NOT_FOUND
208215
.withDescription("Table not found: BadTableName")
209216
.asRuntimeException()));
@@ -282,7 +289,7 @@ public void closeTransactionBeforeEndOfAsyncQuery() throws Exception {
282289
List<String> resultList = new ArrayList<>();
283290
do {
284291
results.drainTo(resultList);
285-
} while (!finished.isDone() || results.size() > 0);
292+
} while (!finished.isDone() || !results.isEmpty());
286293
assertThat(finished.get()).isTrue();
287294
assertThat(resultList).containsExactly("k1", "k2", "k3");
288295
// The session will be released back into the pool by the asynchronous result set when it has

0 commit comments

Comments
 (0)