4343import io .grpc .StatusRuntimeException ;
4444import org .junit .Test ;
4545import org .junit .runner .RunWith ;
46- import org .junit .runners .JUnit4 ;
46+ import org .junit .runners .Parameterized ;
47+ import org .junit .runners .Parameterized .Parameter ;
48+ import org .junit .runners .Parameterized .Parameters ;
4749
48- @ RunWith (JUnit4 .class )
50+ @ RunWith (Parameterized .class )
4951public class RetryDmlAsPartitionedDmlMockServerTest extends AbstractMockServerTest {
52+ private enum ExceptionType {
53+ MutationLimitExceeded {
54+ @ Override
55+ StatusRuntimeException createException () {
56+ return createTransactionMutationLimitExceededException ();
57+ }
58+ },
59+ ResourceLimitExceeded {
60+ @ Override
61+ StatusRuntimeException createException () {
62+ return createTransactionResourceLimitExceededException ();
63+ }
64+ };
65+
66+ abstract StatusRuntimeException createException ();
67+ }
68+
69+ @ Parameters (name = "exception = {0}" )
70+ public static Object [] data () {
71+ return ExceptionType .values ();
72+ }
73+
74+ @ SuppressWarnings ("ClassEscapesDefinedScope" )
75+ @ Parameter
76+ public ExceptionType exceptionType ;
5077
5178 static StatusRuntimeException createTransactionMutationLimitExceededException () {
5279 Metadata .Key <byte []> key =
@@ -70,10 +97,16 @@ static StatusRuntimeException createTransactionMutationLimitExceededException()
7097 .asRuntimeException (trailers );
7198 }
7299
100+ static StatusRuntimeException createTransactionResourceLimitExceededException () {
101+ return Status .INVALID_ARGUMENT
102+ .withDescription ("Transaction resource limits exceeded" )
103+ .asRuntimeException ();
104+ }
105+
73106 @ Test
74107 public void testTransactionMutationLimitExceeded_isNotRetriedByDefault () {
75108 mockSpanner .setExecuteSqlExecutionTime (
76- SimulatedExecutionTime .ofException (createTransactionMutationLimitExceededException ()));
109+ SimulatedExecutionTime .ofException (exceptionType . createException ()));
77110
78111 try (Connection connection = createConnection ()) {
79112 connection .setAutocommit (true );
@@ -95,7 +128,7 @@ public void testTransactionMutationLimitExceeded_isNotRetriedByDefault() {
95128 public void testTransactionMutationLimitExceeded_canBeRetriedAsPDML () {
96129 Statement statement = Statement .of ("update test set value=1 where true" );
97130 mockSpanner .setExecuteSqlExecutionTime (
98- SimulatedExecutionTime .ofException (createTransactionMutationLimitExceededException ()));
131+ SimulatedExecutionTime .ofException (exceptionType . createException ()));
99132 mockSpanner .putStatementResult (
100133 MockSpannerServiceImpl .StatementResult .update (statement , 100000L ));
101134
@@ -134,7 +167,7 @@ public void testTransactionMutationLimitExceeded_retryAsPDMLFails() {
134167 Statement statement = Statement .of ("insert into test (id, value) select -id, value from test" );
135168 // The transactional update statement uses ExecuteSql(..).
136169 mockSpanner .setExecuteSqlExecutionTime (
137- SimulatedExecutionTime .ofException (createTransactionMutationLimitExceededException ()));
170+ SimulatedExecutionTime .ofException (exceptionType . createException ()));
138171 mockSpanner .putStatementResult (
139172 MockSpannerServiceImpl .StatementResult .exception (
140173 statement ,
@@ -230,7 +263,7 @@ public void testTransactionMutationLimitExceeded_isWrappedAsCauseOfBatchUpdateEx
230263 Statement statement = Statement .of (sql );
231264 mockSpanner .putStatementResult (
232265 MockSpannerServiceImpl .StatementResult .exception (
233- statement , createTransactionMutationLimitExceededException ()));
266+ statement , exceptionType . createException ()));
234267
235268 try (Connection connection = createConnection ()) {
236269 connection .setAutocommit (true );
0 commit comments