Index: src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>windows-1252 =================================================================== --- src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java (revision ) +++ src/test/java/org/apache/jackrabbit/core/cluster/TestJournal.java (revision ) @@ -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; + +/** +* TestJournal 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(); + } + } +} Index: src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>windows-1252 =================================================================== --- src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java (revision ) +++ src/test/java/org/apache/jackrabbit/core/cluster/FailUpdateOnJournalExceptionTest.java (revision ) @@ -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; + +/** + * FailUpdateOnJournalExceptionTest 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()); + } + +} Index: src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>windows-1252 =================================================================== --- src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java (revision 1377607) +++ src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java (revision ) @@ -605,7 +605,7 @@ /** * {@inheritDoc} */ - public void updateCreated(Update update) { + public void updateCreated(Update update) throws ClusterException { if (status != STARTED) { log.info("not started: update create ignored."); return; @@ -615,10 +615,10 @@ update.setAttribute(ATTRIBUTE_RECORD, record); } catch (JournalException e) { String msg = "Unable to create log entry."; - log.error(msg, e); + throw new ClusterException(msg, e); } catch (Throwable e) { String msg = "Unexpected error while creating log entry."; - log.error(msg, e); + throw new ClusterException(msg, e); } } Index: src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml (revision ) +++ src/test/resources/org/apache/jackrabbit/core/cluster/repository-with-test-journal.xml (revision ) @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>windows-1252 =================================================================== --- src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java (revision 1377607) +++ src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventChannel.java (revision ) @@ -25,8 +25,9 @@ * 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. Index: src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>windows-1252 =================================================================== --- src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java (revision 1377607) +++ src/test/java/org/apache/jackrabbit/core/cluster/TestAll.java (revision ) @@ -41,6 +41,7 @@ suite.addTestSuite(ClusterSyncTest.class); suite.addTestSuite(DbClusterTest.class); suite.addTestSuite(DbClusterTestJCR3162.class); + suite.addTestSuite(FailUpdateOnJournalExceptionTest.class); return suite; } Index: src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>windows-1252 =================================================================== --- src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java (revision 1377607) +++ src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java (revision ) @@ -27,6 +27,7 @@ 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 @@ virtualNodeReferences = new ChangeLog[virtualProviders.length]; // let listener know about change + try { - eventChannel.updateCreated(this); + eventChannel.updateCreated(this); + } catch (ClusterException e) { + throw new ItemStateException("updateCreated failed", e); + } try { writeLock = acquireWriteLock(local);