Skip to content

Commit d85982d

Browse files
authored
Port transactions spec tests to unified format (#1310)
JAVA-4171
1 parent afc0eab commit d85982d

File tree

99 files changed

+33650
-24946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+33650
-24946
lines changed

driver-core/src/test/functional/com/mongodb/client/test/CollectionHelper.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.mongodb.MongoClientSettings;
2020
import com.mongodb.MongoCommandException;
2121
import com.mongodb.MongoNamespace;
22+
import com.mongodb.MongoWriteConcernException;
2223
import com.mongodb.ReadPreference;
2324
import com.mongodb.ServerCursor;
2425
import com.mongodb.WriteConcern;
@@ -34,6 +35,8 @@
3435
import com.mongodb.internal.bulk.UpdateRequest;
3536
import com.mongodb.internal.bulk.WriteRequest;
3637
import com.mongodb.internal.client.model.AggregationLevel;
38+
import com.mongodb.internal.diagnostics.logging.Logger;
39+
import com.mongodb.internal.diagnostics.logging.Loggers;
3740
import com.mongodb.internal.operation.AggregateOperation;
3841
import com.mongodb.internal.operation.BatchCursor;
3942
import com.mongodb.internal.operation.CommandReadOperation;
@@ -70,6 +73,7 @@
7073
import static java.util.Collections.singletonList;
7174

7275
public final class CollectionHelper<T> {
76+
private static final Logger LOGGER = Loggers.getLogger("test");
7377

7478
private final Codec<T> codec;
7579
private final CodecRegistry registry = MongoClientSettings.getDefaultCodecRegistry();
@@ -89,7 +93,18 @@ public static void drop(final MongoNamespace namespace) {
8993
}
9094

9195
public static void drop(final MongoNamespace namespace, final WriteConcern writeConcern) {
92-
new DropCollectionOperation(namespace, writeConcern).execute(getBinding());
96+
// This loop is a workaround for unanticipated failures of the drop command when run on a sharded cluster < 4.2.
97+
// In practice the command tends to succeed on the first attempt after a failure
98+
boolean success = false;
99+
while (!success) {
100+
try {
101+
new DropCollectionOperation(namespace, writeConcern).execute(getBinding());
102+
success = true;
103+
} catch (MongoWriteConcernException e) {
104+
LOGGER.info("Retrying drop collection after a write concern error: " + e);
105+
// repeat until success!
106+
}
107+
}
93108
}
94109

95110
public static void dropDatabase(final String name) {
@@ -159,7 +174,23 @@ public void create(final String collectionName, final CreateCollectionOptions op
159174
if (validationOptions.getValidationAction() != null) {
160175
operation.validationAction(validationOptions.getValidationAction());
161176
}
162-
operation.execute(getBinding());
177+
178+
// This loop is a workaround for unanticipated failures of the create command when run on a sharded cluster < 4.2
179+
// In practice the command tends to succeed on the first attempt after a failure
180+
boolean success = false;
181+
while (!success) {
182+
try {
183+
operation.execute(getBinding());
184+
success = true;
185+
} catch (MongoCommandException e) {
186+
if ("Interrupted".equals(e.getErrorCodeName())) {
187+
LOGGER.info("Retrying create collection after a write concern error: " + e);
188+
// repeat until success!
189+
} else {
190+
throw e;
191+
}
192+
}
193+
}
163194
}
164195

165196
public void killCursor(final MongoNamespace namespace, final ServerCursor serverCursor) {
@@ -399,7 +430,7 @@ public List<BsonDocument> listIndexes(){
399430
return indexes;
400431
}
401432

402-
public void killAllSessions() {
433+
public static void killAllSessions() {
403434
try {
404435
new CommandReadOperation<>("admin", new BsonDocument("killAllSessions", new BsonArray()),
405436
new BsonDocumentCodec()).execute(getBinding());

driver-core/src/test/resources/transactions-convenient-api/README.rst

Lines changed: 0 additions & 220 deletions
This file was deleted.

0 commit comments

Comments
 (0)