Search in sources :

Example 6 with FailedThumbnailInfo

use of org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo in project alfresco-repository by Alfresco.

the class ThumbnailServiceImplTest method testRuleExecutionOnFailedThumbnailChild.

/**
 * Inbound rule must not be applied on failed thumbnail
 *
 * see MNT-10914
 */
@Test
public void testRuleExecutionOnFailedThumbnailChild() throws Exception {
    // create inbound rule on folder
    Map<String, Serializable> params = new HashMap<String, Serializable>(1);
    params.put("aspect-name", ContentModel.ASPECT_GEN_CLASSIFIABLE);
    Rule rule = new Rule();
    rule.setRuleType(RuleType.INBOUND);
    Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME, params);
    ActionCondition condition = this.actionService.createActionCondition(NoConditionEvaluator.NAME, null);
    action.addActionCondition(condition);
    rule.setAction(action);
    rule.applyToChildren(true);
    services.getRuleService().saveRule(folder, rule);
    TestTransaction.flagForCommit();
    TestTransaction.end();
    final NodeRef corruptNode = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            return createCorruptedContent(folder);
        }
    });
    // Make sure the source node is correctly set up before we start
    // It should not be renditioned and should not be marked as having any failed thumbnails.
    assertFalse(secureNodeService.hasAspect(corruptNode, ContentModel.ASPECT_FAILED_THUMBNAIL_SOURCE));
    // Attempt to perform a thumbnail that we know will fail.
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            ThumbnailDefinition thumbnailDef = thumbnailService.getThumbnailRegistry().getThumbnailDefinition("doclib");
            Action createThumbnailAction = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, services);
            actionService.executeAction(createThumbnailAction, corruptNode, true, true);
            return null;
        }
    });
    // The thumbnail attempt has now failed. But a compensating action should have been scheduled that will mark the
    // source node with a failure aspect. As that is an asynchronous action, we need to wait for that to complete.
    // This should be long enough for the compensating action to run.
    Thread.sleep(3000);
    final NodeRef failedThumbnailNode = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            assertTrue("corrupt node should have failed thumbnails aspect", secureNodeService.hasAspect(corruptNode, ContentModel.ASPECT_FAILED_THUMBNAIL_SOURCE));
            Map<String, FailedThumbnailInfo> failedThumbnails = thumbnailService.getFailedThumbnails(corruptNode);
            assertEquals("Wrong number of failed thumbnails", 1, failedThumbnails.size());
            assertTrue("Missing QName for failed thumbnail", failedThumbnails.containsKey("doclib"));
            final FailedThumbnailInfo doclibFailureInfo = failedThumbnails.get("doclib");
            assertNotNull("Failure info was null", doclibFailureInfo);
            return doclibFailureInfo.getFailedThumbnailNode();
        }
    });
    assertTrue("Rule must not be executed on document", secureNodeService.hasAspect(corruptNode, ContentModel.ASPECT_GEN_CLASSIFIABLE));
    assertFalse("Rule must not be executed on failed thumbnail", secureNodeService.hasAspect(failedThumbnailNode, ContentModel.ASPECT_GEN_CLASSIFIABLE));
}
Also used : Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) HashMap(java.util.HashMap) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FailedThumbnailInfo(org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo) Rule(org.alfresco.service.cmr.rule.Rule) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 7 with FailedThumbnailInfo

use of org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo in project alfresco-repository by Alfresco.

the class NodeEligibleForRethumbnailingEvaluatorTest method testNodeWithFailedThumbnails.

@Test
public void testNodeWithFailedThumbnails() {
    // A "non-difficult" node is one which is not yet known to be difficult to thumbnail.
    // In other words it is one which has previously failed to thumbnail, but which has not yet
    // hit the retryCount limit for initial retries.
    NodeEligibleForRethumbnailingEvaluator evaluator = (NodeEligibleForRethumbnailingEvaluator) this.applicationContext.getBean(NodeEligibleForRethumbnailingEvaluator.NAME);
    // Evaluate the thumbnail definition which has failed.
    // 
    // 1. A node that has failed once - and more recently than the limit.
    ActionCondition condition = new ActionConditionImpl(GUID.generate(), NodeEligibleForRethumbnailingEvaluator.NAME);
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_THUMBNAIL_DEFINITION_NAME, thumbnailDef1.getLocalName());
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_RETRY_PERIOD, failureHandlingOptions.getRetryPeriod() * 1000);
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_RETRY_COUNT, failureHandlingOptions.getRetryCount());
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD, failureHandlingOptions.getQuietPeriod() * 1000);
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD_RETRIES_ENABLED, true);
    assertFalse(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 2. A node that has failed once - but longer ago than the lower limit.
    Map<String, FailedThumbnailInfo> failures = thumbnailService.getFailedThumbnails(recentlyFailedNodeRef);
    assertFalse(failures.isEmpty());
    final FailedThumbnailInfo failedThumbnailInfo = failures.get(thumbnailDef1.getLocalName());
    final long timeBeforeTheLimit = new Date().getTime() - (failureHandlingOptions.getRetryPeriod() * 1000l) - 5000l;
    nodeService.setProperty(failedThumbnailInfo.getFailedThumbnailNode(), ContentModel.PROP_FAILED_THUMBNAIL_TIME, timeBeforeTheLimit);
    assertTrue(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 3. If the same node had failed retryCount times, it would not be eligible.
    // At this point it would be a "difficult" document.
    nodeService.setProperty(failedThumbnailInfo.getFailedThumbnailNode(), ContentModel.PROP_FAILURE_COUNT, failureHandlingOptions.getRetryCount());
    assertFalse(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 4. If it had failed retryCount times, but its last failure time was more than
    // quietPeriod seconds ago, then it would be eligible.
    final long timeBeforeTheLongLimit = new Date().getTime() - (failureHandlingOptions.getQuietPeriod() * 1000l) - 5000l;
    nodeService.setProperty(failedThumbnailInfo.getFailedThumbnailNode(), ContentModel.PROP_FAILED_THUMBNAIL_TIME, timeBeforeTheLongLimit);
    assertTrue(evaluator.evaluate(condition, recentlyFailedNodeRef));
    // 5. Unless the retries during the quiet period are disabled...
    condition.setParameterValue(NodeEligibleForRethumbnailingEvaluator.PARAM_QUIET_PERIOD_RETRIES_ENABLED, false);
    assertFalse(evaluator.evaluate(condition, recentlyFailedNodeRef));
}
Also used : FailedThumbnailInfo(org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo) ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) Date(java.util.Date) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Aggregations

FailedThumbnailInfo (org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo)7 Serializable (java.io.Serializable)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Date (java.util.Date)3 QName (org.alfresco.service.namespace.QName)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)2 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)2 Action (org.alfresco.service.cmr.action.Action)2 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)2 ActionConditionImpl (org.alfresco.repo.action.ActionConditionImpl)1 Rule (org.alfresco.service.cmr.rule.Rule)1 BaseSpringTest (org.alfresco.util.BaseSpringTest)1