jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1378004 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/cluster/ main/java/org/apache/jackrabbit/core/state/ test/java/org/apache/jackrabbit/core/cluster/ test/resources/org/apache/jackrabbit/core/cluster/
Date Tue, 28 Aug 2012 07:22:58 GMT
Author: mreutegg
Date: Tue Aug 28 07:22:58 2012
New Revision: 1378004

URL: http://svn.apache.org/viewvc?rev=1378004&view=rev
Log:
JCR-3417: Failed Journal lock not propagated

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml
      - copied, changed from r1377607, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-h2.xml
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=1378004&r1=1378003&r2=1378004&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Tue Aug 28 07:22:58 2012
@@ -605,7 +605,7 @@ public class ClusterNode implements Runn
         /**
          * {@inheritDoc}
          */
-        public void updateCreated(Update update) {
+        public void updateCreated(Update update) throws ClusterException {
             if (status != STARTED) {
                 log.info("not started: update create ignored.");
                 return;
@@ -614,11 +614,12 @@ public class ClusterNode implements Runn
                 Record record = producer.append();
                 update.setAttribute(ATTRIBUTE_RECORD, record);
             } catch (JournalException e) {
-                String msg = "Unable to create log entry.";
-                log.error(msg, e);
+                String msg = "Unable to create log entry: " + e.getMessage();
+                throw new ClusterException(msg, e);
             } catch (Throwable e) {
-                String msg = "Unexpected error while creating log entry.";
-                log.error(msg, e);
+                String msg = "Unexpected error while creating log entry: "
+                        + e.getMessage();
+                throw new ClusterException(msg, e);
             }
         }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java?rev=1378004&r1=1378003&r2=1378004&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java
Tue Aug 28 07:22:58 2012
@@ -25,8 +25,9 @@ public interface UpdateEventChannel {
      * Called when an a update operation has been created.
      *
      * @param update update operation
+     * @throws ClusterException if an error occurs writing to the event channel.
      */
-    void updateCreated(Update update);
+    void updateCreated(Update update) throws ClusterException;
 
     /**
      * Called when an a update operation has been prepared.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=1378004&r1=1378003&r2=1378004&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Tue Aug 28 07:22:58 2012
@@ -27,6 +27,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 
 import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.cluster.ClusterException;
 import org.apache.jackrabbit.core.cluster.UpdateEventChannel;
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeId;
@@ -567,7 +568,11 @@ public class SharedItemStateManager
             virtualNodeReferences = new ChangeLog[virtualProviders.length];
 
             // let listener know about change
-            eventChannel.updateCreated(this);
+            try {
+                eventChannel.updateCreated(this);
+            } catch (ClusterException e) {
+                throw new ItemStateException(e.getMessage(), e);
+            }
 
             try {
                 writeLock = acquireWriteLock(local);

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java?rev=1378004&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
Tue Aug 28 07:22:58 2012
@@ -0,0 +1,86 @@
+/*
+ * 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.core.cluster;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.test.JUnitTest;
+
+/**
+ * <code>FailUpdateOnJournalExceptionTest</code> checks if
+ * UpdateEventChannel.updateCreated(Update) throws a ClusterException
+ * when locking the Journal fails. See JCR-3417
+ */
+public class FailUpdateOnJournalExceptionTest extends JUnitTest {
+
+    private RepositoryImpl repo;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        deleteAll();
+        FileUtils.copyInputStreamToFile(
+                getClass().getResourceAsStream("repository-with-test-journal.xml"),
+                new File(getTestDir(), "repository.xml"));
+        repo = RepositoryImpl.create(RepositoryConfig.create(getTestDir()));
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (repo != null) {
+            repo.shutdown();
+        }
+        deleteAll();
+        super.tearDown();
+    }
+
+    public void testUpdate() throws Exception {
+        Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
+        Node root = s.getRootNode();
+        root.addNode("foo");
+        s.save();
+        root.addNode("bar");
+        TestJournal.refuseLock = true;
+        try {
+            s.save();
+            fail("Session.save() must fail with RepositoryException when Journal cannot be
locked.");
+        } catch (RepositoryException e) {
+            // expected
+        } finally {
+            TestJournal.refuseLock = false;
+        }
+    }
+
+    private static void deleteAll() throws IOException {
+        FileUtils.deleteDirectory(getTestDir());
+    }
+
+    private static File getTestDir() throws IOException {
+        return new File("target",
+                FailUpdateOnJournalExceptionTest.class.getSimpleName());
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java?rev=1378004&r1=1378003&r2=1378004&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java
Tue Aug 28 07:22:58 2012
@@ -41,6 +41,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(ClusterSyncTest.class);
         suite.addTestSuite(DbClusterTest.class);
         suite.addTestSuite(DbClusterTestJCR3162.class);
+        suite.addTestSuite(FailUpdateOnJournalExceptionTest.class);
 
         return suite;
     }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java?rev=1378004&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
Tue Aug 28 07:22:58 2012
@@ -0,0 +1,38 @@
+/*
+ * 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.core.cluster;
+
+import org.apache.jackrabbit.core.journal.JournalException;
+import org.apache.jackrabbit.core.journal.MemoryJournal;
+
+/**
+* <code>TestJournal</code> extends the MemoryJournal with a static hook to
+* refuse lock acquisition.
+*/
+public final class TestJournal extends MemoryJournal {
+
+    static boolean refuseLock = false;
+
+    @Override
+    protected void doLock() throws JournalException {
+        if (refuseLock) {
+            throw new JournalException("lock refused");
+        } else {
+            super.doLock();
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml
(from r1377607, jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-h2.xml)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml?p2=jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml&p1=jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-h2.xml&r1=1377607&r2=1378004&rev=1378004&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-h2.xml
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml
Tue Aug 28 07:22:58 2012
@@ -158,14 +158,7 @@
         Cluster configuration with system variables.
     -->
     <Cluster>
-        <Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal">
-            <param name="driver" value="org.h2.Driver" />
-            <param name="url" value="jdbc:h2:${rep.home}/../db"/>
-            <param name="schemaObjectPrefix" value="journal_"/>
-            <param name="databaseType" value="h2"/>
-            <param name="user" value="sa"/>
-            <param name="password" value="sa"/>
-        </Journal>
+        <Journal class="org.apache.jackrabbit.core.cluster.TestJournal"/>
     </Cluster>
     
 </Repository>



Mime
View raw message