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 re...@apache.org on 2016/02/01 15:22:10 UTC

svn commit: r1727941 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/rdb/ test/java/org/apache/jackrabbit/oak/plugins/document/ test/java/org/apache/jackrabbit/oak/plugins/document/rdb/

Author: reschke
Date: Mon Feb  1 14:22:09 2016
New Revision: 1727941

URL: http://svn.apache.org/viewvc?rev=1727941&view=rev
Log:
OAK-3938: Occasional failure in MultiDocumentStoreTest.batchUpdateCachedDocument()

Enable existing test, add new test, disable bulk updates for Oracle for now

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBCTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1727941&r1=1727940&r2=1727941&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Mon Feb  1 14:22:09 2016
@@ -297,7 +297,8 @@ public class RDBDocumentStore implements
 
     @Override
     public <T extends Document> List<T> createOrUpdate(Collection<T> collection, List<UpdateOp> updateOps) {
-        if (!BATCHUPDATES) {
+        if (!BATCHUPDATES
+                || dbInfo == RDBDocumentStoreDB.ORACLE /* see OAK-3938 */) {
             List<T> results = new ArrayList<T>(updateOps.size());
             for (UpdateOp update : updateOps) {
                 results.add(createOrUpdate(collection, update));
@@ -1500,7 +1501,7 @@ public class RDBDocumentStore implements
     }
 
     @Nonnull
-    private <T extends Document> RDBTableMetaData getTable(Collection<T> collection) {
+    protected <T extends Document> RDBTableMetaData getTable(Collection<T> collection) {
         RDBTableMetaData tmd = this.tableMeta.get(collection);
         if (tmd != null) {
             return tmd;

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java?rev=1727941&r1=1727940&r2=1727941&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MultiDocumentStoreTest.java Mon Feb  1 14:22:09 2016
@@ -297,8 +297,6 @@ public class MultiDocumentStoreTest exte
 
     @Test
     public void batchUpdateCachedDocument() throws Exception {
-        // OAK-3938
-        assumeTrue(dsf == DocumentStoreFixture.MONGO);
         String id = Utils.getIdFromPath("/foo");
         removeMe.add(id);
 

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBCTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBCTest.java?rev=1727941&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBCTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBCTest.java Mon Feb  1 14:22:09 2016
@@ -0,0 +1,114 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.UnsupportedEncodingException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest;
+import org.apache.jackrabbit.oak.plugins.document.Collection;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
+import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture;
+import org.junit.Test;
+
+/**
+ * Tests checking certain JDBC related features.
+ */
+public class RDBDocumentStoreJDBCTest extends AbstractDocumentStoreTest {
+
+    public RDBDocumentStoreJDBCTest(DocumentStoreFixture dsf) {
+        super(dsf);
+        assumeTrue(super.rdbDataSource != null);
+    }
+
+    @Test
+    public void batchUpdateResult() throws SQLException {
+
+        // https://issues.apache.org/jira/browse/OAK-3938
+        assumeTrue(super.dsf != DocumentStoreFixture.RDB_ORACLE);
+
+        String table = ((RDBDocumentStore)super.ds).getTable(Collection.NODES).getName();
+
+        Connection con = super.rdbDataSource.getConnection();
+        con.setReadOnly(false);
+        try {
+            PreparedStatement st = con.prepareStatement("DELETE FROM " + table + " WHERE ID in (?, ?, ?)");
+            setIdInStatement(st, 1, "key-1");
+            setIdInStatement(st, 2, "key-2");
+            setIdInStatement(st, 3, "key-3");
+            st.executeUpdate();
+            st.close();
+            con.commit();
+
+            st = con.prepareStatement("INSERT INTO " + table + " (id) VALUES (?)");
+            setIdInStatement(st, 1, "key-3");
+            st.executeUpdate();
+            st.close();
+            con.commit();
+
+            removeMe.add("key-3");
+
+            PreparedStatement batchSt = con.prepareStatement("UPDATE " + table + " SET data = '{}' WHERE id = ?");
+            setIdInStatement(batchSt, 1, "key-1");
+            batchSt.addBatch();
+
+            setIdInStatement(batchSt, 1, "key-2");
+            batchSt.addBatch();
+
+            setIdInStatement(batchSt, 1, "key-3");
+            batchSt.addBatch();
+
+            int[] batchResult = batchSt.executeBatch();
+            batchSt.close();
+            con.commit();
+
+            // System.out.println(super.dsname + " " + Arrays.toString(batchResult));
+
+            assertEquals(3, batchResult.length);
+            assertFalse("Row was updated although not present, status: " + batchResult[0], isSuccess(batchResult[0]));
+            assertFalse("Row was updated although not present, status: " + batchResult[1], isSuccess(batchResult[1]));
+            assertTrue("Row should be updated correctly.", isSuccess(batchResult[2]));
+        } finally {
+            con.close();
+        }
+    }
+
+    private static boolean isSuccess(int result) {
+        return result == 1 || result == Statement.SUCCESS_NO_INFO;
+    }
+
+    private void setIdInStatement(PreparedStatement stmt, int idx, String id) throws SQLException {
+        boolean binaryId = ((RDBDocumentStore)super.ds).getTable(Collection.NODES).isIdBinary();
+        if (binaryId) {
+            try {
+                stmt.setBytes(idx, id.getBytes("UTF-8"));
+            } catch (UnsupportedEncodingException ex) {
+                throw new DocumentStoreException(ex);
+            }
+        } else {
+            stmt.setString(idx, id);
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBCTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBCTest.java
------------------------------------------------------------------------------
    svn:executable = *