1818
1919import com .mongodb .ClientSessionOptions ;
2020import com .mongodb .MongoClientException ;
21+ import com .mongodb .MongoCommandException ;
2122import com .mongodb .MongoException ;
23+ import com .mongodb .MongoNodeIsRecoveringException ;
24+ import com .mongodb .MongoTimeoutException ;
2225import com .mongodb .TransactionOptions ;
2326import com .mongodb .client .model .Sorts ;
2427import com .mongodb .internal .time .ExponentialBackoff ;
4245import static com .mongodb .ClusterFixture .isSharded ;
4346import static com .mongodb .client .Fixture .getPrimary ;
4447import static org .junit .jupiter .api .Assertions .assertEquals ;
48+ import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
4549import static org .junit .jupiter .api .Assertions .assertThrows ;
4650import static org .junit .jupiter .api .Assertions .assertTrue ;
4751import static org .junit .jupiter .api .Assertions .fail ;
@@ -114,8 +118,10 @@ public void testRetryTimeoutEnforcedTransientTransactionError() {
114118 }));
115119 fail ("Test should have thrown an exception." );
116120 } catch (Exception e ) {
117- assertEquals (errorMessage , e .getMessage ());
118- assertTrue (((MongoException ) e ).getErrorLabels ().contains (MongoException .TRANSIENT_TRANSACTION_ERROR_LABEL ));
121+ assertInstanceOf (MongoTimeoutException .class , e );
122+ MongoException cause = (MongoException ) e .getCause ();
123+ assertEquals (errorMessage , cause .getMessage ());
124+ assertTrue (cause .getErrorLabels ().contains (MongoException .TRANSIENT_TRANSACTION_ERROR_LABEL ));
119125 }
120126 }
121127
@@ -139,8 +145,10 @@ public void testRetryTimeoutEnforcedUnknownTransactionCommit() {
139145 }));
140146 fail ("Test should have thrown an exception." );
141147 } catch (Exception e ) {
142- assertEquals (91 , ((MongoException ) e ).getCode ());
143- assertTrue (((MongoException ) e ).getErrorLabels ().contains (MongoException .UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL ));
148+ assertInstanceOf (MongoNodeIsRecoveringException .class , e .getCause ());
149+ MongoNodeIsRecoveringException cause = (MongoNodeIsRecoveringException ) e .getCause ();
150+ assertEquals (91 , cause .getCode ());
151+ assertTrue (cause .getErrorLabels ().contains (MongoException .UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL ));
144152 } finally {
145153 failPointAdminDb .runCommand (Document .parse ("{'configureFailPoint': 'failCommand', 'mode': 'off'}" ));
146154 }
@@ -168,8 +176,11 @@ public void testRetryTimeoutEnforcedTransientTransactionErrorOnCommit() {
168176 }));
169177 fail ("Test should have thrown an exception." );
170178 } catch (Exception e ) {
171- assertEquals (251 , ((MongoException ) e ).getCode ());
172- assertTrue (((MongoException ) e ).getErrorLabels ().contains (MongoException .TRANSIENT_TRANSACTION_ERROR_LABEL ));
179+ assertEquals (-4 , ((MongoException ) e ).getCode ());
180+ assertInstanceOf (MongoCommandException .class , e .getCause ());
181+ MongoCommandException cause = (MongoCommandException ) e .getCause ();
182+ assertEquals (251 , cause .getCode ());
183+ assertTrue (cause .getErrorLabels ().contains (MongoException .TRANSIENT_TRANSACTION_ERROR_LABEL ));
173184 } finally {
174185 failPointAdminDb .runCommand (Document .parse ("{'configureFailPoint': 'failCommand', 'mode': 'off'}" ));
175186 }
0 commit comments