@@ -56,6 +56,7 @@ public final class BatchClientImplTest {
5656 private static final String SESSION_NAME = DB_NAME + "/sessions/s1" ;
5757 private static final ByteString TXN_ID = ByteString .copyFromUtf8 ("my-txn" );
5858 private static final String TIMESTAMP = "2017-11-15T10:54:20Z" ;
59+ private static boolean isMultiplexedSession = false ;
5960
6061 @ Mock private SpannerRpc gapicRpc ;
6162 @ Mock private SpannerOptions spannerOptions ;
@@ -68,6 +69,11 @@ public final class BatchClientImplTest {
6869 public static void setupOpenTelemetry () {
6970 SpannerOptions .resetActiveTracingFramework ();
7071 SpannerOptions .enableOpenTelemetryTraces ();
72+ Boolean useMultiplexedSessionFromEnvVariablePartitionedOps =
73+ SessionPoolOptions .getUseMultiplexedSessionFromEnvVariablePartitionedOps ();
74+ isMultiplexedSession =
75+ useMultiplexedSessionFromEnvVariablePartitionedOps != null
76+ && useMultiplexedSessionFromEnvVariablePartitionedOps ;
7177 }
7278
7379 @ SuppressWarnings ("unchecked" )
@@ -88,18 +94,31 @@ public void setUp() {
8894 when (spannerOptions .getTransportOptions ()).thenReturn (transportOptions );
8995 SessionPoolOptions sessionPoolOptions = mock (SessionPoolOptions .class );
9096 when (sessionPoolOptions .getPoolMaintainerClock ()).thenReturn (Clock .INSTANCE );
97+ when (sessionPoolOptions .getUseMultiplexedSessionPartitionedOps ())
98+ .thenReturn (isMultiplexedSession );
9199 when (spannerOptions .getSessionPoolOptions ()).thenReturn (sessionPoolOptions );
92100 @ SuppressWarnings ("resource" )
93101 SpannerImpl spanner = new SpannerImpl (gapicRpc , spannerOptions );
94- client = new BatchClientImpl (spanner .getSessionClient (db ), false );
102+ client = new BatchClientImpl (spanner .getSessionClient (db ), isMultiplexedSession );
95103 }
96104
97105 @ SuppressWarnings ("unchecked" )
98106 @ Test
99107 public void testBatchReadOnlyTxnWithBound () throws Exception {
100- Session sessionProto = Session .newBuilder ().setName (SESSION_NAME ).build ();
101- when (gapicRpc .createSession (eq (DB_NAME ), anyString (), anyMap (), optionsCaptor .capture ()))
102- .thenReturn (sessionProto );
108+ Session sessionProto =
109+ Session .newBuilder ().setName (SESSION_NAME ).setMultiplexed (isMultiplexedSession ).build ();
110+ if (isMultiplexedSession ) {
111+ when (gapicRpc .createSession (
112+ eq (DB_NAME ),
113+ anyString (),
114+ anyMap (),
115+ optionsCaptor .capture (),
116+ eq (isMultiplexedSession )))
117+ .thenReturn (sessionProto );
118+ } else {
119+ when (gapicRpc .createSession (eq (DB_NAME ), anyString (), anyMap (), optionsCaptor .capture ()))
120+ .thenReturn (sessionProto );
121+ }
103122 com .google .protobuf .Timestamp timestamp = Timestamps .parse (TIMESTAMP );
104123 Transaction txnMetadata =
105124 Transaction .newBuilder ().setId (TXN_ID ).setReadTimestamp (timestamp ).build ();
@@ -113,12 +132,14 @@ public void testBatchReadOnlyTxnWithBound() throws Exception {
113132 assertThat (batchTxn .getReadTimestamp ()).isEqualTo (t );
114133 assertThat (batchTxn .getReadTimestamp ())
115134 .isEqualTo (batchTxn .getBatchTransactionId ().getTimestamp ());
135+ assertEquals (batchTxn .getBatchTransactionId ().isMultiplexedSession (), isMultiplexedSession );
116136 }
117137
118138 @ Test
119139 public void testBatchReadOnlyTxnWithTxnId () {
120140 when (txnID .getSessionId ()).thenReturn (SESSION_NAME );
121141 when (txnID .getTransactionId ()).thenReturn (TXN_ID );
142+ when (txnID .isMultiplexedSession ()).thenReturn (isMultiplexedSession );
122143 Timestamp t = Timestamp .parseTimestamp (TIMESTAMP );
123144 when (txnID .getTimestamp ()).thenReturn (t );
124145
@@ -128,6 +149,8 @@ public void testBatchReadOnlyTxnWithTxnId() {
128149 assertThat (batchTxn .getReadTimestamp ()).isEqualTo (t );
129150 assertThat (batchTxn .getReadTimestamp ())
130151 .isEqualTo (batchTxn .getBatchTransactionId ().getTimestamp ());
152+ assertThat (batchTxn .getBatchTransactionId ().isMultiplexedSession ())
153+ .isEqualTo (isMultiplexedSession );
131154 }
132155
133156 @ Test
0 commit comments