|
58 | 58 | import java.util.concurrent.ExecutionException; |
59 | 59 | import java.util.concurrent.ExecutorService; |
60 | 60 | import java.util.concurrent.Executors; |
| 61 | +import java.util.concurrent.ThreadLocalRandom; |
61 | 62 | import org.junit.AfterClass; |
62 | 63 | import org.junit.Before; |
63 | 64 | import org.junit.BeforeClass; |
@@ -237,17 +238,24 @@ public void invalidDatabase() throws Exception { |
237 | 238 | RemoteSpannerHelper helper = env.getTestHelper(); |
238 | 239 | DatabaseClient invalidClient = |
239 | 240 | helper.getClient().getDatabaseClient(DatabaseId.of(helper.getInstanceId(), "invalid")); |
240 | | - ApiFuture<Struct> row = |
241 | | - invalidClient |
242 | | - .singleUse(TimestampBound.strong()) |
243 | | - .readRowAsync(TABLE_NAME, Key.of("k99"), ALL_COLUMNS); |
| 241 | + Thread.sleep(ThreadLocalRandom.current().nextLong(100L)); |
244 | 242 | try { |
| 243 | + // The NOT_FOUND error can come from both the call to invalidClient.singleUse() as well as |
| 244 | + // from the call to row.get(), which is why both need to be inside the try block. |
| 245 | + ApiFuture<Struct> row = |
| 246 | + invalidClient |
| 247 | + .singleUse(TimestampBound.strong()) |
| 248 | + .readRowAsync(TABLE_NAME, Key.of("k99"), ALL_COLUMNS); |
245 | 249 | row.get(); |
246 | 250 | fail("missing expected exception"); |
247 | | - } catch (ExecutionException e) { |
248 | | - assertThat(e.getCause()).isInstanceOf(SpannerException.class); |
249 | | - SpannerException se = (SpannerException) e.getCause(); |
250 | | - assertThat(se.getErrorCode()).isEqualTo(ErrorCode.NOT_FOUND); |
| 251 | + } catch (ExecutionException | SpannerException thrownException) { |
| 252 | + SpannerException spannerException; |
| 253 | + if (thrownException instanceof ExecutionException) { |
| 254 | + spannerException = (SpannerException) thrownException.getCause(); |
| 255 | + } else { |
| 256 | + spannerException = (SpannerException) thrownException; |
| 257 | + } |
| 258 | + assertEquals(ErrorCode.NOT_FOUND, spannerException.getErrorCode()); |
251 | 259 | } |
252 | 260 | } |
253 | 261 |
|
|
0 commit comments