diff --git a/source/java/org/alfresco/repo/replication/ReplicationActionExecutor.java b/source/java/org/alfresco/repo/replication/ReplicationActionExecutor.java index f76430a5bb..ab630389b6 100644 --- a/source/java/org/alfresco/repo/replication/ReplicationActionExecutor.java +++ b/source/java/org/alfresco/repo/replication/ReplicationActionExecutor.java @@ -35,6 +35,7 @@ import org.alfresco.repo.transfer.ContentClassFilter; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionTrackingService; import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.replication.DisabledReplicationJobException; import org.alfresco.service.cmr.replication.ReplicationDefinition; import org.alfresco.service.cmr.replication.ReplicationServiceException; import org.alfresco.service.cmr.repository.NodeRef; @@ -270,7 +271,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase { } if(!replicationDef.isEnabled()) { - throw new ReplicationServiceException(I18NUtil.getMessage(MSG_ERR_REPLICATION_DEF_DISABLED)); + throw new DisabledReplicationJobException(I18NUtil.getMessage(MSG_ERR_REPLICATION_DEF_DISABLED)); } if(!replicationParams.isEnabled()) { @@ -373,7 +374,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase { @Override public boolean onLogException(Log logger, Throwable t, String message) { - if(t instanceof ActionCancelledException) + if(t instanceof ActionCancelledException || t instanceof DisabledReplicationJobException) { logger.debug(message); return true; diff --git a/source/java/org/alfresco/service/cmr/replication/DisabledReplicationJobException.java b/source/java/org/alfresco/service/cmr/replication/DisabledReplicationJobException.java new file mode 100644 index 0000000000..84478bdfaf --- /dev/null +++ b/source/java/org/alfresco/service/cmr/replication/DisabledReplicationJobException.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2005-2015 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.service.cmr.replication; + +public class DisabledReplicationJobException extends ReplicationServiceException +{ + + private static final long serialVersionUID = 1L; + + public DisabledReplicationJobException(String message) + { + super(message); + } + + public DisabledReplicationJobException(String message, Throwable source) + { + super(message, source); + } +} diff --git a/source/test-java/org/alfresco/repo/replication/ReplicationServiceIntegrationTest.java b/source/test-java/org/alfresco/repo/replication/ReplicationServiceIntegrationTest.java index d5adb8ce53..c3c57ad704 100644 --- a/source/test-java/org/alfresco/repo/replication/ReplicationServiceIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/replication/ReplicationServiceIntegrationTest.java @@ -33,6 +33,7 @@ import junit.framework.TestCase; import org.alfresco.model.ContentModel; import org.alfresco.repo.action.ActionImpl; +import org.alfresco.repo.action.RuntimeActionService; import org.alfresco.repo.jscript.ClasspathScriptLocation; import org.alfresco.repo.lock.JobLockService; import org.alfresco.repo.model.Repository; @@ -54,6 +55,7 @@ import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedActionService import org.alfresco.service.cmr.action.scheduled.SchedulableAction.IntervalPeriod; import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.UnableToReleaseLockException; +import org.alfresco.service.cmr.replication.DisabledReplicationJobException; import org.alfresco.service.cmr.replication.ReplicationDefinition; import org.alfresco.service.cmr.replication.ReplicationService; import org.alfresco.service.cmr.replication.ReplicationServiceException; @@ -77,6 +79,8 @@ import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.GUID; import org.alfresco.util.Pair; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.experimental.categories.Category; import org.springframework.context.ConfigurableApplicationContext; @@ -91,6 +95,8 @@ public class ReplicationServiceIntegrationTest extends TestCase { private static ConfigurableApplicationContext ctx = (ConfigurableApplicationContext)ApplicationContextHelper.getApplicationContext(); + private static final Log log = LogFactory.getLog(ReplicationServiceIntegrationTest.class); + private ReplicationActionExecutor replicationActionExecutor; private ReplicationService replicationService; @@ -553,17 +559,6 @@ public class ReplicationServiceIntegrationTest extends TestCase } catch(ReplicationServiceException e) {} txn.rollback(); - // Now disabled, not allowed - assertEquals(true, rd.isEnabled()); - rd.setEnabled(false); - assertEquals(false, rd.isEnabled()); - txn = transactionService.getUserTransaction(); - txn.begin(); - try { - actionService.executeAction(rd, replicationRoot); - fail("Shouldn't be permitted when disabled"); - } catch(ReplicationServiceException e) {} - txn.rollback(); // Invalid Transfer Target, not allowed rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test"); @@ -627,6 +622,29 @@ public class ReplicationServiceIntegrationTest extends TestCase actionService.executeAction(rd2, replicationRoot); txn.commit(); + // Now disabled, not allowed + assertEquals(true, rd.isEnabled()); + rd.setEnabled(false); + assertEquals(false, rd.isEnabled()); + txn = transactionService.getUserTransaction(); + txn.begin(); + try { + actionService.executeAction(rd, replicationRoot); + fail("Shouldn't be permitted when disabled"); + } catch(ReplicationServiceException e) { + //check if throwed exception is of expected type + assertTrue(e instanceof DisabledReplicationJobException); + assertTrue(actionService instanceof RuntimeActionService); + if (actionService instanceof RuntimeActionService){ + RuntimeActionService runtimeActionService = (RuntimeActionService)actionService; + //check if throwed exception is considered handled + assertTrue(runtimeActionService.onLogException(rd, log, e, e.getMessage())); + } + + } + txn.rollback(); + rd.setEnabled(true); + // Schedule it for 0.5 seconds into the future // Ensure that it is run to completion