Author: reschke
Date: Wed Nov 8 17:55:13 2017
New Revision: 1814608
URL: http://svn.apache.org/viewvc?rev=1814608&view=rev
Log:
OAK-5028: Remove DocumentStore.update() (ported to 1.6)
Removed:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/CacheConsistencyIT.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistencyIT.java
Modified:
jackrabbit/oak/branches/1.6/oak-core/ (props changed)
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStats.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsCollector.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTestBase.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndInvalidateIT.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndUpdateIT.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStorePerformanceTest.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsIT.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/FailingDocumentStore.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCWithSplitTest.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/ReadOnlyDocumentStoreWrapperTest.java
Propchange: jackrabbit/oak/branches/1.6/oak-core/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 8 17:55:13 2017
@@ -1,4 +1,4 @@
/jackrabbit/oak/branches/1.0/oak-core:1665962
/jackrabbit/oak/trunk/oak-core:1781068,1781075,1781248,1781386,1781846,1781907,1782000,1782029,1782196,1782447,1782476,1782770,1782945,1782966,1782973,1782990,1783061,1783066,1783089,1783104-1783105,1783110,1783619,1783720,1783731,1783733,1783738,1783742,1783773,1783855,1783891,1784023,1784034,1784130,1784162,1784251,1784401,1784551,1784574,1784689,1785095,1785108,1785283,1785838,1785917,1785919,1785946,1786122,1787074,1787145,1787151,1787217,1787425,1788056,1788378,1788387-1788389,1788463,1788476,1788850,1789056,1789441,1789534,1790382,1792049,1792463,1792742,1792746,1793013,1793088,1793618,1793627,1793644,1794393,1794417,1794683,1795138,1795314,1795330,1795475,1795488,1795491,1795502,1795594,1795613,1795618,1796144,1796230,1796239,1796274,1796278,1796988,1797378,1798035,1798834,1799219,1799389,1799393,1799924,1800269,1800606,1800613,1800974,1801011,1801013,1801118-1801119,1801675,1802260,1802262,1802286,1802548,1802934,1802938,1802973,1803026,1803247-1803249,1803951,1803953-180395
5,1805851-1805852,1806668,1807308,1807688,1808125,1808128,1808142,1808240,1808246,1809024,1809026,1809131,1809163,1809253,1809255-1809256,1811380,1811952,1811963,1811986,1814332
-/jackrabbit/oak/trunk/oak-store-document:1809866,1811575,1811702,1811709,1811823,1811835,1811931,1812750,1812753,1814407
+/jackrabbit/oak/trunk/oak-store-document:1809866,1811575,1811702,1811709,1811823,1811835,1811931,1812750,1812753,1814407,1814499,1814579
/jackrabbit/trunk/oak-core:1345480
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java
Wed Nov 8 17:55:13 2017
@@ -255,31 +255,6 @@ public interface DocumentStore {
throws IllegalArgumentException, DocumentStoreException;
/**
- * Update documents with the given keys. Only existing documents are
- * updated and keys for documents that do not exist are simply ignored.
- * There is no guarantee in which sequence the updates are performed.
- * <p>
- * If this method fails with a {@code DocumentStoreException}, then only
some
- * of the documents identified by {@code keys} may have been updated. The
- * implementation however ensures that the result of the operation is
- * properly reflected in the document cache. That is, an implementation
- * could simply evict documents with the given keys from the cache.
- *
- * @param <T> the document type.
- * @param collection the collection.
- * @param keys the keys of the documents to update.
- * @param updateOp the update operation to apply to each of the documents
- * (where {@link Condition}s are not allowed)
- * @throws IllegalArgumentException when the {@linkplain UpdateOp} is
conditional
- * @throws DocumentStoreException if the operation failed. E.g. because of
- * an I/O error.
- */
- <T extends Document> void update(Collection<T> collection,
- List<String> keys,
- UpdateOp updateOp)
- throws IllegalArgumentException, DocumentStoreException;
-
- /**
* Atomically checks if the document exists and updates it, otherwise the
* document is created (aka upsert). The returned document is immutable.
* <p>
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStats.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStats.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStats.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStats.java
Wed Nov 8 17:55:13 2017
@@ -239,12 +239,6 @@ public class DocumentStoreStats implemen
}
@Override
- public void doneUpdate(long timeTakenNanos, Collection<? extends Document>
collection, int updateCount) {
- //NODES - Update is called for lastRev update
- perfLog(timeTakenNanos, "update");
- }
-
- @Override
public void doneFindAndModify(long timeTakenNanos, Collection<? extends
Document> collection, String key, boolean newEntry,
boolean success, int retryCount) {
if (collection == Collection.NODES){
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsCollector.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsCollector.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsCollector.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsCollector.java
Wed Nov 8 17:55:13 2017
@@ -73,14 +73,6 @@ public interface DocumentStoreStatsColle
void doneCreateOrUpdate(long timeTakenNanos, Collection<? extends
Document> collection, List<String> ids);
/**
- * Called when a given updated has modified multiple documents
- * @param timeTakenNanos time taken
- * @param collection the collection
- * @param updateCount number of updates performed
- */
- void doneUpdate(long timeTakenNanos, Collection<? extends Document>
collection, int updateCount);
-
- /**
* Called when a update operation was completed which affected single
* document.
* @param timeTakenNanos time taken
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
Wed Nov 8 17:55:13 2017
@@ -357,26 +357,6 @@ public class MemoryDocumentStore impleme
}
@Override
- public <T extends Document> void update(Collection<T> collection,
- List<String> keys,
- UpdateOp updateOp) {
- assertUnconditional(updateOp);
- Lock lock = rwLock.writeLock();
- lock.lock();
- try {
- ConcurrentSkipListMap<String, T> map = getMap(collection);
- for (String key : keys) {
- if (!map.containsKey(key)) {
- continue;
- }
- internalCreateOrUpdate(collection, updateOp.shallowCopy(key),
true);
- }
- } finally {
- lock.unlock();
- }
- }
-
- @Override
public String toString() {
StringBuilder buff = new StringBuilder();
buff.append("Nodes:\n");
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
Wed Nov 8 17:55:13 2017
@@ -103,10 +103,8 @@ import com.mongodb.WriteResult;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not;
-import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Maps.filterKeys;
-import static com.google.common.collect.Maps.filterValues;
import static com.google.common.collect.Sets.difference;
import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createIndex;
import static
org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex;
@@ -1181,63 +1179,6 @@ public class MongoDocumentStore implemen
}
}
- @Override
- public <T extends Document> void update(Collection<T> collection,
- List<String> keys,
- UpdateOp updateOp) {
- log("update", keys, updateOp);
- UpdateUtils.assertUnconditional(updateOp);
- DBCollection dbCollection = getDBCollection(collection);
- QueryBuilder query = QueryBuilder.start(Document.ID).in(keys);
- // make sure we don't modify the original updateOp
- updateOp = updateOp.copy();
- DBObject update = createUpdate(updateOp, false);
- final Stopwatch watch = startWatch();
- try {
- Map<String, NodeDocument> cachedDocs = Collections.emptyMap();
- if (collection == Collection.NODES) {
- cachedDocs = Maps.newHashMap();
- for (String key : keys) {
- cachedDocs.put(key, nodesCache.getIfPresent(key));
- }
- }
- try {
- dbCollection.update(query.get(), update, false, true);
- if (collection == Collection.NODES) {
- Map<String, ModificationStamp> modCounts =
getModStamps(filterValues(cachedDocs, notNull()).keySet());
- // update cache
- for (Entry<String, NodeDocument> entry :
cachedDocs.entrySet()) {
- // the cachedDocs is not empty, so the collection =
NODES
- Lock lock = nodeLocks.acquire(entry.getKey());
- try {
- ModificationStamp postUpdateModStamp =
modCounts.get(entry.getKey());
- if (postUpdateModStamp != null
- && entry.getValue() != null
- && entry.getValue() != NodeDocument.NULL
- &&
Long.valueOf(postUpdateModStamp.modCount -
1).equals(entry.getValue().getModCount())) {
- // post update modCount is one higher than
- // what we currently see in the cache. we can
- // replace the cached document
- NodeDocument newDoc =
applyChanges(Collection.NODES, entry.getValue(),
updateOp.shallowCopy(entry.getKey()));
-
nodesCache.replaceCachedDocument(entry.getValue(), newDoc);
- } else {
- // make sure concurrently loaded document is
- // invalidated
- nodesCache.invalidate(entry.getKey());
- }
- } finally {
- lock.unlock();
- }
- }
- }
- } catch (MongoException e) {
- throw handleException(e, collection, keys);
- }
- } finally {
- stats.doneUpdate(watch.elapsed(TimeUnit.NANOSECONDS), collection,
keys.size());
- }
- }
-
/**
* Returns the {@link Document#MOD_COUNT} and
* {@link NodeDocument#MODIFIED_IN_SECS} values of the documents with the
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
Wed Nov 8 17:55:13 2017
@@ -315,12 +315,6 @@ public class RDBDocumentStore implements
}
@Override
- public <T extends Document> void update(Collection<T> collection,
List<String> keys, UpdateOp updateOp) {
- UpdateUtils.assertUnconditional(updateOp);
- internalUpdate(collection, keys, updateOp);
- }
-
- @Override
public <T extends Document> T createOrUpdate(Collection<T> collection,
UpdateOp update) {
UpdateUtils.assertUnconditional(update);
return internalCreateOrUpdate(collection, update, true, false);
@@ -1360,65 +1354,6 @@ public class RDBDocumentStore implements
update.increment(MODCOUNT, 1);
}
- @CheckForNull
- private <T extends Document> void internalUpdate(Collection<T> collection,
List<String> ids, UpdateOp update) {
-
- if (isAppendableUpdate(update, true) &&
!requiresPreviousState(update)) {
- Operation modOperation = update.getChanges().get(MODIFIEDKEY);
- long modified = getModifiedFromOperation(modOperation);
- boolean modifiedIsConditional = modOperation == null ||
modOperation.type != UpdateOp.Operation.Type.SET;
- String appendData = ser.asString(update);
-
- for (List<String> chunkedIds : Lists.partition(ids, CHUNKSIZE)) {
-
- if (collection == Collection.NODES) {
- for (String key : chunkedIds) {
- nodesCache.invalidate(key);
- }
- }
-
- Connection connection = null;
- RDBTableMetaData tmd = getTable(collection);
- boolean success = false;
- try {
- Stopwatch watch = startWatch();
- connection = this.ch.getRWConnection();
- success = db.batchedAppendingUpdate(connection, tmd,
chunkedIds, modified, modifiedIsConditional, appendData);
- connection.commit();
- //Internally 'db' would make multiple calls and number of
those
- //remote calls would not be captured
- stats.doneUpdate(watch.elapsed(TimeUnit.NANOSECONDS),
collection, chunkedIds.size());
- } catch (SQLException ex) {
- success = false;
- this.ch.rollbackConnection(connection);
- } finally {
- this.ch.closeConnection(connection);
- }
- if (success) {
- if (collection == Collection.NODES) {
- for (String id : chunkedIds) {
- nodesCache.invalidate(id);
- }
- }
- } else {
- for (String id : chunkedIds) {
- UpdateOp up = update.copy();
- up = up.shallowCopy(id);
- internalCreateOrUpdate(collection, up, false, true);
- }
- }
- }
- } else {
- Stopwatch watch = startWatch();
- for (String id : ids) {
- UpdateOp up = update.copy();
- up = up.shallowCopy(id);
- internalCreateOrUpdate(collection, up, false, true);
- }
- stats.doneUpdate(watch.elapsed(TimeUnit.NANOSECONDS), collection,
ids.size());
- }
- }
-
private <T extends Document> List<T> internalQuery(Collection<T>
collection, String fromKey, String toKey,
List<String> excludeKeyPatterns, List<QueryCondition> conditions,
int limit) {
Connection connection = null;
@@ -1758,14 +1693,6 @@ public class RDBDocumentStore implements
return true;
}
- /*
- * check whether this update operation requires knowledge about the
previous
- * state
- */
- private static boolean requiresPreviousState(UpdateOp update) {
- return !update.getConditions().isEmpty();
- }
-
private static long getModifiedFromOperation(Operation op) {
return op == null ? 0L : Long.parseLong(op.value.toString());
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java
Wed Nov 8 17:55:13 2017
@@ -131,42 +131,6 @@ public class RDBDocumentStoreJDBC {
}
}
- public boolean batchedAppendingUpdate(Connection connection,
RDBTableMetaData tmd, List<String> allIds, Long modified,
- boolean setModifiedConditionally, String appendData) throws
SQLException {
- boolean result = true;
- for (List<String> ids : Lists.partition(allIds,
RDBJDBCTools.MAX_IN_CLAUSE)) {
- String appendDataWithComma = "," + appendData;
- PreparedStatementComponent stringAppend =
this.dbInfo.getConcatQuery(appendDataWithComma, tmd.getDataLimitInOctets());
- PreparedStatementComponent inClause =
RDBJDBCTools.createInStatement("ID", ids, tmd.isIdBinary());
- StringBuilder t = new StringBuilder();
- t.append("update " + tmd.getName() + " set ");
- t.append(setModifiedConditionally ? "MODIFIED = case when ? >
MODIFIED then ? else MODIFIED end, " : "MODIFIED = ?, ");
- t.append("MODCOUNT = MODCOUNT + 1, DSIZE = DSIZE + ?, ");
- t.append("DATA = " + stringAppend.getStatementComponent() + " ");
- t.append("where ").append(inClause.getStatementComponent());
- PreparedStatement stmt = connection.prepareStatement(t.toString());
- try {
- int si = 1;
- stmt.setObject(si++, modified, Types.BIGINT);
- if (setModifiedConditionally) {
- stmt.setObject(si++, modified, Types.BIGINT);
- }
- stmt.setObject(si++, appendDataWithComma.length(),
Types.BIGINT);
- si = stringAppend.setParameters(stmt, si);
- si = inClause.setParameters(stmt, si);
- int count = stmt.executeUpdate();
- if (count != ids.size()) {
- LOG.debug("DB update failed: only " + result + " of " +
ids.size() + " updated. Table: " + tmd.getName() + ", IDs:"
- + ids);
- result = false;
- }
- } finally {
- stmt.close();
- }
- }
- return result;
- }
-
public int delete(Connection connection, RDBTableMetaData tmd,
List<String> allIds) throws SQLException {
int count = 0;
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java
Wed Nov 8 17:55:13 2017
@@ -124,13 +124,6 @@ public final class LeaseCheckDocumentSto
}
@Override
- public final <T extends Document> void update(Collection<T> collection,
- List<String> keys, UpdateOp updateOp) {
- performLeaseCheck();
- delegate.update(collection, keys, updateOp);
- }
-
- @Override
public final <T extends Document> T createOrUpdate(Collection<T>
collection,
UpdateOp update) {
performLeaseCheck();
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
Wed Nov 8 17:55:13 2017
@@ -207,25 +207,6 @@ public class LoggingDocumentStoreWrapper
}
}
- @Override
- public <T extends Document> void update(final Collection<T> collection,
- final List<String> keys,
- final UpdateOp updateOp) {
- try {
- logMethod("update", collection, keys, updateOp);
- logResult(new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- store.update(collection, keys, updateOp);
- return null;
- }
- });
- } catch (Exception e) {
- logException(e);
- throw convert(e);
- }
- }
-
@Nonnull
@Override
public <T extends Document> T createOrUpdate(final Collection<T>
collection,
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
Wed Nov 8 17:55:13 2017
@@ -96,12 +96,6 @@ public class SynchronizingDocumentStoreW
}
@Override
- public synchronized <T extends Document> void update(final Collection<T>
collection, final List<String> keys,
- final UpdateOp updateOp) {
- store.update(collection, keys, updateOp);
- }
-
- @Override
public synchronized <T extends Document> T createOrUpdate(final
Collection<T> collection, final UpdateOp update) {
return store.createOrUpdate(collection, update);
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
Wed Nov 8 17:55:13 2017
@@ -246,22 +246,6 @@ public class TimingDocumentStoreWrapper
}
@Override
- public <T extends Document> void update(Collection<T> collection,
- List<String> keys,
- UpdateOp updateOp) {
- try {
- long start = now();
- base.update(collection, keys, updateOp);
- updateAndLogTimes("update", start, 0, 0);
- if (logCommonCall()) {
- logCommonCall(start, "update " + collection);
- }
- } catch (Exception e) {
- throw convert(e);
- }
- }
-
- @Override
@CheckForNull
public <T extends Document> T createOrUpdate(Collection<T> collection,
UpdateOp update) {
try {
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java
Wed Nov 8 17:55:13 2017
@@ -355,16 +355,6 @@ public class BasicDocumentStoreTest exte
catch (IllegalArgumentException expected) {
// reported by DocumentStore
}
-
- try {
- UpdateOp up = new UpdateOp(id, false);
- up.equals("foo", "bar");
- super.ds.update(Collection.NODES, Collections.singletonList(id),
up);
- fail("conditional update should fail");
- }
- catch (IllegalArgumentException expected) {
- // reported by DocumentStore
- }
}
@Test
@@ -541,33 +531,6 @@ public class BasicDocumentStoreTest exte
}
@Test
- public void testRepeatingUpdatesOnSQLServer() {
- // simulates two updates to trigger the off-by-one bug documented in
OAK-3670
- String id = this.getClass().getName() +
".testRepeatingUpdatesOnSQLServer";
-
- // remove if present
- NodeDocument nd = super.ds.find(Collection.NODES, id);
- if (nd != null) {
- super.ds.remove(Collection.NODES, id);
- }
-
- UpdateOp up = new UpdateOp(id, true);
- assertTrue(super.ds.create(Collection.NODES,
Collections.singletonList(up)));
- removeMe.add(id);
-
- up = new UpdateOp(id, false);
- up.set("f0", generateConstantString(3000));
- super.ds.update(Collection.NODES, Collections.singletonList(id), up);
-
- up = new UpdateOp(id, false);
- up.set("f1", generateConstantString(967));
- super.ds.update(Collection.NODES, Collections.singletonList(id), up);
-
- NodeDocument doc = super.ds.find(Collection.NODES, id, 0);
- assertNotNull(doc);
- }
-
- @Test
public void testModifiedMaxUpdateQuery() {
String id = this.getClass().getName() + ".testModifiedMaxUpdate";
// create a test node
@@ -614,32 +577,6 @@ public class BasicDocumentStoreTest exte
}
@Test
- public void testModifyModified() {
- // https://issues.apache.org/jira/browse/OAK-2940
- String id = this.getClass().getName() + ".testModifyModified";
- // create a test node
- UpdateOp up = new UpdateOp(id, true);
- up.set("_modified", 1000L);
- boolean success = super.ds.create(Collection.NODES,
Collections.singletonList(up));
- assertTrue(success);
- removeMe.add(id);
-
- // update with "max" operation
- up = new UpdateOp(id, false);
- up.max("_modified", 2000L);
- super.ds.update(Collection.NODES, Collections.singletonList(id), up);
- NodeDocument nd = super.ds.find(Collection.NODES, id, 0);
- assertEquals(((Number)nd.get("_modified")).longValue(), 2000L);
-
- // update with "set" operation
- up = new UpdateOp(id, false);
- up.set("_modified", 1500L);
- super.ds.update(Collection.NODES, Collections.singletonList(id), up);
- nd = super.ds.find(Collection.NODES, id, 0);
- assertEquals(((Number)nd.get("_modified")).longValue(), 1500L);
- }
-
- @Test
public void testModifyDeletedOnce() {
// https://issues.apache.org/jira/browse/OAK-3852
String id = this.getClass().getName() + ".testModifyDeletedOnce";
@@ -656,15 +593,6 @@ public class BasicDocumentStoreTest exte
// RDB persistence does not distinguish null and false
assertEquals(dovalue.booleanValue(), Boolean.FALSE);
}
-
- // update
- up = new UpdateOp(id, false);
- up.set(NodeDocument.DELETED_ONCE, Boolean.TRUE);
- super.ds.update(Collection.NODES, Collections.singletonList(id), up);
- nd = super.ds.find(Collection.NODES, id, 0);
- assertNotNull(nd);
- assertNotNull(nd.get(NodeDocument.DELETED_ONCE));
-
assertEquals(((Boolean)nd.get(NodeDocument.DELETED_ONCE)).booleanValue(),
Boolean.TRUE);
}
@Test
@@ -791,33 +719,6 @@ public class BasicDocumentStoreTest exte
}
@Test
- public void testUpdateMultiple() {
- String id = this.getClass().getName() + ".testUpdateMultiple";
- // create a test node
- super.ds.remove(Collection.NODES, id);
- UpdateOp up = new UpdateOp(id, true);
- boolean success = super.ds.create(Collection.NODES,
Collections.singletonList(up));
- assertTrue(success);
- removeMe.add(id);
-
- // update a non-existing one and this one
- List<String> toupdate = new ArrayList<String>();
- toupdate.add(id + "-" + UUID.randomUUID());
- toupdate.add(id);
-
- UpdateOp up2 = new UpdateOp(id, false);
- up2.set("foo", "bar");
- ds.update(Collection.NODES, toupdate, up2);
-
- // id should be updated
- ds.invalidateCache();
- Document d = ds.find(Collection.NODES, id);
- assertNotNull(d);
- assertEquals(id, d.getId());
- assertEquals("bar", d.get("foo").toString());
- }
-
- @Test
public void testUpdateModified() {
String id = this.getClass().getName() + ".testUpdateModified";
// create a test node
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTestBase.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTestBase.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTestBase.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CacheConsistencyTestBase.java
Wed Nov 8 17:55:13 2017
@@ -108,29 +108,6 @@ public abstract class CacheConsistencyTe
setTemporaryUpdateException(null);
}
- // update
- try {
- // make sure cache is populated
- olddoc = ds.find(Collection.NODES, id1);
-
- String random = UUID.randomUUID().toString();
- setTemporaryUpdateException(random);
- try {
- up1 = new UpdateOp(id1, false);
- up1.set("_test", random);
- ds.update(Collection.NODES, Collections.singletonList(id1),
up1);
- fail("should have failed with DocumentStoreException");
- } catch (DocumentStoreException ex) {
- assertEquals("should fail with enforced exception",
ex.getCause().getMessage(), random);
- // make sure cache was invalidated
- NodeDocument newdoc = ds.find(Collection.NODES, id1, 1000);
- assertNotNull(newdoc);
- assertEquals(random, newdoc.get("_test"));
- }
- } finally {
- setTemporaryUpdateException(null);
- }
-
// createOrUpdate
try {
// make sure cache is populated
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndInvalidateIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndInvalidateIT.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndInvalidateIT.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndInvalidateIT.java
Wed Nov 8 17:55:13 2017
@@ -126,13 +126,16 @@ public class ConcurrentQueryAndInvalidat
}
private Iterable<String> updateDocuments() {
+ UpdateOp op = new UpdateOp("foo", false);
+ NodeDocument.setLastRev(op, newRevision());
+ List<UpdateOp> ops = Lists.newArrayList();
List<String> ids = Lists.newArrayList();
for (int i = 0; i < NUM_NODES; i++) {
- ids.add(getIdFromPath("/node-" + i));
+ String id = getIdFromPath("/node-" + i);
+ ids.add(id);
+ ops.add(op.shallowCopy(id));
}
- UpdateOp op = new UpdateOp("foo", false);
- NodeDocument.setLastRev(op, newRevision());
- ds2.update(NODES, ids, op);
+ ds2.createOrUpdate(NODES, ops);
return ids;
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndUpdateIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndUpdateIT.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndUpdateIT.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ConcurrentQueryAndUpdateIT.java
Wed Nov 8 17:55:13 2017
@@ -91,13 +91,13 @@ public class ConcurrentQueryAndUpdateIT
}
private void updateDocuments() {
- List<String> ids = Lists.newArrayList();
- for (int i = 0; i < NUM_NODES; i++) {
- ids.add(getIdFromPath("/node-" + i));
- }
UpdateOp op = new UpdateOp("foo", false);
NodeDocument.setLastRev(op, newRevision());
- ds.update(NODES, ids, op);
+ List<UpdateOp> ops = Lists.newArrayList();
+ for (int i = 0; i < NUM_NODES; i++) {
+ ops.add(op.shallowCopy(getIdFromPath("/node-" + i)));
+ }
+ ds.createOrUpdate(NODES, ops);
}
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
Wed Nov 8 17:55:13 2017
@@ -164,14 +164,6 @@ public class CountingDocumentStore imple
}
@Override
- public <T extends Document> void update(Collection<T> collection,
- List<String> keys,
- UpdateOp updateOp) {
- getStats(collection).numCreateOrUpdateCalls++;
- delegate.update(collection, keys, updateOp);
- }
-
- @Override
public <T extends Document> T createOrUpdate(Collection<T> collection,
UpdateOp update) {
getStats(collection).numCreateOrUpdateCalls++;
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
Wed Nov 8 17:55:13 2017
@@ -16,11 +16,8 @@
*/
package org.apache.jackrabbit.oak.plugins.document;
-import java.util.Collections;
-
import org.apache.jackrabbit.oak.json.JsopDiff;
import
org.apache.jackrabbit.oak.plugins.document.util.TimingDocumentStoreWrapper;
-import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -29,7 +26,6 @@ import org.junit.After;
import org.junit.Test;
import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
import static
org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS_RESOLUTION;
import static
org.apache.jackrabbit.oak.plugins.document.util.Utils.getIdFromPath;
import static org.junit.Assert.assertEquals;
@@ -119,17 +115,4 @@ public class DocumentNodeStoreIT extends
ns1.dispose();
ns2.dispose();
}
-
- // OAK-2297
- @Test
- public void updateAbsentDocument() throws Exception {
- String id = Utils.getIdFromPath("/test");
- // trigger cache entry for /test
- ds.find(NODES, id);
-
- UpdateOp updateOp = new UpdateOp(id, false);
- updateOp.setMapEntry("foo", Revision.newRevision(1), "bar");
-
- ds.update(NODES, Collections.singletonList(id), updateOp);
- }
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStorePerformanceTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStorePerformanceTest.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStorePerformanceTest.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStorePerformanceTest.java
Wed Nov 8 17:55:13 2017
@@ -29,7 +29,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.slf4j.Logger;
@@ -199,7 +198,11 @@ public class DocumentStorePerformanceTes
UpdateOp up = new UpdateOp(bid, true);
up.setMapEntry("_lastRev", cr, "iteration-" + cnt);
up.max("_modified",
NodeDocument.getModifiedInSecs(System.currentTimeMillis()));
- super.ds.update(Collection.NODES, ids, up);
+ List<UpdateOp> ops = new ArrayList<UpdateOp>();
+ for (String id : ids) {
+ ops.add(up.shallowCopy(id));
+ }
+ super.ds.createOrUpdate(Collection.NODES, ops);
cnt += 1;
}
@@ -308,107 +311,4 @@ public class DocumentStorePerformanceTes
LOG.info("document updates with property of size " + size + (growing ?
" (growing)" : "") + " for " + super.dsname + " was " + cnt + " in " + duration
+ "ms (" + (cnt / (duration / 1000f)) + "/s)");
}
-
- @Test
- public void testConcurrentUpdatePerf1DS() throws InterruptedException {
- String id = this.getClass().getName() + ".testConcurrentUpdatePerf1DS";
- concurrentUpdatePerf(id, 1);
- }
-
- @Test
- public void testConcurrentUpdatePerf2DS() throws InterruptedException {
- String id = this.getClass().getName() + ".testConcurrentUpdatePerf1DS";
- concurrentUpdatePerf(id, 2);
- }
-
- private void concurrentUpdatePerf(String testName, int stores) throws
InterruptedException {
- final String id = testName;
- final long duration = 1000;
-
- ds1.remove(Collection.NODES, id);
- UpdateOp up = new UpdateOp(id, true);
- up.set(Document.MOD_COUNT, 1L);
- up.set("c", 0L);
- up.set("u", 0L);
- super.ds1.create(Collection.NODES, Collections.singletonList(up));
- removeMe.add(id);
-
- final DocumentStore ts1 = ds1;
- final DocumentStore ts2 = stores == 2 ? ds2 : ds1;
-
- final AtomicBoolean threadTwoIsActive = new AtomicBoolean(false);
- final AtomicBoolean threadOneIsDone = new AtomicBoolean(false);
-
- Thread one = new Thread(new Runnable() {
- @Override
- public void run() {
- int failures = 0;
- while (!threadTwoIsActive.get()) {
- }
- // operation that requires fetching the previous state
- UpdateOp up = new UpdateOp(id, false);
- up.increment("c", 1);
- up.notEquals("qux", "qux");
- long end = System.currentTimeMillis() + duration;
- while (System.currentTimeMillis() < end) {
- try {
- ts1.update(Collection.NODES,
Collections.singletonList(id), up);
- } catch (RuntimeException ex) {
- failures += 1;
- }
- }
- try {
- UpdateOp up2 = new UpdateOp(id, false);
- up2.set("cfailures", failures);
- ts1.update(Collection.NODES,
Collections.singletonList(id), up2);
- } catch (RuntimeException ex) {
- }
- threadOneIsDone.set(true);
- }
- }, "cond");
-
- Thread two = new Thread(new Runnable() {
- @Override
- public void run() {
- int failures = 0;
- // operation that does not require fetching the previous state
- UpdateOp up = new UpdateOp(id, false);
- up.increment("u", 1);
- while (!threadOneIsDone.get()) {
- try {
- ts2.update(Collection.NODES,
Collections.singletonList(id), up);
- threadTwoIsActive.set(true);
- } catch (RuntimeException ex) {
- failures += 1;
- }
- }
- threadTwoIsActive.set(true);
- try {
- UpdateOp up2 = new UpdateOp(id, false);
- up2.set("ufailures", failures);
- ts1.update(Collection.NODES,
Collections.singletonList(id), up2);
- } catch (RuntimeException ex) {
- }
- }
- }, "uncond");
-
- two.start();
- one.start();
-
- two.join();
- one.join();
-
- // reading uncached because for some reason MongoDS doesn't see the
- // changes made in ds2
- NodeDocument nd = ds1.find(Collection.NODES, id, 0);
- assertNotNull(nd);
- int cc = nd.get("c") == null ? 0 :
Integer.valueOf(nd.get("c").toString());
- int uc = nd.get("u") == null ? 0 :
Integer.valueOf(nd.get("u").toString());
- long mc = nd.getModCount();
- String msg = String.format(
- "Concurrent updates %s on %s cond. updates: %d (failures: %s),
uncond. updates: %d (failures: %s), _modCount: %d, ops/sec: %d, %% of cond.
updates: %d",
- stores == 1 ? "(one ds)" : "(two ds)", super.dsname, cc,
nd.get("cfailures"), uc, nd.get("ufailures"), mc,
- mc * 1000 / duration, cc * 100 / mc);
- LOG.info(msg);
- }
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsIT.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsIT.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreStatsIT.java
Wed Nov 8 17:55:13 2017
@@ -19,10 +19,8 @@
package org.apache.jackrabbit.oak.plugins.document;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.UUID;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
@@ -106,25 +104,6 @@ public class DocumentStoreStatsIT extend
}
@Test
- public void update() throws Exception{
- String id = testName.getMethodName();
-
- UpdateOp up = new UpdateOp(id, true);
- ds.create(Collection.NODES, singletonList(up));
- removeMe.add(id);
-
- List<String> toupdate = new ArrayList<String>();
- toupdate.add(id + "-" + UUID.randomUUID());
- toupdate.add(id);
-
- UpdateOp up2 = new UpdateOp(id, false);
- up2.set("foo", "bar");
- ds.update(Collection.NODES, toupdate, up2);
-
- verify(stats).doneUpdate(anyLong(), eq(Collection.NODES), eq(2));
- }
-
- @Test
public void findAndModify() throws Exception{
String id = testName.getMethodName();
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java
Wed Nov 8 17:55:13 2017
@@ -101,13 +101,6 @@ public class DocumentStoreWrapper implem
}
@Override
- public <T extends Document> void update(Collection<T> collection,
- List<String> keys,
- UpdateOp updateOp) {
- store.update(collection, keys, updateOp);
- }
-
- @Override
public <T extends Document> T createOrUpdate(Collection<T> collection,
UpdateOp update) {
return store.createOrUpdate(collection, update);
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/FailingDocumentStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/FailingDocumentStore.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/FailingDocumentStore.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/FailingDocumentStore.java
Wed Nov 8 17:55:13 2017
@@ -140,17 +140,6 @@ class FailingDocumentStore extends Docum
}
@Override
- public <T extends Document> void update(Collection<T> collection,
- List<String> keys,
- UpdateOp updateOp) {
- // update individually
- for (String k : keys) {
- maybeFail();
- super.update(collection, singletonList(k), updateOp);
- }
- }
-
- @Override
public <T extends Document> T createOrUpdate(Collection<T> collection,
UpdateOp update) {
maybeFail();
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java
Wed Nov 8 17:55:13 2017
@@ -20,132 +20,27 @@ import static java.util.Collections.sync
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Random;
import java.util.concurrent.CountDownLatch;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class MultiDocumentStoreTest extends AbstractMultiDocumentStoreTest {
- private static final Logger LOG =
LoggerFactory.getLogger(MultiDocumentStoreTest.class);
-
public MultiDocumentStoreTest(DocumentStoreFixture dsf) {
super(dsf);
}
@Test
- public void testInterleavedUpdate() {
- String id = this.getClass().getName() + ".testInterleavedUpdate";
-
- // remove if present
- NodeDocument nd = super.ds1.find(Collection.NODES, id);
- if (nd != null) {
- super.ds1.remove(Collection.NODES, id);
- }
-
- UpdateOp up = new UpdateOp(id, true);
- up.set("_foo", 0);
- assertTrue(super.ds1.create(Collection.NODES,
Collections.singletonList(up)));
- removeMe.add(id);
-
- long increments = 10;
-
- for (int i = 0; i < increments; i++) {
- up = new UpdateOp(id, true);
- up.increment("_foo", 1);
- if (i % 2 == 0) {
- super.ds1.update(Collection.NODES,
Collections.singletonList(id), up);
- }
- else {
- super.ds2.update(Collection.NODES,
Collections.singletonList(id), up);
- }
- }
-
- // read uncached
- nd = super.ds1.find(Collection.NODES, id, 0);
- assertEquals("_foo should have been incremented 10 times", increments,
nd.get("_foo"));
- }
-
- @Test
- public void testInvalidateCache() {
- // use a "proper" ID because otherwise Mongo's cache invalidation will
fail
- // see OAK-2588
- String id = "1:/" + this.getClass().getName() + ".testInvalidateCache";
-
- // remove if present
- NodeDocument nd = super.ds1.find(Collection.NODES, id);
- if (nd != null) {
- super.ds1.remove(Collection.NODES, id);
- }
-
- UpdateOp up = new UpdateOp(id, true);
- up.set("_foo", "bar");
- assertTrue(super.ds1.create(Collection.NODES,
Collections.singletonList(up)));
- removeMe.add(id);
-
- // fill both caches
- NodeDocument nd1 = super.ds1.find(Collection.NODES, id);
- NodeDocument nd2 = super.ds2.find(Collection.NODES, id);
- assertNotNull(nd1);
- assertNotNull(nd2);
- long firstVersion = nd1.getModCount();
- assertEquals(firstVersion, nd2.getModCount().longValue());
-
- // letTimeElapse();
-
- // update through ds1
- UpdateOp upds1 = new UpdateOp(id, true);
- upds1.set("foo", "qux");
- super.ds1.update(Collection.NODES, Collections.singletonList(id),
upds1);
- nd1 = super.ds1.find(Collection.NODES, id);
- assertEquals("modcount should have changed in ds1", firstVersion + 1,
nd1.getModCount().longValue());
-
- // check cached version in ds2
- nd2 = super.ds2.find(Collection.NODES, id);
- assertEquals("ds2 should still be on first version", firstVersion,
nd2.getModCount().longValue());
-
- // check uncached version in ds2
- nd2 = super.ds2.find(Collection.NODES, id, 0);
- assertEquals("ds2 should now see the second version", firstVersion +
1, nd2.getModCount().longValue());
-
- // check cached version in ds2 (was the cache refreshed?)
- NodeDocument nd2b = super.ds2.find(Collection.NODES, id);
- assertEquals("ds2 should now see the second version", firstVersion +
1, nd2b.getModCount().longValue());
-
- // update through ds2
- UpdateOp upds2 = new UpdateOp(id, true);
- upds2.set("foo", "blub");
- super.ds2.update(Collection.NODES, Collections.singletonList(id),
upds1);
- nd2 = super.ds2.find(Collection.NODES, id);
- assertEquals("modcount should have incremented again", firstVersion +
2, nd2.getModCount().longValue());
-
- long ds1checktime = nd1.getLastCheckTime();
- letTimeElapse();
-
- // try the invalidation
- ds1.invalidateCache();
-
- // ds1 should see the same version even when doing a cached read
- nd1 = super.ds1.find(Collection.NODES, id);
- assertEquals("modcount should have incremented again", firstVersion +
2, nd1.getModCount().longValue());
- assertTrue(nd1.getLastCheckTime() > ds1checktime);
- }
-
- @Test
public void testInterleavedBatchUpdate() {
int amount = 10;
int halfAmount = amount / 2;
@@ -331,158 +226,6 @@ public class MultiDocumentStoreTest exte
assertEquals(1L, foo.get("_ds2"));
}
- @Test
- public void testChangeVisibility() {
- String id = this.getClass().getName() + ".testChangeVisibility";
-
- super.ds1.remove(Collection.NODES, id);
-
- UpdateOp up = new UpdateOp(id, true);
- up.set("_foo", 0);
- up.set("_bar", 0);
- assertTrue(super.ds1.create(Collection.NODES,
Collections.singletonList(up)));
- removeMe.add(id);
- NodeDocument orig = super.ds1.find(Collection.NODES, id);
-
- // only run test if DS supports modcount
- if (orig.getModCount() != null) {
- long origMc = orig.getModCount();
-
- UpdateOp up2 = new UpdateOp(id, false);
- up2.increment("_foo", 1L);
- super.ds2.update(Collection.NODES, Collections.singletonList(id),
up2);
- NodeDocument ds2doc = super.ds2.find(Collection.NODES, id);
- long ds2Mc = ds2doc.getModCount();
- assertTrue("_modCount needs to be > " + origMc + " but was " +
ds2Mc, ds2Mc > origMc);
-
- UpdateOp up1 = new UpdateOp(id, false);
- up1.increment("_bar", 1L);
- super.ds1.update(Collection.NODES, Collections.singletonList(id),
up1);
-
- NodeDocument ds1doc = super.ds1.find(Collection.NODES, id);
- long ds1Mc = ds1doc.getModCount();
- assertTrue("_modCount needs to be > " + ds2Mc + " but was " +
ds1Mc, ds1Mc > ds2Mc);
- }
- }
-
- @Test
- public void concurrentUpdate() throws Exception {
- String id = Utils.getIdFromPath("/foo");
- ds1.remove(Collection.NODES, id);
- ds2.invalidateCache();
- removeMe.add(id);
- UpdateOp op = new UpdateOp(id, true);
- ds1.create(Collection.NODES, Collections.singletonList(op));
-
- List<Exception> exceptions = Collections.synchronizedList(new
ArrayList<Exception>());
- List<Thread> threads = Lists.newArrayList();
- threads.add(new Thread(new Updater(ds1, id, exceptions)));
- threads.add(new Thread(new Updater(ds2, id, exceptions)));
- Reader r = new Reader(id, exceptions, ds1, ds2);
- Thread reader = new Thread(r);
- for (Thread t : threads) {
- t.start();
- }
- reader.start();
- for (Thread t : threads) {
- t.join();
- }
- r.terminate();
- reader.join();
- for (Exception e : exceptions) {
- throw e;
- }
- }
-
- private static final class Reader implements Runnable {
-
- private final String id;
- private final List<Exception> exceptions;
- private final List<DocumentStore> stores;
- private volatile boolean terminate = false;
- private final Map<Long, NodeDocument> docs = Maps.newHashMap();
-
- public Reader(String id, List<Exception> exceptions, DocumentStore...
stores) {
- this.id = id;
- this.exceptions = exceptions;
- this.stores = Lists.newArrayList(stores);
- }
-
- void terminate() {
- terminate = true;
- }
-
- @Override
- public void run() {
- Random random = new Random();
- while (!terminate) {
- try {
- DocumentStore ds =
stores.get(random.nextInt(stores.size()));
- NodeDocument d = ds.find(Collection.NODES, id);
- long modCount = d.getModCount();
- NodeDocument seen = docs.get(modCount);
- if (seen == null) {
- docs.put(modCount, d);
- } else {
- Map<String, Object> expected = getPropertyValues(seen);
- Map<String, Object> actual = getPropertyValues(d);
- assertEquals(expected, actual);
- }
- Thread.sleep(random.nextInt(1));
- } catch (AssertionError e) {
- exceptions.add(new Exception(e.getMessage()));
- break;
- } catch (Exception e) {
- exceptions.add(e);
- break;
- }
- }
- }
-
- static Map<String, Object> getPropertyValues(NodeDocument doc) {
- Map<String, Object> props = Maps.newHashMap();
- for (String k : doc.keySet()) {
- if (Utils.isPropertyName(k)) {
- props.put(k, doc.get(k));
- }
- }
- return props;
- }
- }
-
- private static final class Updater implements Runnable {
-
- private final DocumentStore ds;
- private final String id;
- private final List<Exception> exceptions;
- private long counter = 0;
-
- public Updater(DocumentStore ds, String id, List<Exception>
exceptions) {
- this.ds = ds;
- this.id = id;
- this.exceptions = exceptions;
- }
-
- @Override
- public void run() {
- String p = Thread.currentThread().getName();
- for (int i = 0; i < 1000; i++) {
- UpdateOp op = new UpdateOp(id, false);
- op.set(p, counter++);
- try {
- ds.update(Collection.NODES, Collections.singletonList(id),
op);
- } catch (Exception e) {
- if (ds instanceof RDBDocumentStore
- && e.getMessage().contains("race?")) {
- LOG.warn(e.toString());
- } else {
- exceptions.add(e);
- }
- }
- }
- }
- }
-
private static long letTimeElapse() {
long ts = System.currentTimeMillis();
while (System.currentTimeMillis() == ts) {
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCWithSplitTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCWithSplitTest.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCWithSplitTest.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCWithSplitTest.java
Wed Nov 8 17:55:13 2017
@@ -208,17 +208,6 @@ public class VersionGCWithSplitTest {
this.docStore = base;
}
- @Override
- public <T extends Document> void update(final Collection<T> collection,
- final List<String> keys,
- final UpdateOp updateOp) {
- runLocked(new Runnable() {
- public void run() {
- docStore.update(collection, keys, updateOp);
- }
- });
- }
-
@Nonnull
@Override
public <T extends Document> T createOrUpdate(final Collection<T>
collection,
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
Wed Nov 8 17:55:13 2017
@@ -124,15 +124,5 @@ public class MongoDBExceptionTest {
assertTrue("Exception message does not contain id: '" +
e.getMessage() + "'",
e.getMessage().contains(id));
}
-
- exceptionMsg = "update failed";
- try {
- store.update(Collection.NODES, singletonList(id), op);
- fail("DocumentStoreException expected");
- } catch (DocumentStoreException e) {
- assertTrue(e.getMessage().contains(exceptionMsg));
- assertTrue("Exception message does not contain id: '" +
e.getMessage() + "'",
- e.getMessage().contains(id));
- }
}
}
Modified:
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/ReadOnlyDocumentStoreWrapperTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/ReadOnlyDocumentStoreWrapperTest.java?rev=1814608&r1=1814607&r2=1814608&view=diff
==============================================================================
---
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/ReadOnlyDocumentStoreWrapperTest.java
(original)
+++
jackrabbit/oak/branches/1.6/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/ReadOnlyDocumentStoreWrapperTest.java
Wed Nov 8 17:55:13 2017
@@ -1,195 +1,186 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.jackrabbit.oak.plugins.document.util;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import org.apache.jackrabbit.oak.plugins.document.Collection;
-import org.apache.jackrabbit.oak.plugins.document.Document;
-import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
-import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
-import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
-import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
-import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
-import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
-import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class ReadOnlyDocumentStoreWrapperTest {
- @Rule
- public DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
-
- @Test
- public void testPassthrough() throws NoSuchMethodException,
InvocationTargetException, IllegalAccessException {
- final List<String> disallowedMethods = Lists.newArrayList(
- "create", "update", "remove", "createOrUpdate",
"findAndUpdate");
- InvocationHandler handler = new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
- String methodName = method.getName();
-
- if (disallowedMethods.contains(methodName)) {
- Assert.fail(String.format("Invalid passthrough of method
(%s) with params %s", method, Arrays.toString(args)));
- }
-
- if ("determineServerTimeDifferenceMillis".equals(methodName)) {
- return new Long(0);
- } else {
- return null;
- }
- }
- };
- DocumentStore proxyStore =
(DocumentStore)Proxy.newProxyInstance(DocumentStore.class.getClassLoader(),
- new Class[]{DocumentStore.class},
- handler);
-
- DocumentStore readOnlyStore =
ReadOnlyDocumentStoreWrapperFactory.getInstance(proxyStore);
-
- Collection<? extends Document> []collections = new Collection[] {
- Collection.CLUSTER_NODES, Collection.JOURNAL,
Collection.NODES, Collection.SETTINGS
- };
- for (Collection collection : collections) {
- readOnlyStore.find(collection, null);
- readOnlyStore.find(collection, null, 0);
-
- readOnlyStore.query(collection, null, null, 0);
- readOnlyStore.query(collection, null, null, null, 0, 0);
-
- boolean uoeThrown = false;
- try {
- readOnlyStore.remove(collection, "");
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("remove must throw UnsupportedOperationException",
uoeThrown);
-
- uoeThrown = false;
- try {
- readOnlyStore.remove(collection, Lists.<String>newArrayList());
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("remove must throw UnsupportedOperationException",
uoeThrown);
-
- uoeThrown = false;
- try {
- readOnlyStore.remove(collection, Maps.<String,
Map<UpdateOp.Key, UpdateOp.Condition>>newHashMap());
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("remove must throw UnsupportedOperationException",
uoeThrown);
- uoeThrown = false;
-
- try {
- readOnlyStore.create(collection, null);
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("create must throw UnsupportedOperationException",
uoeThrown);
- uoeThrown = false;
-
- try {
- readOnlyStore.update(collection, null, null);
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("update must throw UnsupportedOperationException",
uoeThrown);
- uoeThrown = false;
-
- try {
- readOnlyStore.createOrUpdate(collection, (UpdateOp) null);
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("createOrUpdate must throw
UnsupportedOperationException", uoeThrown);
- uoeThrown = false;
-
- try {
- readOnlyStore.createOrUpdate(collection,
Lists.<UpdateOp>newArrayList());
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("createOrUpdate must throw
UnsupportedOperationException", uoeThrown);
- uoeThrown = false;
-
- try {
- readOnlyStore.findAndUpdate(collection, null);
- } catch (UnsupportedOperationException uoe) {
- //catch uoe thrown by read only wrapper
- uoeThrown = true;
- }
- assertTrue("findAndUpdate must throw
UnsupportedOperationException", uoeThrown);
-
- readOnlyStore.invalidateCache(collection, null);
- readOnlyStore.getIfCached(collection, null);
- }
-
- readOnlyStore.invalidateCache();
- readOnlyStore.invalidateCache(null);
-
- readOnlyStore.dispose();
- readOnlyStore.setReadWriteMode(null);
- readOnlyStore.getCacheStats();
- readOnlyStore.getMetadata();
- readOnlyStore.determineServerTimeDifferenceMillis();
- }
-
- @Test
- public void backgroundRead() throws Exception {
- DocumentStore docStore = new MemoryDocumentStore();
-
- DocumentNodeStore store = builderProvider.newBuilder().setAsyncDelay(0)
- .setDocumentStore(docStore).setClusterId(2).getNodeStore();
- DocumentNodeStore readOnlyStore =
builderProvider.newBuilder().setAsyncDelay(0)
-
.setDocumentStore(docStore).setClusterId(1).setReadOnlyMode().getNodeStore();
-
- NodeBuilder builder = store.getRoot().builder();
- builder.child("node");
- store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
-
- store.runBackgroundOperations();
-
- // at this point node must not be visible
- assertFalse(readOnlyStore.getRoot().hasChildNode("node"));
-
- readOnlyStore.runBackgroundOperations();
-
- // at this point node should get visible
- assertTrue(readOnlyStore.getRoot().hasChildNode("node"));
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.jackrabbit.oak.plugins.document.util;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.jackrabbit.oak.plugins.document.Collection;
+import org.apache.jackrabbit.oak.plugins.document.Document;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
+import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class ReadOnlyDocumentStoreWrapperTest {
+ @Rule
+ public DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
+
+ @Test
+ public void testPassthrough() throws NoSuchMethodException,
InvocationTargetException, IllegalAccessException {
+ final List<String> disallowedMethods = Lists.newArrayList(
+ "create", "update", "remove", "createOrUpdate",
"findAndUpdate");
+ InvocationHandler handler = new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
+ String methodName = method.getName();
+
+ if (disallowedMethods.contains(methodName)) {
+ Assert.fail(String.format("Invalid passthrough of method
(%s) with params %s", method, Arrays.toString(args)));
+ }
+
+ if ("determineServerTimeDifferenceMillis".equals(methodName)) {
+ return new Long(0);
+ } else {
+ return null;
+ }
+ }
+ };
+ DocumentStore proxyStore =
(DocumentStore)Proxy.newProxyInstance(DocumentStore.class.getClassLoader(),
+ new Class[]{DocumentStore.class},
+ handler);
+
+ DocumentStore readOnlyStore =
ReadOnlyDocumentStoreWrapperFactory.getInstance(proxyStore);
+
+ Collection<? extends Document> []collections = new Collection[] {
+ Collection.CLUSTER_NODES, Collection.JOURNAL,
Collection.NODES, Collection.SETTINGS
+ };
+ for (Collection collection : collections) {
+ readOnlyStore.find(collection, null);
+ readOnlyStore.find(collection, null, 0);
+
+ readOnlyStore.query(collection, null, null, 0);
+ readOnlyStore.query(collection, null, null, null, 0, 0);
+
+ boolean uoeThrown = false;
+ try {
+ readOnlyStore.remove(collection, "");
+ } catch (UnsupportedOperationException uoe) {
+ //catch uoe thrown by read only wrapper
+ uoeThrown = true;
+ }
+ assertTrue("remove must throw UnsupportedOperationException",
uoeThrown);
+
+ uoeThrown = false;
+ try {
+ readOnlyStore.remove(collection, Lists.<String>newArrayList());
+ } catch (UnsupportedOperationException uoe) {
+ //catch uoe thrown by read only wrapper
+ uoeThrown = true;
+ }
+ assertTrue("remove must throw UnsupportedOperationException",
uoeThrown);
+
+ uoeThrown = false;
+ try {
+ readOnlyStore.remove(collection, Maps.<String,
Map<UpdateOp.Key, UpdateOp.Condition>>newHashMap());
+ } catch (UnsupportedOperationException uoe) {
+ //catch uoe thrown by read only wrapper
+ uoeThrown = true;
+ }
+ assertTrue("remove must throw UnsupportedOperationException",
uoeThrown);
+ uoeThrown = false;
+
+ try {
+ readOnlyStore.create(collection, null);
+ } catch (UnsupportedOperationException uoe) {
+ //catch uoe thrown by read only wrapper
+ uoeThrown = true;
+ }
+ assertTrue("create must throw UnsupportedOperationException",
uoeThrown);
+ uoeThrown = false;
+
+ try {
+ readOnlyStore.createOrUpdate(collection, (UpdateOp) null);
+ } catch (UnsupportedOperationException uoe) {
+ //catch uoe thrown by read only wrapper
+ uoeThrown = true;
+ }
+ assertTrue("createOrUpdate must throw
UnsupportedOperationException", uoeThrown);
+ uoeThrown = false;
+
+ try {
+ readOnlyStore.createOrUpdate(collection,
Lists.<UpdateOp>newArrayList());
+ } catch (UnsupportedOperationException uoe) {
+ //catch uoe thrown by read only wrapper
+ uoeThrown = true;
+ }
+ assertTrue("createOrUpdate must throw
UnsupportedOperationException", uoeThrown);
+ uoeThrown = false;
+
+ try {
+ readOnlyStore.findAndUpdate(collection, null);
+ } catch (UnsupportedOperationException uoe) {
+ //catch uoe thrown by read only wrapper
+ uoeThrown = true;
+ }
+ assertTrue("findAndUpdate must throw
UnsupportedOperationException", uoeThrown);
+
+ readOnlyStore.invalidateCache(collection, null);
+ readOnlyStore.getIfCached(collection, null);
+ }
+
+ readOnlyStore.invalidateCache();
+ readOnlyStore.invalidateCache(null);
+
+ readOnlyStore.dispose();
+ readOnlyStore.setReadWriteMode(null);
+ readOnlyStore.getCacheStats();
+ readOnlyStore.getMetadata();
+ readOnlyStore.determineServerTimeDifferenceMillis();
+ }
+
+ @Test
+ public void backgroundRead() throws Exception {
+ DocumentStore docStore = new MemoryDocumentStore();
+
+ DocumentNodeStore store = builderProvider.newBuilder().setAsyncDelay(0)
+ .setDocumentStore(docStore).setClusterId(2).getNodeStore();
+ DocumentNodeStore readOnlyStore =
builderProvider.newBuilder().setAsyncDelay(0)
+
.setDocumentStore(docStore).setClusterId(1).setReadOnlyMode().getNodeStore();
+
+ NodeBuilder builder = store.getRoot().builder();
+ builder.child("node");
+ store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+ store.runBackgroundOperations();
+
+ // at this point node must not be visible
+ assertFalse(readOnlyStore.getRoot().hasChildNode("node"));
+
+ readOnlyStore.runBackgroundOperations();
+
+ // at this point node should get visible
+ assertTrue(readOnlyStore.getRoot().hasChildNode("node"));
+ }
+}