Add earlier check for failure in RetryableWritesTest
@@ -53,6 +53,7 @@ import static com.mongodb.ClusterFixture.serverVersionAtLeast;
import static com.mongodb.ClusterFixture.serverVersionLessThan;
import static com.mongodb.async.client.Fixture.getMongoClientBuilderFromConnectionString;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
@@ -153,24 +154,29 @@ public class RetryableWritesTest extends DatabaseTestCase {
BsonDocument result = new BsonDocument();
boolean wasException = false;
+ Exception raisedException = null;
try {
result = helper.getOperationResults(operation);
} catch (Exception e) {
wasException = true;
- }
-
- if (outcome.containsKey("collection")) {
- FutureResultCallback<List<BsonDocument>> futureResultCallback = new FutureResultCallback<List<BsonDocument>>();
- collection.withDocumentClass(BsonDocument.class).find().into(new ArrayList<BsonDocument>(), futureResultCallback);
- assertEquals(outcome.getDocument("collection").getArray("data").getValues(), futureResult(futureResultCallback));
+ raisedException = e;
}
if (outcome.getBoolean("error", BsonBoolean.FALSE).getValue()) {
assertEquals(outcome.containsKey("error"), wasException);
+ } else if (wasException) {
+ fail("Unexpected exception: " + raisedException);
} else {
BsonDocument fixedExpectedResult = outcome.getDocument("result", new BsonDocument());
assertEquals(fixedExpectedResult, result.getDocument("result", new BsonDocument()));
}
+
+ if (outcome.containsKey("collection")) {
+ FutureResultCallback<List<BsonDocument>> futureResultCallback = new FutureResultCallback<List<BsonDocument>>();
+ collection.withDocumentClass(BsonDocument.class).find().into(new ArrayList<BsonDocument>(), futureResultCallback);
+ assertEquals(outcome.getDocument("collection").getArray("data").getValues(), futureResult(futureResultCallback));
+ }
+
}
@Parameterized.Parameters(name = "{1}")
