@@ -1569,49 +1569,55 @@ public void testInitialBeginTransactionWithRW_receivesUnimplemented_fallsBackToR
15691569 // Tests the behavior of the server-side kill switch for read-write multiplexed sessions.
15701570 @ Test
15711571 public void testPartitionedQuery_receivesUnimplemented_fallsBackToRegularSession () {
1572- mockSpanner .setPartitionQueryExecutionTime (
1573- SimulatedExecutionTime .ofException (
1574- Status .INVALID_ARGUMENT
1575- .withDescription (
1576- "Partitioned operations are not supported with multiplexed sessions" )
1577- .asRuntimeException ()));
1578- BatchClientImpl client = (BatchClientImpl ) spanner .getBatchClient (DatabaseId .of ("p" , "i" , "d" ));
1579-
1580- try (BatchReadOnlyTransaction transaction =
1581- client .batchReadOnlyTransaction (TimestampBound .strong ())) {
1582- // Partitioned Query should fail
1583- SpannerException spannerException =
1584- assertThrows (
1585- SpannerException .class ,
1586- () -> {
1587- transaction .partitionQuery (PartitionOptions .getDefaultInstance (), STATEMENT );
1588- });
1589- assertEquals (ErrorCode .INVALID_ARGUMENT , spannerException .getErrorCode ());
1590-
1591- // Verify that we received one PartitionQueryRequest.
1592- List <PartitionQueryRequest > partitionQueryRequests =
1593- mockSpanner .getRequestsOfType (PartitionQueryRequest .class );
1594- assertEquals (1 , partitionQueryRequests .size ());
1595- // Verify the requests were executed using multiplexed sessions
1596- Session session2 = mockSpanner .getSession (partitionQueryRequests .get (0 ).getSession ());
1597- assertNotNull (session2 );
1598- assertTrue (session2 .getMultiplexed ());
1599- assertTrue (client .unimplementedForPartitionedOps .get ());
1600- }
1601- try (BatchReadOnlyTransaction transaction =
1602- client .batchReadOnlyTransaction (TimestampBound .strong ())) {
1603- // Partitioned Query should fail
1604- transaction .partitionQuery (PartitionOptions .getDefaultInstance (), STATEMENT );
1605-
1606- // // Verify that we received two PartitionQueryRequest. and it uses a regular session due to
1607- // fallback.
1608- List <PartitionQueryRequest > partitionQueryRequests =
1609- mockSpanner .getRequestsOfType (PartitionQueryRequest .class );
1610- assertEquals (2 , partitionQueryRequests .size ());
1611- // Verify the requests are not executed using multiplexed sessions
1612- Session session2 = mockSpanner .getSession (partitionQueryRequests .get (1 ).getSession ());
1613- assertNotNull (session2 );
1614- assertFalse (session2 .getMultiplexed ());
1572+ try {
1573+ mockSpanner .setPartitionQueryExecutionTime (
1574+ SimulatedExecutionTime .ofException (
1575+ Status .INVALID_ARGUMENT
1576+ .withDescription (
1577+ "Partitioned operations are not supported with multiplexed sessions" )
1578+ .asRuntimeException ()));
1579+ BatchClientImpl client =
1580+ (BatchClientImpl ) spanner .getBatchClient (DatabaseId .of ("p" , "i" , "d" ));
1581+
1582+ try (BatchReadOnlyTransaction transaction =
1583+ client .batchReadOnlyTransaction (TimestampBound .strong ())) {
1584+ // Partitioned Query should fail
1585+ SpannerException spannerException =
1586+ assertThrows (
1587+ SpannerException .class ,
1588+ () -> {
1589+ transaction .partitionQuery (PartitionOptions .getDefaultInstance (), STATEMENT );
1590+ });
1591+ assertEquals (ErrorCode .INVALID_ARGUMENT , spannerException .getErrorCode ());
1592+
1593+ // Verify that we received one PartitionQueryRequest.
1594+ List <PartitionQueryRequest > partitionQueryRequests =
1595+ mockSpanner .getRequestsOfType (PartitionQueryRequest .class );
1596+ assertEquals (1 , partitionQueryRequests .size ());
1597+ // Verify the requests were executed using multiplexed sessions
1598+ Session session2 = mockSpanner .getSession (partitionQueryRequests .get (0 ).getSession ());
1599+ assertNotNull (session2 );
1600+ assertTrue (session2 .getMultiplexed ());
1601+ assertTrue (BatchClientImpl .unimplementedForPartitionedOps .get ());
1602+ }
1603+ try (BatchReadOnlyTransaction transaction =
1604+ client .batchReadOnlyTransaction (TimestampBound .strong ())) {
1605+ // Partitioned Query should fail
1606+ transaction .partitionQuery (PartitionOptions .getDefaultInstance (), STATEMENT );
1607+
1608+ // // Verify that we received two PartitionQueryRequest. and it uses a regular session due
1609+ // to
1610+ // fallback.
1611+ List <PartitionQueryRequest > partitionQueryRequests =
1612+ mockSpanner .getRequestsOfType (PartitionQueryRequest .class );
1613+ assertEquals (2 , partitionQueryRequests .size ());
1614+ // Verify the requests are not executed using multiplexed sessions
1615+ Session session2 = mockSpanner .getSession (partitionQueryRequests .get (1 ).getSession ());
1616+ assertNotNull (session2 );
1617+ assertFalse (session2 .getMultiplexed ());
1618+ }
1619+ } finally {
1620+ BatchClientImpl .unimplementedForPartitionedOps .set (false );
16151621 }
16161622 }
16171623
0 commit comments