Skip to content

Commit 7891545

Browse files
committed
Add assertions not required by the spec to errorPropagationAfterEncounteringMultipleErrorsCase3
This made its `configureFailPointEventMatcher` the same as the one in cases 1 and 2, which lead to a nice simplification.
1 parent f9fd19e commit 7891545

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -375,20 +375,10 @@ public static void errorPropagationAfterEncounteringMultipleErrorsCase1(final Fu
375375
+ " errorLabels: ['" + RETRYABLE_ERROR_LABEL + "', '" + SYSTEM_OVERLOADED_ERROR_LABEL + "']\n"
376376
+ " }\n"
377377
+ "}\n");
378-
Predicate<CommandEvent> configureFailPointEventMatcher = event -> {
379-
if (event instanceof CommandFailedEvent) {
380-
CommandFailedEvent commandFailedEvent = (CommandFailedEvent) event;
381-
MongoException cause = assertInstanceOf(MongoException.class, commandFailedEvent.getThrowable());
382-
assertEquals(91, cause.getCode());
383-
return true;
384-
}
385-
return false;
386-
};
387378
errorPropagationAfterEncounteringMultipleErrors(
388379
clientCreator,
389380
configureFailPoint,
390381
configureFailPointFromListener,
391-
configureFailPointEventMatcher,
392382
10107,
393383
null);
394384
}
@@ -427,20 +417,10 @@ public static void errorPropagationAfterEncounteringMultipleErrorsCase2(final Fu
427417
+ "', '" + NO_WRITES_PERFORMED_ERROR_LABEL + "']\n"
428418
+ " }\n"
429419
+ "}\n");
430-
Predicate<CommandEvent> configureFailPointEventMatcher = event -> {
431-
if (event instanceof CommandFailedEvent) {
432-
CommandFailedEvent commandFailedEvent = (CommandFailedEvent) event;
433-
MongoException cause = assertInstanceOf(MongoException.class, commandFailedEvent.getThrowable());
434-
assertEquals(91, cause.getCode());
435-
return true;
436-
}
437-
return false;
438-
};
439420
errorPropagationAfterEncounteringMultipleErrors(
440421
clientCreator,
441422
configureFailPoint,
442423
configureFailPointFromListener,
443-
configureFailPointEventMatcher,
444424
91,
445425
null);
446426
}
@@ -479,12 +459,10 @@ public static void errorPropagationAfterEncounteringMultipleErrorsCase3(final Fu
479459
+ "', '" + NO_WRITES_PERFORMED_ERROR_LABEL + "']\n"
480460
+ " }\n"
481461
+ "}\n");
482-
Predicate<CommandEvent> configureFailPointEventMatcher = event -> event instanceof CommandFailedEvent;
483462
errorPropagationAfterEncounteringMultipleErrors(
484463
clientCreator,
485464
configureFailPoint,
486465
configureFailPointFromListener,
487-
configureFailPointEventMatcher,
488466
91,
489467
NO_WRITES_PERFORMED_ERROR_LABEL);
490468
}
@@ -496,12 +474,20 @@ private static void errorPropagationAfterEncounteringMultipleErrors(
496474
final Function<MongoClientSettings, MongoClient> clientCreator,
497475
final BsonDocument configureFailPoint,
498476
final BsonDocument configureFailPointFromListener,
499-
final Predicate<CommandEvent> configureFailPointEventMatcher,
500477
final int expectedErrorCode,
501478
@Nullable final String unexpectedErrorLabel) throws Exception {
502479
assumeTrue(serverVersionAtLeast(6, 0));
503480
assumeTrue(isDiscoverableReplicaSet());
504481
ServerAddress primaryServerAddress = getPrimary();
482+
Predicate<CommandEvent> configureFailPointEventMatcher = event -> {
483+
if (event instanceof CommandFailedEvent) {
484+
CommandFailedEvent commandFailedEvent = (CommandFailedEvent) event;
485+
MongoException cause = assertInstanceOf(MongoException.class, commandFailedEvent.getThrowable());
486+
assertEquals(91, cause.getCode());
487+
return true;
488+
}
489+
return false;
490+
};
505491
try (ConfigureFailPointCommandListener commandListener = new ConfigureFailPointCommandListener(
506492
configureFailPointFromListener, primaryServerAddress, configureFailPointEventMatcher);
507493
MongoClient client = clientCreator.apply(getMongoClientSettingsBuilder()

0 commit comments

Comments
 (0)