File tree
Expand file treeCollapse file tree3 files changed
+53
-3
lines changed main/java/com/google/cloud/spanner test/java/com/google/cloud/spanner
Expand file treeCollapse file tree3 files changed
+53
-3
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -61,7 +61,15 @@ public Struct getCurrentRowAsStruct() {
|
61 | 61 |
|
62 | 62 | @Override
|
63 | 63 | public void close() {
|
64 |
| -delegate.get().close(); |
| 64 | +ResultSet rs; |
| 65 | +try { |
| 66 | +rs = delegate.get(); |
| 67 | +} catch (Exception e) { |
| 68 | +// Ignore any exceptions when getting the underlying result set, as that means that there is |
| 69 | +// nothing that needs to be closed. |
| 70 | +return; |
| 71 | +} |
| 72 | +rs.close(); |
65 | 73 | }
|
66 | 74 |
|
67 | 75 | @Override
|
|
Original file line number | Diff line number | Diff line change |
---|
@@ -1255,7 +1255,10 @@ public void close() {
|
1255 | 1255 | Exception = null;
|
1256 | 1256 | checkedOutSessions.remove(this);
|
1257 | 1257 | }
|
1258 |
| -get().close(); |
| 1258 | +PooledSession delegate = getOrNull(); |
| 1259 | +if (delegate != null) { |
| 1260 | +delegate.close(); |
| 1261 | +} |
1259 | 1262 | }
|
1260 | 1263 |
|
1261 | 1264 | @Override
|
@@ -1264,7 +1267,19 @@ public ApiFuture<Empty> asyncClose() {
|
1264 | 1267 | Exception = null;
|
1265 | 1268 | checkedOutSessions.remove(this);
|
1266 | 1269 | }
|
1267 |
| -return get().asyncClose(); |
| 1270 | +PooledSession delegate = getOrNull(); |
| 1271 | +if (delegate != null) { |
| 1272 | +return delegate.asyncClose(); |
| 1273 | +} |
| 1274 | +return ApiFutures.immediateFuture(Empty.getDefaultInstance()); |
| 1275 | +} |
| 1276 | + |
| 1277 | +private PooledSession getOrNull() { |
| 1278 | +try { |
| 1279 | +return get(); |
| 1280 | +} catch (Throwable t) { |
| 1281 | +return null; |
| 1282 | +} |
1268 | 1283 | }
|
1269 | 1284 |
|
1270 | 1285 | @Override
|
|
Original file line number | Diff line number | Diff line change |
---|
@@ -1599,4 +1599,31 @@ public Long run(TransactionContext transaction) throws Exception {
|
1599 | 1599 | }
|
1600 | 1600 | });
|
1601 | 1601 | }
|
| 1602 | + |
| 1603 | +@Test |
| 1604 | +public void testBatchCreateSessionsFailure_shouldNotPropagateToCloseMethod() { |
| 1605 | +try { |
| 1606 | +// Simulate session creation failures on the backend. |
| 1607 | +mockSpanner.setBatchCreateSessionsExecutionTime( |
| 1608 | +SimulatedExecutionTime.ofStickyException(Status.RESOURCE_EXHAUSTED.asRuntimeException())); |
| 1609 | +DatabaseClient client = |
| 1610 | +spannerWithEmptySessionPool.getDatabaseClient( |
| 1611 | +DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); |
| 1612 | +// This will not cause any failure as getting a session from the pool is guaranteed to be |
| 1613 | +// non-blocking, and any exceptions will be delayed until actual query execution. |
| 1614 | +ResultSet rs = client.singleUse().executeQuery(SELECT1); |
| 1615 | +try { |
| 1616 | +while (rs.next()) { |
| 1617 | +fail("Missing expected exception"); |
| 1618 | +} |
| 1619 | +} catch (SpannerException e) { |
| 1620 | +assertThat(e.getErrorCode()).isEqualTo(ErrorCode.RESOURCE_EXHAUSTED); |
| 1621 | +} finally { |
| 1622 | +// This should not cause any failures. |
| 1623 | +rs.close(); |
| 1624 | +} |
| 1625 | +} finally { |
| 1626 | +mockSpanner.setBatchCreateSessionsExecutionTime(SimulatedExecutionTime.none()); |
| 1627 | +} |
| 1628 | +} |
1602 | 1629 | }
|
You can’t perform that action at this time.
0 commit comments