Merged 5.0.N (5.0.3) to HEAD (5.1/Cloud)

108512: Merged DEV to 5.0.N (5.0.3)
      107232: MNT-14195 : Replication Jobs: An error is thrown every time that a scheduled job should be run if it was disabled
      108319: MNT-14195 : Replication Jobs: An error is thrown every time that a scheduled job should be run if it was disabled
         - added tests


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@108535 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-07-18 08:45:23 +00:00
parent 6d2b4d29a7
commit 9441ab7bd9
3 changed files with 67 additions and 13 deletions

View File

@@ -35,6 +35,7 @@ import org.alfresco.repo.transfer.ContentClassFilter;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionTrackingService; import org.alfresco.service.cmr.action.ActionTrackingService;
import org.alfresco.service.cmr.action.ParameterDefinition; 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.ReplicationDefinition;
import org.alfresco.service.cmr.replication.ReplicationServiceException; import org.alfresco.service.cmr.replication.ReplicationServiceException;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -270,7 +271,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
} }
if(!replicationDef.isEnabled()) 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()) if(!replicationParams.isEnabled())
{ {
@@ -373,7 +374,7 @@ public class ReplicationActionExecutor extends ActionExecuterAbstractBase {
@Override @Override
public boolean onLogException(Log logger, Throwable t, String message) public boolean onLogException(Log logger, Throwable t, String message)
{ {
if(t instanceof ActionCancelledException) if(t instanceof ActionCancelledException || t instanceof DisabledReplicationJobException)
{ {
logger.debug(message); logger.debug(message);
return true; return true;

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

View File

@@ -33,6 +33,7 @@ import junit.framework.TestCase;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl; import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.action.RuntimeActionService;
import org.alfresco.repo.jscript.ClasspathScriptLocation; import org.alfresco.repo.jscript.ClasspathScriptLocation;
import org.alfresco.repo.lock.JobLockService; import org.alfresco.repo.lock.JobLockService;
import org.alfresco.repo.model.Repository; 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.action.scheduled.SchedulableAction.IntervalPeriod;
import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.UnableToReleaseLockException; 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.ReplicationDefinition;
import org.alfresco.service.cmr.replication.ReplicationService; import org.alfresco.service.cmr.replication.ReplicationService;
import org.alfresco.service.cmr.replication.ReplicationServiceException; 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.ApplicationContextHelper;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.alfresco.util.Pair; 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.junit.experimental.categories.Category;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
@@ -91,6 +95,8 @@ public class ReplicationServiceIntegrationTest extends TestCase
{ {
private static ConfigurableApplicationContext ctx = private static ConfigurableApplicationContext ctx =
(ConfigurableApplicationContext)ApplicationContextHelper.getApplicationContext(); (ConfigurableApplicationContext)ApplicationContextHelper.getApplicationContext();
private static final Log log = LogFactory.getLog(ReplicationServiceIntegrationTest.class);
private ReplicationActionExecutor replicationActionExecutor; private ReplicationActionExecutor replicationActionExecutor;
private ReplicationService replicationService; private ReplicationService replicationService;
@@ -553,17 +559,6 @@ public class ReplicationServiceIntegrationTest extends TestCase
} catch(ReplicationServiceException e) {} } catch(ReplicationServiceException e) {}
txn.rollback(); 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 // Invalid Transfer Target, not allowed
rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test"); rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
@@ -627,6 +622,29 @@ public class ReplicationServiceIntegrationTest extends TestCase
actionService.executeAction(rd2, replicationRoot); actionService.executeAction(rd2, replicationRoot);
txn.commit(); 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 // Schedule it for 0.5 seconds into the future
// Ensure that it is run to completion // Ensure that it is run to completion