Skip to content

Commit 4537f37

Browse files
committed
Refactor prose retryable writes/reads tests
JAVA-6055
1 parent b33dca9 commit 4537f37

5 files changed

Lines changed: 237 additions & 178 deletions

File tree

driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/RetryableReadsProseTest.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,27 @@
2222
import org.bson.Document;
2323
import org.junit.jupiter.api.Test;
2424

25-
import java.util.concurrent.ExecutionException;
26-
import java.util.concurrent.TimeoutException;
27-
2825
import static com.mongodb.client.model.Filters.eq;
2926

3027
/**
31-
* See
32-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests">Retryable Reads Tests</a>.
28+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#prose-tests">
29+
* Prose Tests</a>.
3330
*/
3431
final class RetryableReadsProseTest {
3532
/**
36-
* See
37-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests#poolclearederror-retryability-test">
38-
* PoolClearedError Retryability Test</a>.
33+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#1-poolclearederror-retryability-test">
34+
* 1. PoolClearedError Retryability Test</a>.
3935
*/
4036
@Test
41-
void poolClearedExceptionMustBeRetryable() throws InterruptedException, ExecutionException, TimeoutException {
37+
void poolClearedExceptionMustBeRetryable() throws Exception {
4238
RetryableWritesProseTest.poolClearedExceptionMustBeRetryable(
4339
SyncMongoClient::new,
4440
mongoCollection -> mongoCollection.find(eq(0)).iterator().hasNext(), "find", false);
4541
}
4642

4743
/**
48-
* See
49-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests#21-retryable-reads-are-retried-on-a-different-mongos-when-one-is-available">
50-
* Retryable Reads Are Retried on a Different mongos When One is Available</a>.
44+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#21-retryable-reads-are-retried-on-a-different-mongos-when-one-is-available">
45+
* 2.1 Retryable Reads Are Retried on a Different mongos When One is Available</a>.
5146
*/
5247
@Test
5348
void retriesOnDifferentMongosWhenAvailable() {
@@ -61,9 +56,8 @@ void retriesOnDifferentMongosWhenAvailable() {
6156
}
6257

6358
/**
64-
* See
65-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests#22-retryable-reads-are-retried-on-the-same-mongos-when-no-others-are-available">
66-
* Retryable Reads Are Retried on the Same mongos When No Others are Available</a>.
59+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#22-retryable-reads-are-retried-on-the-same-mongos-when-no-others-are-available">
60+
* 2.2 Retryable Reads Are Retried on the Same mongos When No Others are Available</a>.
6761
*/
6862
@Test
6963
void retriesOnSameMongosWhenAnotherNotAvailable() {

driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/RetryableWritesProseTest.java

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,53 @@
1616

1717
package com.mongodb.reactivestreams.client;
1818

19-
import com.mongodb.client.test.CollectionHelper;
2019
import com.mongodb.reactivestreams.client.syncadapter.SyncMongoClient;
2120
import org.bson.Document;
22-
import org.bson.codecs.DocumentCodec;
23-
import org.junit.jupiter.api.BeforeEach;
2421
import org.junit.jupiter.api.Test;
2522

26-
import java.util.concurrent.ExecutionException;
27-
import java.util.concurrent.TimeoutException;
28-
2923
/**
30-
* See
31-
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-writes/tests/README.md#prose-tests">Retryable Write Prose Tests</a>.
24+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-writes/tests/README.md#prose-tests">
25+
* Prose Tests</a>.
3226
*/
33-
public class RetryableWritesProseTest extends DatabaseTestCase {
34-
private CollectionHelper<Document> collectionHelper;
35-
36-
@BeforeEach
37-
@Override
38-
public void setUp() {
39-
super.setUp();
40-
41-
collectionHelper = new CollectionHelper<>(new DocumentCodec(), collection.getNamespace());
42-
collectionHelper.create();
43-
}
44-
27+
final class RetryableWritesProseTest {
4528
/**
46-
* Prose test #2.
29+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-writes/tests/README.md#2-test-that-drivers-properly-retry-after-encountering-poolclearederrors">
30+
* 2. Test that drivers properly retry after encountering PoolClearedErrors</a>.
4731
*/
4832
@Test
49-
public void poolClearedExceptionMustBeRetryable() throws InterruptedException, ExecutionException, TimeoutException {
33+
void poolClearedExceptionMustBeRetryable() throws Exception {
5034
com.mongodb.client.RetryableWritesProseTest.poolClearedExceptionMustBeRetryable(
5135
SyncMongoClient::new,
5236
mongoCollection -> mongoCollection.insertOne(new Document()), "insert", true);
5337
}
5438

5539
/**
56-
* Prose test #3.
40+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-writes/tests/README.md#3-test-that-drivers-return-the-original-error-after-encountering-a-writeconcernerror-with-a-retryablewriteerror-label">
41+
* 3. Test that drivers return the original error after encountering a WriteConcernError with a RetryableWriteError label</a>.
5742
*/
5843
@Test
59-
public void originalErrorMustBePropagatedIfNoWritesPerformed() throws InterruptedException {
44+
void originalErrorMustBePropagatedIfNoWritesPerformed() throws Exception {
6045
com.mongodb.client.RetryableWritesProseTest.originalErrorMustBePropagatedIfNoWritesPerformed(
6146
SyncMongoClient::new);
6247
}
6348

6449
/**
65-
* Prose test #4.
50+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-writes/tests/README.md#4-test-that-in-a-sharded-cluster-writes-are-retried-on-a-different-mongos-when-one-is-available">
51+
* 4. Test that in a sharded cluster writes are retried on a different mongos when one is available</a>.
6652
*/
6753
@Test
68-
public void retriesOnDifferentMongosWhenAvailable() {
54+
void retriesOnDifferentMongosWhenAvailable() {
6955
com.mongodb.client.RetryableWritesProseTest.retriesOnDifferentMongosWhenAvailable(
7056
SyncMongoClient::new,
7157
mongoCollection -> mongoCollection.insertOne(new Document()), "insert", true);
7258
}
7359

7460
/**
75-
* Prose test #5.
61+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-writes/tests/README.md#5-test-that-in-a-sharded-cluster-writes-are-retried-on-the-same-mongos-when-no-others-are-available">
62+
* 5. Test that in a sharded cluster writes are retried on the same mongos when no others are available</a>.
7663
*/
7764
@Test
78-
public void retriesOnSameMongosWhenAnotherNotAvailable() {
65+
void retriesOnSameMongosWhenAnotherNotAvailable() {
7966
com.mongodb.client.RetryableWritesProseTest.retriesOnSameMongosWhenAnotherNotAvailable(
8067
SyncMongoClient::new,
8168
mongoCollection -> mongoCollection.insertOne(new Document()), "insert", true);

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,26 @@
1919
import org.bson.Document;
2020
import org.junit.jupiter.api.Test;
2121

22-
import java.util.concurrent.ExecutionException;
23-
import java.util.concurrent.TimeoutException;
24-
2522
import static com.mongodb.client.model.Filters.eq;
2623

2724
/**
28-
* See
29-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests">Retryable Reads Tests</a>.
25+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#prose-tests">
26+
* Prose Tests</a>.
3027
*/
3128
final class RetryableReadsProseTest {
3229
/**
33-
* See
34-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests#poolclearederror-retryability-test">
35-
* PoolClearedError Retryability Test</a>.
30+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#1-poolclearederror-retryability-test">
31+
* 1. PoolClearedError Retryability Test</a>.
3632
*/
3733
@Test
38-
void poolClearedExceptionMustBeRetryable() throws InterruptedException, ExecutionException, TimeoutException {
34+
void poolClearedExceptionMustBeRetryable() throws Exception {
3935
RetryableWritesProseTest.poolClearedExceptionMustBeRetryable(MongoClients::create,
4036
mongoCollection -> mongoCollection.find(eq(0)).iterator().hasNext(), "find", false);
4137
}
4238

4339
/**
44-
* See
45-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests#21-retryable-reads-are-retried-on-a-different-mongos-when-one-is-available">
46-
* Retryable Reads Are Retried on a Different mongos When One is Available</a>.
40+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#21-retryable-reads-are-retried-on-a-different-mongos-when-one-is-available">
41+
* 2.1 Retryable Reads Are Retried on a Different mongos When One is Available</a>.
4742
*/
4843
@Test
4944
void retriesOnDifferentMongosWhenAvailable() {
@@ -56,9 +51,8 @@ void retriesOnDifferentMongosWhenAvailable() {
5651
}
5752

5853
/**
59-
* See
60-
* <a href="https://github.com/mongodb/specifications/tree/master/source/retryable-reads/tests#22-retryable-reads-are-retried-on-the-same-mongos-when-no-others-are-available">
61-
* Retryable Reads Are Retried on the Same mongos When No Others are Available</a>.
54+
* <a href="https://github.com/mongodb/specifications/blob/master/source/retryable-reads/tests/README.md#22-retryable-reads-are-retried-on-the-same-mongos-when-no-others-are-available">
55+
* 2.2 Retryable Reads Are Retried on the Same mongos When No Others are Available</a>.
6256
*/
6357
@Test
6458
void retriesOnSameMongosWhenAnotherNotAvailable() {

0 commit comments

Comments
 (0)