Skip to content

Commit 9dcd5c0

Browse files
committed
Fixing tests
1 parent f22198e commit 9dcd5c0

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

driver-sync/src/test/functional/com/mongodb/client/ClientSideOperationTimeoutProseTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.mongodb.client.gridfs.GridFSBucket;
2121
import com.mongodb.client.gridfs.GridFSBuckets;
2222
import com.mongodb.internal.time.ExponentialBackoff;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeEach;
2325

2426

2527
/**
@@ -37,15 +39,16 @@ protected GridFSBucket createGridFsBucket(final MongoDatabase mongoDatabase, fin
3739
return GridFSBuckets.create(mongoDatabase, bucketName);
3840
}
3941

42+
@BeforeEach
4043
@Override
4144
public void setUp() {
4245
super.setUp();
4346
ExponentialBackoff.setTestJitterSupplier(() -> 0);
4447
}
4548

49+
@AfterEach
4650
@Override
4751
public void tearDown() throws InterruptedException {
48-
super.tearDown();
4952
try {
5053
super.tearDown();
5154
} finally {

driver-sync/src/test/functional/com/mongodb/client/WithTransactionProseTest.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
import com.mongodb.ClientSessionOptions;
2020
import com.mongodb.MongoClientException;
21+
import com.mongodb.MongoCommandException;
2122
import com.mongodb.MongoException;
23+
import com.mongodb.MongoNodeIsRecoveringException;
24+
import com.mongodb.MongoTimeoutException;
2225
import com.mongodb.TransactionOptions;
2326
import com.mongodb.client.model.Sorts;
2427
import com.mongodb.internal.time.ExponentialBackoff;
@@ -42,6 +45,7 @@
4245
import static com.mongodb.ClusterFixture.isSharded;
4346
import static com.mongodb.client.Fixture.getPrimary;
4447
import static org.junit.jupiter.api.Assertions.assertEquals;
48+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
4549
import static org.junit.jupiter.api.Assertions.assertThrows;
4650
import static org.junit.jupiter.api.Assertions.assertTrue;
4751
import 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

Comments
 (0)