You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2017/12/21 10:14:10 UTC
svn commit: r1818903 -
/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistency2Test.java
Author: mreutegg
Date: Thu Dec 21 10:14:10 2017
New Revision: 1818903
URL: http://svn.apache.org/viewvc?rev=1818903&view=rev
Log:
OAK-7101: Stale documents in RDBDocumentStore cache
Add ignored test again with different name
Added:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistency2Test.java (with props)
Added: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistency2Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistency2Test.java?rev=1818903&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistency2Test.java (added)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistency2Test.java Thu Dec 21 10:14:10 2017
@@ -0,0 +1,126 @@
+/*
+ * 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.rdb;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.sql.DataSource;
+
+import com.google.common.collect.Lists;
+
+import org.apache.jackrabbit.oak.plugins.document.AbstractRDBConnectionTest;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Revision;
+import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
+import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getIdFromPath;
+import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getKeyLowerLimit;
+import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getKeyUpperLimit;
+import static org.junit.Assert.assertEquals;
+
+@Ignore("OAK-7101")
+public class RDBCacheConsistency2Test extends AbstractRDBConnectionTest {
+
+ private static final long CACHE_SIZE = 128 * 1024;
+
+ private static final int NUM_NODES = 50;
+
+ private DocumentStore ds;
+
+ private AtomicLong counter = new AtomicLong();
+
+ @Override
+ protected DocumentMK.Builder newBuilder(DataSource db) throws Exception {
+ String prefix = "T" + Long.toHexString(System.currentTimeMillis());
+ RDBOptions opt = new RDBOptions().tablePrefix(prefix).dropTablesOnClose(true);
+ return new DocumentMK.Builder().clock(getTestClock())
+ .memoryCacheSize(CACHE_SIZE).setLeaseCheck(false)
+ .setRDBConnection(dataSource, opt);
+ }
+
+ @Before
+ public void before() {
+ ds = mk.getDocumentStore();
+ }
+
+ /**
+ * Perform concurrent update and query operations and check if the document
+ * cache is consistent afterwards. See OAK-7101.
+ */
+ @Test
+ public void cacheUpdate() throws Exception {
+ Revision r = newRevision();
+ for (int i = 0; i < NUM_NODES; i++) {
+ String id = Utils.getIdFromPath("/node-" + i);
+ UpdateOp op = new UpdateOp(id, true);
+ NodeDocument.setLastRev(op, r);
+ }
+
+ for (int i = 0; i < 1000; i++) {
+ Thread q = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ queryDocuments();
+ }
+ });
+ Thread u = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ updateDocuments();
+ }
+ });
+ q.start();
+ u.start();
+ q.join();
+ u.join();
+ for (int j = 0; j < NUM_NODES; j++) {
+ NodeDocument doc = ds.getIfCached(NODES, Utils.getIdFromPath("/node-" + j));
+ if (doc != null) {
+ assertEquals("Unexpected revision timestamp for " + doc.getId(),
+ counter.get(), doc.getLastRev().get(1).getTimestamp());
+ }
+ }
+ }
+ }
+
+ private Revision newRevision() {
+ return new Revision(counter.incrementAndGet(), 0, 1);
+ }
+
+ private void queryDocuments() {
+ ds.query(NODES, getKeyLowerLimit("/"), getKeyUpperLimit("/"), 100);
+ }
+
+ private void updateDocuments() {
+ UpdateOp op = new UpdateOp("foo", false);
+ Revision r = newRevision();
+ NodeDocument.setLastRev(op, r);
+ List<UpdateOp> ops = Lists.newArrayList();
+ for (int i = 0; i < NUM_NODES; i++) {
+ ops.add(op.shallowCopy(getIdFromPath("/node-" + i)));
+ }
+ ds.createOrUpdate(NODES, ops);
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBCacheConsistency2Test.java
------------------------------------------------------------------------------
svn:eol-style = native