当前位置: 首页>>代码示例>>Java>>正文


Java ActionStatus类代码示例

本文整理汇总了Java中org.alfresco.service.cmr.action.ActionStatus的典型用法代码示例。如果您正苦于以下问题:Java ActionStatus类的具体用法?Java ActionStatus怎么用?Java ActionStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ActionStatus类属于org.alfresco.service.cmr.action包,在下文中一共展示了ActionStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: populateActionProperties

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/**
 * Populates the action properties from the node reference
 * 
 * @param actionNodeRef the action node reference
 * @param action the action
 */
private void populateActionProperties(NodeRef actionNodeRef, Action action)
{
    Map<QName, Serializable> props = this.nodeService.getProperties(actionNodeRef);

    action.setTitle((String) props.get(ActionModel.PROP_ACTION_TITLE));
    action.setDescription((String) props.get(ActionModel.PROP_ACTION_DESCRIPTION));

    Boolean trackStatusObj = (Boolean) props.get(ActionModel.PROP_TRACK_STATUS);
    action.setTrackStatus(trackStatusObj);              // Allowed to be null

    Boolean executeAsynchObj = (Boolean) props.get(ActionModel.PROP_EXECUTE_ASYNCHRONOUSLY);
    boolean executeAsynch = executeAsynchObj == null ? false : executeAsynchObj.booleanValue();
    action.setExecuteAsynchronously(executeAsynch);

    ((ActionImpl) action).setCreator((String) props.get(ContentModel.PROP_CREATOR));
    ((ActionImpl) action).setCreatedDate((Date) props.get(ContentModel.PROP_CREATED));
    ((ActionImpl) action).setModifier((String) props.get(ContentModel.PROP_MODIFIER));
    ((ActionImpl) action).setModifiedDate((Date) props.get(ContentModel.PROP_MODIFIED));
    
    ((ActionImpl) action).setExecutionStartDate((Date) props.get(ActionModel.PROP_EXECUTION_START_DATE));
    ((ActionImpl) action).setExecutionEndDate((Date) props.get(ActionModel.PROP_EXECUTION_END_DATE));
    ((ActionImpl) action).setExecutionStatus(ActionStatus.valueOf(props.get(ActionModel.PROP_EXECUTION_ACTION_STATUS)));
    ((ActionImpl) action).setExecutionFailureMessage((String) props.get(ActionModel.PROP_EXECUTION_FAILURE_MESSAGE));

    // Get the compensating action
    List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(actionNodeRef, RegexQNamePattern.MATCH_ALL,
                ActionModel.ASSOC_COMPENSATING_ACTION);
    if (assocs.size() != 0)
    {
        Action compensatingAction = createAction(assocs.get(0).getChildRef());
        action.setCompensatingAction(compensatingAction);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:40,代码来源:ActionServiceImpl.java

示例2: recordActionPending

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
public void recordActionPending(ActionImpl action, NodeRef actionedUponNodeRef)
{
    // Set the status
    action.setExecutionStatus(ActionStatus.Pending);

    // Mark it as not having started quite yet
    action.setExecutionStartDate(null);

    // Have it put into the cache, so we can tell it
    // is waiting to be run
    placeActionInCache(action, actionedUponNodeRef);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:13,代码来源:ActionTrackingServiceImpl.java

示例3: recordActionExecuting

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
private void recordActionExecuting(ActionImpl action, NodeRef actionedUponNodeRef)
{
    if (logger.isDebugEnabled() == true)
    {
        logger.debug("Action " + action + " with provisional key " + generateCacheKey(action)
                + " has begun exection");
    }

    // Grab what status it was before
    ActionStatus previousStatus = action.getExecutionStatus();

    // Mark the action as starting
    action.setExecutionStartDate(new Date());
    action.setExecutionStatus(ActionStatus.Running);

    // If it's a synchronous execution, put it into the cache
    if (previousStatus != ActionStatus.Pending)
    {
        placeActionInCache(action, actionedUponNodeRef);
    }
    else
    {
        // If it's async, update the existing cache entry
        String key = generateCacheKey(action);
        ExecutionDetails details = executingActionsCache.get(key);

        // Check it's really there, warn + fix if not
        if (details == null)
        {
            logger.warn("Went to mark the start of execution of " + action + " with key " + key
                    + " but it wasn't in the running actions cache! "
                    + "Your running actions cache is probably too small");
        }

        // Update and save into the cache
        details = buildExecutionDetails(action);
        executingActionsCache.put(key, details);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:40,代码来源:ActionTrackingServiceImpl.java

示例4: testFatallyFailingActions

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/** Failing actions go into the cache, then out */
public void testFatallyFailingActions() throws Exception
{
   Action failedAction = performFailingActionImpl(true, "54321");
   
   assertEquals(ActionStatus.Failed, failedAction.getExecutionStatus());
   assertEquals("Bang!", failedAction.getExecutionFailureMessage());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:9,代码来源:ActionTrackingServiceImplTest.java

示例5: testTransientlyFailingActions

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/** Failing actions go into the cache, then out */
public void testTransientlyFailingActions() throws Exception
{
   Action failedAction = performFailingActionImpl(false, "654321");
   
   assertEquals(ActionStatus.Declined, failedAction.getExecutionStatus());
   assertTrue(failedAction.getExecutionFailureMessage().endsWith("Pop!"));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:9,代码来源:ActionTrackingServiceImplTest.java

示例6: getSummaryFromAction

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/**
 * Returns the ExecutionSummary for the given action if it
 *  is currently executing, or null if it isn't
 */
public static ExecutionSummary getSummaryFromAction(Action action)
{
   // Is it running?
   if(action.getExecutionStatus() == ActionStatus.Running) {
      return WrappedActionTrackingService.buildExecutionSummary(action);
   }
   // Has it been given a execution id?
   // (eg has already finished, but this one was run)
   if( ((ActionImpl)action).getExecutionInstance() != -1 ) {
      return WrappedActionTrackingService.buildExecutionSummary(action);
   }
   // Not running, and hasn't run, we can't help
   return null;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:19,代码来源:AbstractActionWebscript.java

示例7: getExecutionStatus

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
public ActionStatus getExecutionStatus() {
   return executionStatus;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:4,代码来源:ActionImpl.java

示例8: testReplicationExecutionCancelling

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/**
 * Check that cancelling works.
 * Does this by taking a lock on the job, cancelling,
 *  releasing and seeing it abort.
 *  
 * Tests that when we ask for a replication task to be cancelled,
 *  that it starts, cancels, and the status is correctly recorded
 *  for it.
 */
public void testReplicationExecutionCancelling() throws Exception
{
   // We need the test transfer target for this test
   makeTransferTarget();

   // Create a task
   ReplicationDefinition rd = replicationService.createReplicationDefinition(ACTION_NAME, "Test");
   rd.setTargetName(TRANSFER_TARGET);
   rd.getPayload().add(folder1);
   rd.getPayload().add(folder2);
   
   // Get the lock for 2 seconds
   String token = jobLockService.getLock(
         rd.getReplicationQName(),
         2 * 1000,
         1,
         1
   );
   
   // Request it be run async
   UserTransaction txn = transactionService.getUserTransaction();
   txn.begin();
   actionService.executeAction(rd, replicationRoot, false, true);
   assertEquals(ActionStatus.Pending, rd.getExecutionStatus());
   
   assertEquals(false, actionTrackingService.isCancellationRequested(rd));
   actionTrackingService.requestActionCancellation(rd);
   assertEquals(true, actionTrackingService.isCancellationRequested(rd));
   
   txn.commit();

   // Let it get going, will be waiting for the lock
   //  having registered with the action tracking service
   for(int i=0; i<100; i++) {
      // Keep asking for it to be cancelled ASAP
      actionTrackingService.requestActionCancellation(rd);
      
      if(rd.getExecutionStatus().equals(ActionStatus.Running)) {
         // Good, has started up
         // Stop waiting and do the cancel
         break;
      } else {
         // Still pending, wait a bit more
         Thread.sleep(10);
      }
   }

   // Ensure it started, and should shortly stop
   assertEquals(ActionStatus.Running, rd.getExecutionStatus());
   assertEquals(true, actionTrackingService.isCancellationRequested(rd));
   
   // Release our lock, should allow the replication task
   //  to get going and spot the cancel
   jobLockService.releaseLock(token, rd.getReplicationQName());
   
   // Let the main replication task run to cancelled/completed
   // This can take quite some time though...
   for(int i=0; i<10; i++) {
      if(rd.getExecutionStatus() == ActionStatus.Running) {
         Thread.sleep(1000);
      } else {
         // It has finished running, check it
         break;
      }
   }
   
   // Ensure it was cancelled
   assertEquals(null, rd.getExecutionFailureMessage());
   assertNotNull(rd.getLocalTransferReport());
   assertNotNull(rd.getRemoteTransferReport());
   assertEquals(ActionStatus.Cancelled, rd.getExecutionStatus());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:82,代码来源:ReplicationServiceIntegrationTest.java

示例9: testWorkingActions

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/** Working actions go into the cache, then out */
public void testWorkingActions() throws Exception 
{
   final SleepActionExecuter sleepActionExec = 
      (SleepActionExecuter)ctx.getBean(SleepActionExecuter.NAME);
   sleepActionExec.resetTimesExecuted();
   sleepActionExec.setSleepMs(10000);

   // Have it run asynchronously
   UserTransaction txn = transactionService.getUserTransaction();
   txn.begin();
   Action action = createWorkingSleepAction("54321");
   assertNull(action.getExecutionStartDate());
   assertNull(action.getExecutionEndDate());
   assertNull(action.getExecutionFailureMessage());
   assertEquals(ActionStatus.New, action.getExecutionStatus());
   
   String key = ActionTrackingServiceImpl.generateCacheKey(action);
   assertEquals(null, executingActionsCache.get(key));
   
   this.actionService.executeAction(action, this.nodeRef, false, true);
   
   
   // End the transaction. Should allow the async action
   //  to start up, and begin sleeping
   txn.commit();
   Thread.sleep(150);
   
   // The action should now be running 
   // It will have got an execution instance id, so a new key
   key = ActionTrackingServiceImpl.generateCacheKey(action);
   
   
   // Check it's in the cache
   System.out.println("Checking the cache for " + key);
   assertNotNull(executingActionsCache.get(key));
   
   ExecutionSummary s = ActionTrackingServiceImpl.buildExecutionSummary(action);
   ExecutionDetails d = actionTrackingService.getExecutionDetails(s);
   assertNotNull(d.getExecutionSummary());
   assertEquals("sleep-action", d.getActionType());
   assertEquals("54321", d.getActionId());
   assertEquals(1, d.getExecutionInstance());
   assertEquals(null, d.getPersistedActionRef());
   assertNotNull(null, d.getStartedAt());

   
   // Tell it to stop sleeping
   // Then wait for it to finish
   asyncOccurs.awaitExecution(null, sleepActionExec.getExecutingThread(), action.getActionDefinitionName()); 
   
   
   // Ensure it went away again
   assertEquals(ActionStatus.Completed, action.getExecutionStatus());
   assertEquals(null, executingActionsCache.get(key));
   
   d = actionTrackingService.getExecutionDetails(s);
   assertEquals(null, d);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:60,代码来源:ActionTrackingServiceImplTest.java

示例10: performFailingActionImpl

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
private Action performFailingActionImpl(boolean fatalFailure, String actionId) throws Exception
{
    final SleepActionExecuter sleepActionExec = (SleepActionExecuter) ctx.getBean(SleepActionExecuter.NAME);
    sleepActionExec.setSleepMs(10000);

    // Have it run asynchronously
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    Action action = createFailingSleepAction(actionId, fatalFailure);
    assertNull(action.getExecutionStartDate());
    assertNull(action.getExecutionEndDate());
    assertNull(action.getExecutionFailureMessage());
    assertEquals(ActionStatus.New, action.getExecutionStatus());

    String key = ActionTrackingServiceImpl.generateCacheKey(action);
    assertEquals(null, executingActionsCache.get(key));

    this.actionService.executeAction(action, this.nodeRef, false, true);

    // End the transaction. Should allow the async action
    // to be started, and move into its sleeping phase
    txn.commit();
    Thread.sleep(150);

    // Will get an execution instance id, so a new key
    key = ActionTrackingServiceImpl.generateCacheKey(action);

    // Check it's in the cache
    System.out.println("Checking the cache for " + key);
    assertNotNull(executingActionsCache.get(key));

    ExecutionSummary s = ActionTrackingServiceImpl.buildExecutionSummary(action);
    ExecutionDetails d = actionTrackingService.getExecutionDetails(s);
    assertNotNull(d.getExecutionSummary());
    assertEquals("sleep-action", d.getActionType());
    assertEquals(actionId, d.getActionId());
    assertEquals(1, d.getExecutionInstance());
    assertEquals(null, d.getPersistedActionRef());

    // let's be more resilient and try a number of times with a delay
    long start = System.currentTimeMillis();
    int sleepTime = 1000; // 1s
    for (int i = 0; i < 10; i++)
    {
        if (d.getStartedAt() == null)
        {
            Thread.sleep(sleepTime);
            sleepTime += 100; // increase by 100ms
            continue;
        }
        else
        {
            break;
        }
    }
    long end = System.currentTimeMillis();
    assertNotNull("Started at time is null, the action has not yet started after " + (end - start) + "ms",
            d.getStartedAt());

    // Tell it to stop sleeping
    // Then wait for it to finish and go bang
    // (Need to do it by hand, as it won't fire the complete policy
    // as the action has failed)
    sleepActionExec.getExecutingThread().interrupt();
    Thread.sleep(150);

    // Ensure it went away again
    assertEquals(null, executingActionsCache.get(key));

    d = actionTrackingService.getExecutionDetails(s);
    assertEquals(null, d);

    return action;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:75,代码来源:ActionTrackingServiceImplTest.java

示例11: testPendingActions

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/** Ensure that pending actions behave properly */
public void testPendingActions() throws Exception
{
    // New ones won't be in the cache
    Action action = createWorkingSleepAction("1234");
    assertEquals(ActionStatus.New, action.getExecutionStatus());
   
    String key = ActionTrackingServiceImpl.generateCacheKey(action);
    assertEquals(null, executingActionsCache.get(key));
    
   
    // Ask for it to be pending, will go in
    actionTrackingService.recordActionPending(action);
    key = ActionTrackingServiceImpl.generateCacheKey(action);
    assertEquals(ActionStatus.Pending, action.getExecutionStatus());
    assertNotNull(null, executingActionsCache.get(key));
    
    ExecutionSummary s = ActionTrackingServiceImpl.buildExecutionSummary(action);
    ExecutionDetails d = actionTrackingService.getExecutionDetails(s);
    assertNotNull(d.getExecutionSummary());
    assertEquals("sleep-action", d.getActionType());
    assertEquals("1234", d.getActionId());
    assertEquals(1, d.getExecutionInstance());
    assertEquals(null, d.getPersistedActionRef());
    assertNull(null, d.getStartedAt());

    
    // Run it, will stay
    actionTrackingService.recordActionExecuting(action);
    key = ActionTrackingServiceImpl.generateCacheKey(action);
    assertEquals(ActionStatus.Running, action.getExecutionStatus());
    assertNotNull(null, executingActionsCache.get(key));
    
    s = ActionTrackingServiceImpl.buildExecutionSummary(action);
    d = actionTrackingService.getExecutionDetails(s);
    assertNotNull(d.getExecutionSummary());
    assertEquals("sleep-action", d.getActionType());
    assertEquals("1234", d.getActionId());
    assertEquals(1, d.getExecutionInstance());
    assertEquals(null, d.getPersistedActionRef());
    assertNotNull(d.getStartedAt());
   
    
    // Finish, goes
    actionTrackingService.recordActionComplete(action);
    key = ActionTrackingServiceImpl.generateCacheKey(action);
    assertEquals(ActionStatus.Completed, action.getExecutionStatus());
    assertEquals(null, executingActionsCache.get(key));
   
   
    // Put another pending one in
    action = createWorkingSleepAction("1234");
    actionTrackingService.recordActionPending(action);
    key = ActionTrackingServiceImpl.generateCacheKey(action);
    assertEquals(ActionStatus.Pending, action.getExecutionStatus());
    assertNotNull(null, executingActionsCache.get(key));
    
   
    // Remove it by hand
    executingActionsCache.remove(key);
    assertNull(null, executingActionsCache.get(key));
    int instanceId = ((ActionImpl)action).getExecutionInstance();
    
   
    // Run it, will go back in again, ID unchanged
    actionTrackingService.recordActionExecuting(action);
    assertEquals(key, ActionTrackingServiceImpl.generateCacheKey(action));
    assertEquals(instanceId, ((ActionImpl)action).getExecutionInstance());
    
    assertEquals(ActionStatus.Running, action.getExecutionStatus());
    assertNotNull(null, executingActionsCache.get(key));
   
   
    // Finish, will go again
    actionTrackingService.recordActionComplete(action);
    key = ActionTrackingServiceImpl.generateCacheKey(action);
    assertEquals(ActionStatus.Completed, action.getExecutionStatus());
    assertEquals(null, executingActionsCache.get(key));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:80,代码来源:ActionTrackingServiceImplTest.java

示例12: testCancellation

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/** Cancel related */
public void testCancellation() throws Exception
{
    // Ensure we get the right answers checking
    CancellableSleepAction sleepAction1 = (CancellableSleepAction) createWorkingSleepAction(null);
    CancellableSleepAction sleepAction2 = (CancellableSleepAction) createWorkingSleepAction(null);
    actionTrackingService.recordActionExecuting(sleepAction1);
    actionTrackingService.recordActionExecuting(sleepAction2);
    assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction1));
    assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction2));

    // Cancel with the action
    actionTrackingService.requestActionCancellation(sleepAction1);
    assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction1));
    assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction2));

    // Cancel with the summary
    ExecutionSummary s2 = ActionTrackingServiceImpl.buildExecutionSummary(sleepAction2);
    actionTrackingService.requestActionCancellation(s2);
    assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction1));
    assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction2));

    // If the action had gone missing from the cache,
    // then a check will put it back
    CancellableSleepAction sleepAction3 = (CancellableSleepAction) createWorkingSleepAction(null);
    String key3 = ActionTrackingServiceImpl.generateCacheKey(sleepAction3);

    assertNull(executingActionsCache.get(key3));
    assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction3));
    assertNotNull(executingActionsCache.get(key3));

    executingActionsCache.remove(key3);
    assertNull(executingActionsCache.get(key3));
    assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction3));
    assertNotNull(executingActionsCache.get(key3));

    actionTrackingService.requestActionCancellation(sleepAction3);
    assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction3));
    assertNotNull(executingActionsCache.get(key3));

    // Now have one execute and cancel it, ensure it does
    final SleepActionExecuter sleepActionExec = (SleepActionExecuter) ctx.getBean(SleepActionExecuter.NAME);
    sleepActionExec.setSleepMs(10000);

    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();

    executingActionsCache.remove(key3);
    this.actionService.executeAction(sleepAction3, this.nodeRef, false, true);

    // End the transaction. Should allow the async action
    // to be started
    txn.commit();
    Thread.sleep(150);

    // Get the updated key, and check
    key3 = ActionTrackingServiceImpl.generateCacheKey(sleepAction3);
    ExecutionSummary s3 = ActionTrackingServiceImpl.buildExecutionSummary(key3);

    assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction3));
    assertEquals(false, actionTrackingService.getExecutionDetails(s3).isCancelRequested());
    assertNotNull(executingActionsCache.get(key3));

    actionTrackingService.requestActionCancellation(sleepAction3);

    assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction3));
    assertEquals(true, actionTrackingService.getExecutionDetails(s3).isCancelRequested());
    assertNotNull(executingActionsCache.get(key3));

    // Have it finish sleeping, will have been cancelled
    // (Can't use the policy, as cancel is counted as a failure)
    sleepActionExec.getExecutingThread().interrupt();
    Thread.sleep(150);

    // Ensure the proper cancelled tracking
    assertEquals(ActionStatus.Cancelled, sleepAction3.getExecutionStatus());
    assertEquals(null, sleepAction3.getExecutionFailureMessage());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:79,代码来源:ActionTrackingServiceImplTest.java

示例13: testJavascriptAPI

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
public void testJavascriptAPI() throws Exception
{
    // We need a background action to sleep for long enough for
    // it still to be running when the JS fires off
    final SleepActionExecuter sleepActionExec = (SleepActionExecuter) ctx.getBean(SleepActionExecuter.NAME);
    sleepActionExec.setSleepMs(2000);

    ActionImpl sleepAction;
    ActionImpl action;

    // Create three test actions:
    ((ActionTrackingServiceImpl) actionTrackingService).resetNextExecutionId();

    // Sleep one that will still be running
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    sleepAction = (ActionImpl) createWorkingSleepAction(null);
    sleepAction.setNodeRef(nodeRef); // This isn't true!
    this.actionService.executeAction(sleepAction, null, false, true);
    txn.commit();

    // Move one that will appear to be "running"
    action = (ActionImpl) createFailingMoveAction();
    actionTrackingService.recordActionExecuting(action);

    // Finally one that has "failed"
    // (Shouldn't show up in any lists)
    txn = transactionService.getUserTransaction();
    txn.begin();
    action = (ActionImpl) createWorkingSleepAction(null);
    action.setExecutionStartDate(new Date(1234));
    action.setExecutionEndDate(new Date(54321));
    action.setExecutionStatus(ActionStatus.Failed);
    this.actionService.saveAction(this.nodeRef, action);
    txn.commit();

    // Call the test
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("NodeRef", nodeRef.toString());
    model.put("SleepAction", sleepAction);

    ScriptLocation location = new ClasspathScriptLocation(
            "org/alfresco/repo/action/script/test_actionTrackingService.js");
    this.scriptService.executeScript(location, model);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:46,代码来源:ActionTrackingServiceImplTest.java

示例14: performFailingActionImpl

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
private Action performFailingActionImpl(boolean fatalFailure, String actionId) throws Exception
{
    final SleepActionExecuter sleepActionExec = 
          (SleepActionExecuter)ctx.getBean(SleepActionExecuter.NAME);
       sleepActionExec.setSleepMs(10000);

       // Have it run asynchronously
       UserTransaction txn = transactionService.getUserTransaction();
       txn.begin();
       Action action = createFailingSleepAction(actionId, fatalFailure);
       assertNull(action.getExecutionStartDate());
       assertNull(action.getExecutionEndDate());
       assertNull(action.getExecutionFailureMessage());
       assertEquals(ActionStatus.New, action.getExecutionStatus());
       
       String key = ActionTrackingServiceImpl.generateCacheKey(action);
       assertEquals(null, executingActionsCache.get(key));
       
       this.actionService.executeAction(action, this.nodeRef, false, true);
       
       
       // End the transaction. Should allow the async action
       //  to be started, and move into its sleeping phase
       txn.commit();
       Thread.sleep(150);
       
       
       // Will get an execution instance id, so a new key
       key = ActionTrackingServiceImpl.generateCacheKey(action);
       
       
       // Check it's in the cache
       System.out.println("Checking the cache for " + key);
       assertNotNull(executingActionsCache.get(key));
       
       ExecutionSummary s = ActionTrackingServiceImpl.buildExecutionSummary(action);
       ExecutionDetails d = actionTrackingService.getExecutionDetails(s);
       assertNotNull(d.getExecutionSummary());
       assertEquals("sleep-action", d.getActionType());
       assertEquals(actionId, d.getActionId());
       assertEquals(1, d.getExecutionInstance());
       assertEquals(null, d.getPersistedActionRef());

       // let's be more resilient and try a number of times with a delay
       long start = System.currentTimeMillis();
       int sleepTime = 1000; // 1s
       for(int i = 0; i < 10; i++)
       {
           if(d.getStartedAt() == null)
           {
               Thread.sleep(sleepTime);
               sleepTime += 100; // increase by 100ms
               continue;
           }
           else
           {
               break;
           }
       }
       long end = System.currentTimeMillis();
       assertNotNull("Started at time is null, the action has not yet started after " + (end - start) + "ms",
               d.getStartedAt());

       // Tell it to stop sleeping
       // Then wait for it to finish and go bang
       // (Need to do it by hand, as it won't fire the complete policy
       //  as the action has failed)
       sleepActionExec.getExecutingThread().interrupt();
       Thread.sleep(150);
       
       
       // Ensure it went away again
       assertEquals(null, executingActionsCache.get(key));
       
       d = actionTrackingService.getExecutionDetails(s);
       assertEquals(null, d);
       
       return action;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:80,代码来源:ActionTrackingServiceImplTest.java

示例15: testCancellation

import org.alfresco.service.cmr.action.ActionStatus; //导入依赖的package包/类
/** Cancel related */
public void testCancellation() throws Exception {
   // Ensure we get the right answers checking
   CancellableSleepAction sleepAction1 = (CancellableSleepAction)createWorkingSleepAction(null);
   CancellableSleepAction sleepAction2 = (CancellableSleepAction)createWorkingSleepAction(null);
   actionTrackingService.recordActionExecuting(sleepAction1);
   actionTrackingService.recordActionExecuting(sleepAction2);
   assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction1));
   assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction2));

   // Cancel with the action
   actionTrackingService.requestActionCancellation(sleepAction1);
   assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction1));
   assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction2));
   
   // Cancel with the summary
   ExecutionSummary s2 = ActionTrackingServiceImpl.buildExecutionSummary(sleepAction2);
   actionTrackingService.requestActionCancellation(s2);
   assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction1));
   assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction2));
   
   
   // If the action had gone missing from the cache,
   //  then a check will put it back
   CancellableSleepAction sleepAction3 = (CancellableSleepAction)createWorkingSleepAction(null);
   String key3 = ActionTrackingServiceImpl.generateCacheKey(sleepAction3);
   
   assertNull(executingActionsCache.get(key3));
   assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction3));
   assertNotNull(executingActionsCache.get(key3));
   
   executingActionsCache.remove(key3);
   assertNull(executingActionsCache.get(key3));
   assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction3));
   assertNotNull(executingActionsCache.get(key3));
   
   actionTrackingService.requestActionCancellation(sleepAction3);
   assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction3));
   assertNotNull(executingActionsCache.get(key3));
   
   
   // Now have one execute and cancel it, ensure it does
   final SleepActionExecuter sleepActionExec = 
      (SleepActionExecuter)ctx.getBean(SleepActionExecuter.NAME);
   sleepActionExec.setSleepMs(10000);
   
   UserTransaction txn = transactionService.getUserTransaction();
   txn.begin();
   
   executingActionsCache.remove(key3);
   this.actionService.executeAction(sleepAction3, this.nodeRef, false, true);
   
   // End the transaction. Should allow the async action
   //  to be started
   txn.commit();
   Thread.sleep(150);
   
   // Get the updated key, and check
   key3 = ActionTrackingServiceImpl.generateCacheKey(sleepAction3);
   ExecutionSummary s3 = ActionTrackingServiceImpl.buildExecutionSummary(key3);
   
   assertEquals(false, actionTrackingService.isCancellationRequested(sleepAction3));
   assertEquals(false, actionTrackingService.getExecutionDetails(s3).isCancelRequested());
   assertNotNull(executingActionsCache.get(key3));
   
   actionTrackingService.requestActionCancellation(sleepAction3);
   
   assertEquals(true, actionTrackingService.isCancellationRequested(sleepAction3));
   assertEquals(true, actionTrackingService.getExecutionDetails(s3).isCancelRequested());
   assertNotNull(executingActionsCache.get(key3));
   
   // Have it finish sleeping, will have been cancelled
   // (Can't use the policy, as cancel is counted as a failure)
   sleepActionExec.getExecutingThread().interrupt();
   Thread.sleep(150); 

   // Ensure the proper cancelled tracking
   assertEquals(ActionStatus.Cancelled, sleepAction3.getExecutionStatus());
   assertEquals(null, sleepAction3.getExecutionFailureMessage());
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:81,代码来源:ActionTrackingServiceImplTest.java


注:本文中的org.alfresco.service.cmr.action.ActionStatus类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。