Author: mreutegg
Date: Thu Jan 11 12:30:43 2018
New Revision: 1820871
URL: http://svn.apache.org/viewvc?rev=1820871&view=rev
Log:
OAK-7139: Wrap MongoException when query fails
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/com/mongodb/OakFongo.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1820871&r1=1820870&r2=1820871&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
Thu Jan 11 12:30:43 2018
@@ -490,7 +490,7 @@ public class MongoDocumentStore implemen
} catch (RuntimeException e) {
t = e;
}
- throw new DocumentStoreException("Failed to load document with " +
key, t);
+ throw handleException(t, collection, key);
}
/**
@@ -526,7 +526,7 @@ public class MongoDocumentStore implemen
}
}
if (ex != null) {
- throw ex;
+ throw handleException(ex, collection, key);
} else {
// impossible to get here
throw new IllegalStateException();
@@ -581,19 +581,23 @@ public class MongoDocumentStore implemen
String indexedProperty,
long startValue,
int limit) {
- return queryInternal(collection, fromKey, toKey, indexedProperty,
- startValue, limit, maxQueryTimeMS);
+ try {
+ return queryInternal(collection, fromKey, toKey, indexedProperty,
+ startValue, limit, maxQueryTimeMS);
+ } catch (MongoException e) {
+ throw handleException(e, collection, Lists.newArrayList(fromKey,
toKey));
+ }
}
@SuppressWarnings("unchecked")
@Nonnull
- <T extends Document> List<T> queryInternal(Collection<T> collection,
- String fromKey,
- String toKey,
- String indexedProperty,
- long startValue,
- int limit,
- long maxQueryTime) {
+ protected <T extends Document> List<T> queryInternal(Collection<T>
collection,
+ String fromKey,
+ String toKey,
+ String
indexedProperty,
+ long startValue,
+ int limit,
+ long maxQueryTime) {
log("query", fromKey, toKey, indexedProperty, startValue, limit);
DBCollection dbCollection = getDBCollection(collection);
QueryBuilder queryBuilder = QueryBuilder.start(Document.ID);
@@ -1700,7 +1704,7 @@ public class MongoDocumentStore implemen
}
}
- private <T extends Document> DocumentStoreException
handleException(Exception ex,
+ private <T extends Document> DocumentStoreException
handleException(Throwable ex,
Collection<T> collection,
Iterable<String> ids) {
if (collection == Collection.NODES) {
@@ -1711,7 +1715,7 @@ public class MongoDocumentStore implemen
return DocumentStoreException.convert(ex, ids);
}
- private <T extends Document> DocumentStoreException
handleException(Exception ex,
+ private <T extends Document> DocumentStoreException
handleException(Throwable ex,
Collection<T> collection,
String
id) {
return handleException(ex, collection, Collections.singleton(id));
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/com/mongodb/OakFongo.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/com/mongodb/OakFongo.java?rev=1820871&r1=1820870&r2=1820871&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/com/mongodb/OakFongo.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/com/mongodb/OakFongo.java
Thu Jan 11 12:30:43 2018
@@ -88,6 +88,10 @@ public class OakFongo extends Fongo {
List<?> writeRequests,
WriteConcern aWriteConcern)
{}
+ protected void beforeFind(DBObject query, DBObject projection) {}
+
+ protected void afterFind(DBCursor cursor) {}
+
protected void afterExecuteBulkWriteOperation(BulkWriteResult result) {}
private class OakFongoDB extends FongoDB {
@@ -206,5 +210,13 @@ public class OakFongo extends Fongo {
afterExecuteBulkWriteOperation(result);
return result;
}
+
+ @Override
+ public DBCursor find(DBObject query, DBObject projection) {
+ beforeFind(query, projection);
+ DBCursor result = super.find(query, projection);
+ afterFind(result);
+ return result;
+ }
}
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java?rev=1820871&r1=1820870&r2=1820871&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
Thu Jan 11 12:30:43 2018
@@ -35,6 +35,8 @@ import org.junit.Before;
import org.junit.Test;
import static java.util.Collections.singletonList;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -76,6 +78,11 @@ public class MongoDBExceptionTest {
maybeThrow();
}
+ @Override
+ protected void beforeFind(DBObject query, DBObject projection) {
+ maybeThrow();
+ }
+
private void maybeThrow() {
if (exceptionMsg != null) {
throw new MongoException(exceptionMsg);
@@ -124,5 +131,29 @@ public class MongoDBExceptionTest {
assertTrue("Exception message does not contain id: '" +
e.getMessage() + "'",
e.getMessage().contains(id));
}
+
+ exceptionMsg = "find failed";
+ try {
+ store.find(Collection.NODES, id);
+ fail("DocumentStoreException expected");
+ } catch (DocumentStoreException e) {
+ assertThat(e.getMessage(), containsString(exceptionMsg));
+ assertTrue("Exception message does not contain id: '" +
e.getMessage() + "'",
+ e.getMessage().contains(id));
+ }
+
+ String fromKey = Utils.getKeyLowerLimit("/foo");
+ String toKey = Utils.getKeyUpperLimit("/foo");
+ exceptionMsg = "query failed";
+ try {
+ store.query(Collection.NODES, fromKey, toKey, 100);
+ fail("DocumentStoreException expected");
+ } catch (DocumentStoreException e) {
+ assertThat(e.getMessage(), containsString(exceptionMsg));
+ assertTrue("Exception message does not contain id: '" +
e.getMessage() + "'",
+ e.getMessage().contains(fromKey));
+ assertTrue("Exception message does not contain id: '" +
e.getMessage() + "'",
+ e.getMessage().contains(toKey));
+ }
}
}