Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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.
Comment on lines 122 to 123
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment states that the first attempt should result in a DEADLINE_EXCEEDED error, but the code to perform this attempt and verify the exception (e.g., using assertThrows) is missing from the patch. This verification is crucial for testing the retry logic and was present in the deleted test testRetryWithNoSessionCreationWaitTime.

References
  1. Use Assertions.assertThrows if the exception is truly expected as part of the test scenario.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was not added in this test, and as such this review comment is a bit weird. And in addition: The assertThrows is one line below this comment....

Expand All @@ -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<CreateSessionRequest> createSessionRequests =
mockSpanner.getRequestsOfType(CreateSessionRequest.class);
assertEquals(2, createSessionRequests.size());

List<ExecuteSqlRequest> requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
assertEquals(1, requests.size());

testSpanner.close();
}

Expand Down Expand Up @@ -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<CreateSessionRequest> createSessionRequests =
mockSpanner.getRequestsOfType(CreateSessionRequest.class);
assertEquals(2, createSessionRequests.size());

List<ExecuteSqlRequest> requests = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
assertEquals(1, requests.size());

testSpanner.close();
}

@Test
public void testRetryWithDelayedInResponseExceedsSessionCreationWaitTime() {
mockSpanner.setCreateSessionExecutionTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<InstanceConfig> configs = new ArrayList<>();
Expand Down
Loading