|
41 | 41 | import io.grpc.StatusRuntimeException; |
42 | 42 | import io.grpc.inprocess.InProcessServerBuilder; |
43 | 43 | import java.io.IOException; |
| 44 | +import java.util.Arrays; |
44 | 45 | import java.util.List; |
45 | 46 | import java.util.concurrent.ScheduledThreadPoolExecutor; |
46 | 47 | import java.util.concurrent.TimeUnit; |
@@ -927,4 +928,36 @@ public void testBackendPartitionQueryOptions() { |
927 | 928 | assertThat(request.getQueryOptions().getOptimizerVersion()).isEqualTo("1"); |
928 | 929 | } |
929 | 930 | } |
| 931 | + |
| 932 | + @Test |
| 933 | + public void testClientIdReusedOnDatabaseNotFound() { |
| 934 | + mockSpanner.setBatchCreateSessionsExecutionTime( |
| 935 | + SimulatedExecutionTime.ofStickyException( |
| 936 | + SpannerExceptionFactoryTest.newStatusResourceNotFoundException( |
| 937 | + "my-database", |
| 938 | + SpannerExceptionFactory.DATABASE_RESOURCE_TYPE, |
| 939 | + "project/my-project/instances/my-instance/databases/my-database"))); |
| 940 | + try (Spanner spanner = |
| 941 | + SpannerOptions.newBuilder() |
| 942 | + .setProjectId("my-project") |
| 943 | + .setChannelProvider(channelProvider) |
| 944 | + .setCredentials(NoCredentials.getInstance()) |
| 945 | + .build() |
| 946 | + .getService()) { |
| 947 | + DatabaseId databaseId = DatabaseId.of("my-project", "my-instance", "my-database"); |
| 948 | + String prevClientId = null; |
| 949 | + for (int i = 0; i < 100; i++) { |
| 950 | + try { |
| 951 | + DatabaseClientImpl client = (DatabaseClientImpl) spanner.getDatabaseClient(databaseId); |
| 952 | + if (prevClientId != null) { |
| 953 | + assertThat(client.clientId).isEqualTo(prevClientId); |
| 954 | + } |
| 955 | + prevClientId = client.clientId; |
| 956 | + client.singleUse().readRow("MyTable", Key.of(0), Arrays.asList("MyColumn")); |
| 957 | + } catch (Exception e) { |
| 958 | + // ignore |
| 959 | + } |
| 960 | + } |
| 961 | + } |
| 962 | + } |
930 | 963 | } |
0 commit comments