-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise an actionable error message when retryWrites fails due to
using an unsupported storage engine JAVA-3374
- Loading branch information
1 parent
4e5fefa
commit e45c8f3
Showing
7 changed files
with
259 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit # Exit the script with error if any of the commands fail | ||
|
||
# Supported/used environment variables: | ||
# MONGODB_URI Set the URI, including username/password to use to connect to the server via PLAIN authentication mechanism | ||
# JDK Set the version of java to be used. Java versions can be set from the java toolchain /opt/java | ||
# "jdk5", "jdk6", "jdk7", "jdk8", "jdk9" | ||
|
||
JDK=${JDK:-jdk} | ||
|
||
############################################ | ||
# Main Program # | ||
############################################ | ||
|
||
echo "Running MMAPv1 Storage Test" | ||
|
||
echo "Compiling java driver with jdk9" | ||
|
||
# We always compile with the latest version of java | ||
export JAVA_HOME="/opt/java/jdk9" | ||
|
||
echo "Running tests with ${JDK}" | ||
./gradlew -version | ||
./gradlew -PjdkHome=/opt/java/${JDK} --stacktrace --info \ | ||
-Dorg.mongodb.test.uri=${MONGODB_URI} \ | ||
-Dtest.single=RetryableWritesProseTest driver-sync:test driver-async:test |
102 changes: 102 additions & 0 deletions
102
driver-async/src/test/functional/com/mongodb/async/client/RetryableWritesProseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.mongodb.async.client; | ||
|
||
import com.mongodb.MongoClientException; | ||
import com.mongodb.MongoException; | ||
import com.mongodb.async.FutureResultCallback; | ||
import com.mongodb.client.test.CollectionHelper; | ||
import org.bson.Document; | ||
import org.bson.codecs.DocumentCodec; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.mongodb.ClusterFixture.getServerStatus; | ||
import static com.mongodb.ClusterFixture.isDiscoverableReplicaSet; | ||
import static com.mongodb.ClusterFixture.isSharded; | ||
import static com.mongodb.ClusterFixture.serverVersionAtLeast; | ||
import static com.mongodb.ClusterFixture.serverVersionLessThan; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
public class RetryableWritesProseTest extends DatabaseTestCase { | ||
private CollectionHelper<Document> collectionHelper; | ||
|
||
@Before | ||
@Override | ||
public void setUp() { | ||
assumeTrue(canRunTests()); | ||
super.setUp(); | ||
|
||
collectionHelper = new CollectionHelper<Document>(new DocumentCodec(), collection.getNamespace()); | ||
collectionHelper.create(); | ||
} | ||
|
||
@Test | ||
public void testRetryWritesWithInsertOneAgainstMMAPv1RaisesError() { | ||
boolean exceptionFound = false; | ||
|
||
try { | ||
FutureResultCallback<Void> callback = new FutureResultCallback<Void>(); | ||
collection.insertOne(Document.parse("{ x : 1 }"), callback); | ||
futureResult(callback); | ||
} catch (MongoClientException e) { | ||
assertTrue(e.getMessage().equals("This MongoDB deployment does not support retryable writes. " | ||
+ "Please add retryWrites=false to your connection string.")); | ||
assertTrue(((MongoException) e.getCause()).getCode() == 20); | ||
assertTrue(e.getCause().getMessage().contains("Transaction numbers")); | ||
exceptionFound = true; | ||
} | ||
assertTrue(exceptionFound); | ||
} | ||
|
||
@Test | ||
public void testRetryWritesWithFindOneAndDeleteAgainstMMAPv1RaisesError() { | ||
boolean exceptionFound = false; | ||
|
||
try { | ||
FutureResultCallback<Document> callback = new FutureResultCallback<Document>(); | ||
collection.findOneAndDelete(Document.parse("{ x : 1 }"), callback); | ||
futureResult(callback); | ||
} catch (MongoClientException e) { | ||
assertTrue(e.getMessage().equals("This MongoDB deployment does not support retryable writes. " | ||
+ "Please add retryWrites=false to your connection string.")); | ||
assertTrue(((MongoException) e.getCause()).getCode() == 20); | ||
assertTrue(e.getCause().getMessage().contains("Transaction numbers")); | ||
exceptionFound = true; | ||
} | ||
assertTrue(exceptionFound); | ||
} | ||
|
||
private boolean canRunTests() { | ||
Document storageEngine = (Document) getServerStatus().get("storageEngine"); | ||
|
||
return ((isSharded() || isDiscoverableReplicaSet()) | ||
&& storageEngine != null && storageEngine.get("name").equals("mmapv1") | ||
&& serverVersionAtLeast(3, 6) && serverVersionLessThan(4, 1)); | ||
} | ||
|
||
private <T> T futureResult(final FutureResultCallback<T> callback) { | ||
try { | ||
return callback.get(30, TimeUnit.SECONDS); | ||
} catch (Throwable t) { | ||
throw MongoException.fromThrowable(t); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
driver-sync/src/test/functional/com/mongodb/client/RetryableWritesProseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.mongodb.client; | ||
|
||
import com.mongodb.MongoClientException; | ||
import com.mongodb.MongoException; | ||
import org.bson.Document; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static com.mongodb.ClusterFixture.getServerStatus; | ||
import static com.mongodb.ClusterFixture.isDiscoverableReplicaSet; | ||
import static com.mongodb.ClusterFixture.isSharded; | ||
import static com.mongodb.ClusterFixture.serverVersionAtLeast; | ||
import static com.mongodb.ClusterFixture.serverVersionLessThan; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
public class RetryableWritesProseTest extends DatabaseTestCase { | ||
|
||
@Before | ||
@Override | ||
public void setUp() { | ||
assumeTrue(canRunTests()); | ||
super.setUp(); | ||
} | ||
|
||
@Test | ||
public void testRetryWritesWithInsertOneAgainstMMAPv1RaisesError() { | ||
boolean exceptionFound = false; | ||
|
||
try { | ||
collection.insertOne(Document.parse("{x: 1}")); | ||
} catch (MongoClientException e) { | ||
assertTrue(e.getMessage().equals("This MongoDB deployment does not support retryable writes. " | ||
+ "Please add retryWrites=false to your connection string.")); | ||
assertTrue(((MongoException) e.getCause()).getCode() == 20); | ||
assertTrue(e.getCause().getMessage().contains("Transaction numbers")); | ||
exceptionFound = true; | ||
} | ||
assertTrue(exceptionFound); | ||
} | ||
|
||
@Test | ||
public void testRetryWritesWithFindOneAndDeleteAgainstMMAPv1RaisesError() { | ||
boolean exceptionFound = false; | ||
|
||
try { | ||
collection.findOneAndDelete(Document.parse("{x: 1}")); | ||
} catch (MongoClientException e) { | ||
assertTrue(e.getMessage().equals("This MongoDB deployment does not support retryable writes. " | ||
+ "Please add retryWrites=false to your connection string.")); | ||
assertTrue(((MongoException) e.getCause()).getCode() == 20); | ||
assertTrue(e.getCause().getMessage().contains("Transaction numbers")); | ||
exceptionFound = true; | ||
} | ||
assertTrue(exceptionFound); | ||
} | ||
|
||
private boolean canRunTests() { | ||
Document storageEngine = (Document) getServerStatus().get("storageEngine"); | ||
|
||
return ((isSharded() || isDiscoverableReplicaSet()) | ||
&& storageEngine != null && storageEngine.get("name").equals("mmapv1") | ||
&& serverVersionAtLeast(3, 6) && serverVersionLessThan(4, 1)); | ||
} | ||
} |