|
20 | 20 | import org.bson.BsonDocument;
|
21 | 21 | import org.junit.jupiter.api.BeforeEach;
|
22 | 22 | import org.junit.jupiter.api.Test;
|
23 |
| - |
24 | 23 | import org.mockito.Mockito;
|
| 24 | + |
25 | 25 | import org.springframework.core.NestedRuntimeException;
|
26 | 26 | import org.springframework.dao.DataAccessException;
|
27 | 27 | import org.springframework.dao.DataAccessResourceFailureException;
|
28 |
| -import org.springframework.dao.DataIntegrityViolationException; |
29 | 28 | import org.springframework.dao.DuplicateKeyException;
|
30 | 29 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
31 | 30 | import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
32 | 31 | import org.springframework.data.mongodb.ClientSessionException;
|
33 | 32 | import org.springframework.data.mongodb.MongoTransactionException;
|
34 |
| -import org.springframework.data.mongodb.TransientMongoDbException; |
35 | 33 | import org.springframework.data.mongodb.UncategorizedMongoDbException;
|
36 | 34 | import org.springframework.lang.Nullable;
|
37 | 35 |
|
|
41 | 39 | import com.mongodb.MongoSocketException;
|
42 | 40 | import com.mongodb.MongoSocketReadTimeoutException;
|
43 | 41 | import com.mongodb.MongoSocketWriteException;
|
44 |
| -import com.mongodb.MongoWriteException; |
45 | 42 | import com.mongodb.ServerAddress;
|
46 |
| -import com.mongodb.WriteError; |
47 | 43 |
|
48 | 44 | /**
|
49 | 45 | * Unit tests for {@link MongoExceptionTranslator}.
|
@@ -180,30 +176,19 @@ public void translateTransientTransactionExceptions() {
|
180 | 176 | MongoException source = new MongoException(267, "PreparedTransactionInProgress");
|
181 | 177 | source.addLabel(MongoException.TRANSIENT_TRANSACTION_ERROR_LABEL);
|
182 | 178 |
|
183 |
| - expectExceptionWithCauseMessage(translator.translateExceptionIfPossible(source), TransientMongoDbException.class, |
| 179 | + expectExceptionWithCauseMessage(translator.translateExceptionIfPossible(source), |
| 180 | + UncategorizedMongoDbException.class, |
184 | 181 | "PreparedTransactionInProgress");
|
185 | 182 | }
|
186 | 183 |
|
187 | 184 | @Test // DATAMONGO-2073
|
188 |
| - public void translateMongoExceptionWithTransientLabelToTransientMongoDbException() { |
| 185 | + public void translateMongoExceptionWithTransientLabel() { |
189 | 186 |
|
190 | 187 | MongoException exception = new MongoException(0, "");
|
191 | 188 | exception.addLabel(MongoException.UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL);
|
192 | 189 | DataAccessException translatedException = translator.translateExceptionIfPossible(exception);
|
193 | 190 |
|
194 |
| - expectExceptionWithCauseMessage(translatedException, TransientMongoDbException.class); |
195 |
| - } |
196 |
| - |
197 |
| - @Test // DATAMONGO-2073 |
198 |
| - public void wrapsTranslatedExceptionsWhenTransientLabelPresent() { |
199 |
| - |
200 |
| - MongoException exception = new MongoWriteException(new WriteError(112, "WriteConflict", new BsonDocument()), null); |
201 |
| - exception.addLabel(MongoException.UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL); |
202 |
| - |
203 |
| - DataAccessException translatedException = translator.translateExceptionIfPossible(exception); |
204 |
| - |
205 |
| - assertThat(translatedException).isInstanceOf(TransientMongoDbException.class); |
206 |
| - assertThat(translatedException.getCause()).isInstanceOf(DataIntegrityViolationException.class); |
| 191 | + expectExceptionWithCauseMessage(translatedException, UncategorizedMongoDbException.class); |
207 | 192 | }
|
208 | 193 |
|
209 | 194 | private void checkTranslatedMongoException(Class<? extends Exception> clazz, int code) {
|
|
0 commit comments