Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add additional tests for client ids #212

Merged
merged 2 commits into from May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -41,6 +41,7 @@
import io.grpc.StatusRuntimeException;
import io.grpc.inprocess.InProcessServerBuilder;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -927,4 +928,36 @@ public void testBackendPartitionQueryOptions() {
assertThat(request.getQueryOptions().getOptimizerVersion()).isEqualTo("1");
}
}

@Test
public void testClientIdReusedOnDatabaseNotFound() {
mockSpanner.setBatchCreateSessionsExecutionTime(
SimulatedExecutionTime.ofStickyException(
SpannerExceptionFactoryTest.newStatusResourceNotFoundException(
"my-database",
SpannerExceptionFactory.DATABASE_RESOURCE_TYPE,
"project/my-project/instances/my-instance/databases/my-database")));
try (Spanner spanner =
SpannerOptions.newBuilder()
.setProjectId("my-project")
.setChannelProvider(channelProvider)
.setCredentials(NoCredentials.getInstance())
.build()
.getService()) {
DatabaseId databaseId = DatabaseId.of("my-project", "my-instance", "my-database");
String prevClientId = null;
for (int i = 0; i < 100; i++) {
try {
DatabaseClientImpl client = (DatabaseClientImpl) spanner.getDatabaseClient(databaseId);
if (prevClientId != null) {
assertThat(client.clientId).isEqualTo(prevClientId);
}
prevClientId = client.clientId;
client.singleUse().readRow("MyTable", Key.of(0), Arrays.asList("MyColumn"));
} catch (Exception e) {
// ignore
}
}
}
}
}
Expand Up @@ -223,6 +223,13 @@ public void testClientId() throws Exception {
assertThat(revalidated).isNotSameInstanceAs(databaseClient);
assertThat(revalidated.clientId).isEqualTo(databaseClient.clientId);

// Now invalidate the second client and request a new one.
revalidated.pool.setResourceNotFoundException(
new DatabaseNotFoundException(DoNotConstructDirectly.ALLOWED, "not found", null, null));
DatabaseClientImpl revalidated2 = (DatabaseClientImpl) impl.getDatabaseClient(db);
assertThat(revalidated2).isNotSameInstanceAs(revalidated);
assertThat(revalidated2.clientId).isEqualTo(revalidated.clientId);

// Create a new Spanner instance. This will generate new database clients with new ids.
try (Spanner spanner =
SpannerOptions.newBuilder()
Expand Down