Author: mreutegg
Date: Wed Mar 7 10:03:26 2018
New Revision: 1826092
URL: http://svn.apache.org/viewvc?rev=1826092&view=rev
Log:
OAK-7306: MongoDocumentStore: use transient DocumentStoreException type where
appropriate
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java?rev=1826092&r1=1826091&r2=1826092&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtils.java
Wed Mar 7 10:03:26 2018
@@ -27,6 +27,7 @@ import com.mongodb.MongoException;
import com.mongodb.MongoNotPrimaryException;
import com.mongodb.MongoSocketException;
import com.mongodb.MongoWriteConcernException;
+import com.mongodb.WriteConcernException;
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.Type;
@@ -153,8 +154,9 @@ class MongoUtils {
|| t instanceof MongoWriteConcernException
|| t instanceof MongoNotPrimaryException) {
type = Type.TRANSIENT;
- } else if (t instanceof MongoCommandException) {
- int code = ((MongoCommandException) t).getErrorCode();
+ } else if (t instanceof MongoCommandException
+ || t instanceof WriteConcernException) {
+ int code = ((MongoException) t).getCode();
if (code == 11600 // InterruptedAtShutdown
|| code == 11601 // Interrupted
|| code == 11602) { // InterruptedDueToReplStateChange
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java?rev=1826092&r1=1826091&r2=1826092&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoUtilsTest.java
Wed Mar 7 10:03:26 2018
@@ -20,10 +20,12 @@ import java.io.IOException;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
+import com.mongodb.DuplicateKeyException;
import com.mongodb.MongoCommandException;
import com.mongodb.MongoException;
import com.mongodb.MongoSocketException;
import com.mongodb.ServerAddress;
+import com.mongodb.WriteConcernException;
import org.apache.jackrabbit.oak.plugins.document.MongoConnectionFactory;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
@@ -133,18 +135,29 @@ public class MongoUtilsTest {
public void documentStoreExceptionType() {
assertEquals(GENERIC, getDocumentStoreExceptionTypeFor(new
IOException()));
assertEquals(GENERIC, getDocumentStoreExceptionTypeFor(new
MongoException("message")));
- assertEquals(GENERIC,
getDocumentStoreExceptionTypeFor(createMongoCommandException(42)));
- assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(createMongoCommandException(11600)));
- assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(createMongoCommandException(11601)));
- assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(createMongoCommandException(11602)));
+ assertEquals(GENERIC,
getDocumentStoreExceptionTypeFor(newMongoCommandException(42)));
+ assertEquals(GENERIC, getDocumentStoreExceptionTypeFor(new
DuplicateKeyException(response(11000), new ServerAddress(), null)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(newWriteConcernException(11600)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(newWriteConcernException(11601)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(newWriteConcernException(11602)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(newMongoCommandException(11600)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(newMongoCommandException(11601)));
+ assertEquals(TRANSIENT,
getDocumentStoreExceptionTypeFor(newMongoCommandException(11602)));
assertEquals(TRANSIENT, getDocumentStoreExceptionTypeFor(new
MongoSocketException("message", new ServerAddress())));
}
- private static MongoCommandException createMongoCommandException(int code)
{
+ private static MongoCommandException newMongoCommandException(int code) {
+ return new MongoCommandException(response(code), new ServerAddress());
+ }
+
+ private static WriteConcernException newWriteConcernException(int code) {
+ return new WriteConcernException(response(code), new ServerAddress(),
null);
+ }
+
+ private static BsonDocument response(int code) {
BsonDocument response = new BsonDocument();
response.put("code", new BsonInt32(code));
response.put("errmsg", new BsonString("message"));
- ServerAddress address = new ServerAddress();
- return new MongoCommandException(response, address);
+ return response;
}
}