diff --git a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java index 3915efcf6095..c4cd8ba611f0 100644 --- a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java +++ b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java @@ -102,7 +102,7 @@ public void createSpannerInstance() { } @Test - public void testCreateSessionDeadlineExceeded() throws Exception { + public void testCreateSessionDeadlineExceededWithNoSessionCreateWaitTime() throws Exception { // Simulate a problem with the CreateSession RPC making it slow. mockSpanner.setCreateSessionExecutionTime( SimulatedExecutionTime.ofException(Status.DEADLINE_EXCEEDED.asRuntimeException())); @@ -113,9 +113,11 @@ public void testCreateSessionDeadlineExceeded() throws Exception { .setProjectId("test-project") .setChannelProvider(channelProvider) .setCredentials(NoCredentials.getInstance()) + .setSessionPoolOption(SessionPoolOptions.newBuilder().setFailOnSessionLeak().build()) .build() .getService(); - DatabaseClient client = testSpanner.getDatabaseClient(DatabaseId.of("p", "i", "d")); + DatabaseClientImpl client = + (DatabaseClientImpl) testSpanner.getDatabaseClient(DatabaseId.of("p", "i", "d")); // The first attempt should lead to a DEADLINE_EXCEEDED error being propagated from the // CreateSession attempt. @@ -126,13 +128,20 @@ public void testCreateSessionDeadlineExceeded() throws Exception { // The next attempt should then succeed. mockSpanner.unfreeze(); - DatabaseClientImpl clientImpl = (DatabaseClientImpl) client; - assertNotNull(clientImpl.multiplexedSessionDatabaseClient.getCurrentSessionReference()); + assertNotNull(client.multiplexedSessionDatabaseClient.getCurrentSessionReference()); try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) { //noinspection StatementWithEmptyBody while (resultSet.next()) {} } + + List createSessionRequests = + mockSpanner.getRequestsOfType(CreateSessionRequest.class); + assertEquals(2, createSessionRequests.size()); + + List requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class); + assertEquals(1, requests.size()); + testSpanner.close(); } @@ -338,68 +347,6 @@ public void testRetryWithTheDatabaseNotFoundExceptionWithSessionCreationWaitTime testSpanner.close(); } - @Test - public void testRetryWithNoSessionCreationWaitTime() { - mockSpanner.setCreateSessionExecutionTime( - SimulatedExecutionTime.ofExceptions( - Collections.singletonList( - Status.DEADLINE_EXCEEDED - .withDescription( - "CallOptions deadline exceeded after 22.986872393s. " - + "Name resolution delay 6.911918521 seconds. [closed=[], " - + "open=[[connecting_and_lb_delay=32445014148ns, was_still_waiting]]]") - .asRuntimeException()))); - - Spanner testSpanner = - SpannerOptions.newBuilder() - .setProjectId("test-project") - .setChannelProvider(channelProvider) - .setCredentials(NoCredentials.getInstance()) - .setSessionPoolOption( - SessionPoolOptions.newBuilder() - .setUseMultiplexedSession(true) - .setUseMultiplexedSessionForRW(true) - .setUseMultiplexedSessionPartitionedOps(true) - .setFailOnSessionLeak() - .build()) - .build() - .getService(); - - DatabaseClientImpl client = - (DatabaseClientImpl) testSpanner.getDatabaseClient(DatabaseId.of("p", "i", "d")); - - SpannerException spannerException = - assertThrows( - SpannerException.class, - () -> { - try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) { - //noinspection StatementWithEmptyBody - while (resultSet.next()) { - // ignore - } - } - }); - assertEquals(ErrorCode.DEADLINE_EXCEEDED, spannerException.getErrorCode()); - - // The CreateSession RPC will be retried, and as the exception is removed by the first call, - // the second attempt will succeed. - try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) { - //noinspection StatementWithEmptyBody - while (resultSet.next()) { - // ignore - } - } - - List createSessionRequests = - mockSpanner.getRequestsOfType(CreateSessionRequest.class); - assertEquals(2, createSessionRequests.size()); - - List requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class); - assertEquals(1, requests.size()); - - testSpanner.close(); - } - @Test public void testRetryWithDelayedInResponseExceedsSessionCreationWaitTime() { mockSpanner.setCreateSessionExecutionTime( diff --git a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITInstanceAdminTest.java b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITInstanceAdminTest.java index 4e6a87bebf9d..5f0cd33a599a 100644 --- a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITInstanceAdminTest.java +++ b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITInstanceAdminTest.java @@ -48,7 +48,18 @@ @RunWith(JUnit4.class) public class ITInstanceAdminTest { - @ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv(true); + @ClassRule + public static IntegrationTestEnv env = + new IntegrationTestEnv(true) { + @Override + protected void before() throws Throwable { + assumeFalse( + "ITInstanceAdminTest is disabled when running against cloud-devel or cloud-staging", + isRunningOnCloudDevelOrStaging()); + super.before(); + } + }; + static InstanceAdminClient instanceClient; @BeforeClass @@ -59,6 +70,12 @@ public static void setUp() { instanceClient = env.getTestHelper().getClient().getInstanceAdminClient(); } + private static boolean isRunningOnCloudDevelOrStaging() { + String jobType = System.getenv("JOB_TYPE"); + return jobType != null + && (jobType.contains("cloud-devel") || jobType.contains("cloud-staging")); + } + @Test public void instanceConfigOperations() { List configs = new ArrayList<>();