mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Unit tests for scheduled replication actions (ALF-4505)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22142 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -32,10 +32,11 @@ import javax.transaction.UserTransaction;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.action.scheduled.ScheduledPersistedActionImpl;
|
import org.alfresco.repo.action.ActionImpl;
|
||||||
import org.alfresco.repo.lock.JobLockService;
|
import org.alfresco.repo.lock.JobLockService;
|
||||||
import org.alfresco.repo.model.Repository;
|
import org.alfresco.repo.model.Repository;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
import org.alfresco.repo.transfer.TransferServiceImpl;
|
import org.alfresco.repo.transfer.TransferServiceImpl;
|
||||||
import org.alfresco.repo.transfer.TransferTransmitter;
|
import org.alfresco.repo.transfer.TransferTransmitter;
|
||||||
import org.alfresco.repo.transfer.UnitTestInProcessTransmitterImpl;
|
import org.alfresco.repo.transfer.UnitTestInProcessTransmitterImpl;
|
||||||
@@ -558,6 +559,40 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
txn.begin();
|
txn.begin();
|
||||||
actionService.executeAction(rd2, replicationRoot);
|
actionService.executeAction(rd2, replicationRoot);
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
||||||
|
|
||||||
|
// Schedule it for 0.5 seconds into the future
|
||||||
|
// Ensure that it is run to completion
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
((ActionImpl)rd2).setExecutionStatus(ActionStatus.New);
|
||||||
|
|
||||||
|
replicationService.enableScheduling(rd2);
|
||||||
|
rd2.setScheduleStart(new Date(System.currentTimeMillis()+500));
|
||||||
|
replicationService.saveReplicationDefinition(rd2);
|
||||||
|
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
|
// Wait for it to run
|
||||||
|
Thread.sleep(2000);
|
||||||
|
for(int i=0; i<100; i++)
|
||||||
|
{
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
rd2 = replicationService.loadReplicationDefinition(ACTION_NAME2);
|
||||||
|
txn.commit();
|
||||||
|
|
||||||
|
if(rd2.getExecutionStatus().equals(ActionStatus.New) ||
|
||||||
|
rd2.getExecutionStatus().equals(ActionStatus.Pending) ||
|
||||||
|
rd2.getExecutionStatus().equals(ActionStatus.Running))
|
||||||
|
{
|
||||||
|
Thread.sleep(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check it worked
|
||||||
|
assertEquals(ActionStatus.Completed, rd2.getExecutionStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -886,13 +921,20 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
assertEquals(true, td.getNodes().contains(content1_1));
|
assertEquals(true, td.getNodes().contains(content1_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private abstract class DoInTransaction implements RetryingTransactionCallback<Void>
|
||||||
|
{
|
||||||
|
protected final ReplicationDefinition replicationDefinition;
|
||||||
|
private DoInTransaction(ReplicationDefinition rd)
|
||||||
|
{
|
||||||
|
this.replicationDefinition = rd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the schedule related parts work properly
|
* Test that the schedule related parts work properly
|
||||||
*/
|
*/
|
||||||
public void testScheduling() throws Exception
|
public void testScheduling() throws Exception
|
||||||
{
|
{
|
||||||
UserTransaction txn = transactionService.getUserTransaction();
|
|
||||||
|
|
||||||
// A new definition doesn't have scheduling
|
// A new definition doesn't have scheduling
|
||||||
ReplicationDefinition rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
|
ReplicationDefinition rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
|
||||||
rd.setTargetName("Target");
|
rd.setTargetName("Target");
|
||||||
@@ -905,10 +947,17 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
// Enable it
|
// Enable it
|
||||||
txn.begin();
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
replicationService.saveReplicationDefinition(rd);
|
new DoInTransaction(rd) {
|
||||||
replicationService.enableScheduling(rd);
|
public Void execute() throws Throwable {
|
||||||
txn.commit();
|
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||||
|
replicationService.enableScheduling(replicationDefinition);
|
||||||
|
assertTrue(replicationDefinition.isSchedulingEnabled());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true
|
||||||
|
);
|
||||||
|
|
||||||
assertTrue(rd.isSchedulingEnabled());
|
assertTrue(rd.isSchedulingEnabled());
|
||||||
|
|
||||||
|
|
||||||
@@ -940,10 +989,14 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
// Save and check
|
// Save and check
|
||||||
assertEquals(true, rd.isSchedulingEnabled());
|
assertEquals(true, rd.isSchedulingEnabled());
|
||||||
|
|
||||||
txn = transactionService.getUserTransaction();
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
txn.begin();
|
new DoInTransaction(rd) {
|
||||||
replicationService.saveReplicationDefinition(rd);
|
public Void execute() throws Throwable {
|
||||||
txn.commit();
|
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true
|
||||||
|
);
|
||||||
|
|
||||||
assertEquals(true, rd.isSchedulingEnabled());
|
assertEquals(true, rd.isSchedulingEnabled());
|
||||||
assertEquals(1, rd.getScheduleStart().getTime());
|
assertEquals(1, rd.getScheduleStart().getTime());
|
||||||
@@ -966,21 +1019,32 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
||||||
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
||||||
|
|
||||||
txn = transactionService.getUserTransaction();
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
txn.begin();
|
new DoInTransaction(rd) {
|
||||||
replicationService.saveReplicationDefinition(rd);
|
public Void execute() throws Throwable {
|
||||||
rd = replicationService.loadReplicationDefinition(ACTION_NAME);
|
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||||
txn.commit();
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true
|
||||||
|
);
|
||||||
|
|
||||||
assertEquals(true, rd.isSchedulingEnabled());
|
assertEquals(true, rd.isSchedulingEnabled());
|
||||||
assertEquals(1, rd.getScheduleStart().getTime());
|
assertEquals(1, rd.getScheduleStart().getTime());
|
||||||
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
||||||
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
||||||
|
|
||||||
|
rd = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||||
|
assertEquals(true, rd.isSchedulingEnabled());
|
||||||
|
assertEquals(1, rd.getScheduleStart().getTime());
|
||||||
|
assertEquals(2, rd.getScheduleIntervalCount().intValue());
|
||||||
|
assertEquals(IntervalPeriod.Hour, rd.getScheduleIntervalPeriod());
|
||||||
|
|
||||||
|
|
||||||
// Re-load and enable is fine
|
// Re-load and enable is fine
|
||||||
rd2 = replicationService.loadReplicationDefinition(ACTION_NAME);
|
rd2 = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||||
|
assertEquals(true, rd2.isSchedulingEnabled());
|
||||||
replicationService.enableScheduling(rd2);
|
replicationService.enableScheduling(rd2);
|
||||||
|
assertEquals(true, rd2.isSchedulingEnabled());
|
||||||
|
|
||||||
|
|
||||||
// Check on the listing methods
|
// Check on the listing methods
|
||||||
@@ -1013,27 +1077,63 @@ public class ReplicationServiceIntegrationTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
// Enable it, and check the scheduled service
|
// Enable it, and check the scheduled service
|
||||||
txn = transactionService.getUserTransaction();
|
final int count = scheduledPersistedActionService.listSchedules().size();
|
||||||
txn.begin();
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
int count = scheduledPersistedActionService.listSchedules().size();
|
new DoInTransaction(rd) {
|
||||||
replicationService.enableScheduling(rd);
|
public Void execute() throws Throwable {
|
||||||
replicationService.saveReplicationDefinition(rd);
|
replicationService.enableScheduling(replicationDefinition);
|
||||||
|
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||||
assertEquals(count+1, scheduledPersistedActionService.listSchedules().size());
|
assertEquals(count+1, scheduledPersistedActionService.listSchedules().size());
|
||||||
txn.commit();
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Delete is, and check the scheduled service
|
// Delete it, and check the scheduled service
|
||||||
txn = transactionService.getUserTransaction();
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
txn.begin();
|
new RetryingTransactionCallback<Void>() {
|
||||||
replicationService.deleteReplicationDefinition(rd);
|
public Void execute() throws Throwable {
|
||||||
|
ReplicationDefinition replicationDefinition;
|
||||||
|
replicationDefinition = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||||
|
replicationService.deleteReplicationDefinition(replicationDefinition);
|
||||||
|
assertEquals(count, scheduledPersistedActionService.listSchedules().size());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true
|
||||||
|
);
|
||||||
assertEquals(count, scheduledPersistedActionService.listSchedules().size());
|
assertEquals(count, scheduledPersistedActionService.listSchedules().size());
|
||||||
txn.commit();
|
|
||||||
|
|
||||||
|
|
||||||
// Ask for it to run scheduled
|
// Ask for it to run scheduled
|
||||||
// Should fire up and then fail due to missing definitions
|
// Should fire up and then fail due to missing definitions
|
||||||
|
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||||
|
new RetryingTransactionCallback<Void>() {
|
||||||
|
public Void execute() throws Throwable {
|
||||||
|
ReplicationDefinition replicationDefinition;
|
||||||
|
replicationDefinition = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
|
||||||
|
replicationService.enableScheduling(replicationDefinition);
|
||||||
|
replicationDefinition.setScheduleStart(new Date(System.currentTimeMillis()+50));
|
||||||
|
replicationService.saveReplicationDefinition(replicationDefinition);
|
||||||
|
assertEquals(ActionStatus.New, replicationDefinition.getExecutionStatus());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, false, true
|
||||||
|
);
|
||||||
|
|
||||||
// TODO
|
// Let it fire up, wait up to 1.5 seconds
|
||||||
|
for(int i=0; i<150; i++)
|
||||||
|
{
|
||||||
|
rd = replicationService.loadReplicationDefinition(ACTION_NAME);
|
||||||
|
if(rd.getExecutionStatus().equals(ActionStatus.Failed))
|
||||||
|
break;
|
||||||
|
if(rd.getExecutionStatus().equals(ActionStatus.Completed))
|
||||||
|
break;
|
||||||
|
Thread.sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should have failed, as missing target + payload
|
||||||
|
assertEquals(ActionStatus.Failed, rd.getExecutionStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user