Skip to content

Commit 8f89cb4

Browse files
committed
fix tests
1 parent 338bf68 commit 8f89cb4

File tree

4 files changed

+11
-377
lines changed

4 files changed

+11
-377
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchClientImplTest.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public final class BatchClientImplTest {
5757
private static final String SESSION_NAME = DB_NAME + "/sessions/s1";
5858
private static final ByteString TXN_ID = ByteString.copyFromUtf8("my-txn");
5959
private static final String TIMESTAMP = "2017-11-15T10:54:20Z";
60-
private static boolean isMultiplexedSession = false;
6160

6261
@Mock private SpannerRpc gapicRpc;
6362
@Mock private SpannerOptions spannerOptions;
@@ -70,11 +69,6 @@ public final class BatchClientImplTest {
7069
public static void setupOpenTelemetry() {
7170
SpannerOptions.resetActiveTracingFramework();
7271
SpannerOptions.enableOpenTelemetryTraces();
73-
Boolean useMultiplexedSessionFromEnvVariablePartitionedOps =
74-
SessionPoolOptions.getUseMultiplexedSessionFromEnvVariablePartitionedOps();
75-
isMultiplexedSession =
76-
useMultiplexedSessionFromEnvVariablePartitionedOps != null
77-
&& useMultiplexedSessionFromEnvVariablePartitionedOps;
7872
}
7973

8074
@SuppressWarnings("unchecked")
@@ -95,8 +89,7 @@ public void setUp() {
9589
when(spannerOptions.getTransportOptions()).thenReturn(transportOptions);
9690
SessionPoolOptions sessionPoolOptions = mock(SessionPoolOptions.class);
9791
when(sessionPoolOptions.getPoolMaintainerClock()).thenReturn(Clock.INSTANCE);
98-
when(sessionPoolOptions.getUseMultiplexedSessionPartitionedOps())
99-
.thenReturn(isMultiplexedSession);
92+
when(sessionPoolOptions.getUseMultiplexedSessionPartitionedOps()).thenReturn(true);
10093
when(sessionPoolOptions.getMultiplexedSessionMaintenanceDuration()).thenReturn(Duration.ZERO);
10194
when(spannerOptions.getSessionPoolOptions()).thenReturn(sessionPoolOptions);
10295
@SuppressWarnings("resource")
@@ -108,19 +101,10 @@ public void setUp() {
108101
@Test
109102
public void testBatchReadOnlyTxnWithBound() throws Exception {
110103
Session sessionProto =
111-
Session.newBuilder().setName(SESSION_NAME).setMultiplexed(isMultiplexedSession).build();
112-
if (isMultiplexedSession) {
113-
when(gapicRpc.createSession(
114-
eq(DB_NAME),
115-
anyString(),
116-
anyMap(),
117-
optionsCaptor.capture(),
118-
eq(isMultiplexedSession)))
119-
.thenReturn(sessionProto);
120-
} else {
121-
when(gapicRpc.createSession(eq(DB_NAME), anyString(), anyMap(), optionsCaptor.capture()))
122-
.thenReturn(sessionProto);
123-
}
104+
Session.newBuilder().setName(SESSION_NAME).setMultiplexed(true).build();
105+
when(gapicRpc.createSession(
106+
eq(DB_NAME), anyString(), anyMap(), optionsCaptor.capture(), eq(true)))
107+
.thenReturn(sessionProto);
124108
com.google.protobuf.Timestamp timestamp = Timestamps.parse(TIMESTAMP);
125109
Transaction txnMetadata =
126110
Transaction.newBuilder().setId(TXN_ID).setReadTimestamp(timestamp).build();

google-cloud-spanner/src/test/java/com/google/cloud/spanner/ChannelUsageTest.java

Lines changed: 0 additions & 263 deletions
This file was deleted.

google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryableInternalErrorTest.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
import com.google.cloud.NoCredentials;
2424
import com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime;
2525
import com.google.cloud.spanner.connection.AbstractMockServerTest;
26-
import com.google.spanner.v1.BatchCreateSessionsRequest;
26+
import com.google.spanner.v1.CreateSessionRequest;
2727
import com.google.spanner.v1.ExecuteSqlRequest;
2828
import io.grpc.ManagedChannelBuilder;
2929
import io.grpc.Status;
3030
import org.junit.Test;
3131
import org.junit.runner.RunWith;
3232
import org.junit.runners.JUnit4;
33-
import org.threeten.bp.Duration;
3433

3534
@RunWith(JUnit4.class)
3635
public class RetryableInternalErrorTest extends AbstractMockServerTest {
3736
@Test
3837
public void testTranslateInternalException() {
39-
mockSpanner.setBatchCreateSessionsExecutionTime(
38+
// With multiplexed sessions, we use CreateSession instead of BatchCreateSessions
39+
mockSpanner.setCreateSessionExecutionTime(
4040
SimulatedExecutionTime.ofException(
4141
Status.INTERNAL
4242
.withDescription("Authentication backend internal server error. Please retry.")
@@ -53,25 +53,18 @@ public void testTranslateInternalException() {
5353
.setHost(String.format("http://localhost:%d", getPort()))
5454
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
5555
.setCredentials(NoCredentials.getInstance())
56-
.setSessionPoolOption(
57-
SessionPoolOptions.newBuilder()
58-
.setMinSessions(1)
59-
.setMaxSessions(1)
60-
.setWaitForMinSessions(Duration.ofSeconds(5))
61-
.build())
6256
.build()
6357
.getService()) {
6458

6559
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
66-
// Execute a query. This will block until a BatchCreateSessions call has finished and then
60+
// Execute a query. This will wait for multiplexed session creation and then
6761
// invoke ExecuteStreamingSql. Both of these RPCs should be retried.
6862
try (ResultSet resultSet = client.singleUse().executeQuery(SELECT1_STATEMENT)) {
6963
assertTrue(resultSet.next());
7064
assertFalse(resultSet.next());
7165
}
72-
// Verify that both the BatchCreateSessions call and the ExecuteStreamingSql call were
73-
// retried.
74-
assertEquals(2, mockSpanner.countRequestsOfType(BatchCreateSessionsRequest.class));
66+
// Verify that both the CreateSession call and the ExecuteStreamingSql call were retried.
67+
assertEquals(2, mockSpanner.countRequestsOfType(CreateSessionRequest.class));
7568
assertEquals(2, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class));
7669
// Clear the requests before the next test.
7770
mockSpanner.clearRequests();

0 commit comments

Comments
 (0)