Search in sources :

Example 1 with OptimisticLockRetryPolicy

use of org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy in project camel by apache.

the class OptimisticLockRetryPolicyTest method testExponentialBackOffMaximumRetryDelay.

public void testExponentialBackOffMaximumRetryDelay() throws Exception {
    OptimisticLockRetryPolicy policy = new OptimisticLockRetryPolicy();
    policy.setRandomBackOff(false);
    policy.setExponentialBackOff(true);
    policy.setMaximumRetryDelay(200L);
    policy.setRetryDelay(50L);
    for (int i = 0; i < 10; i++) {
        long elapsed = doDelay(policy, i);
        switch(i) {
            case 0:
                assertDelay(50L, elapsed);
                break;
            case 1:
                assertDelay(100L, elapsed);
                break;
            default:
                assertDelay(200L, elapsed);
                break;
        }
    }
}
Also used : OptimisticLockRetryPolicy(org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy)

Example 2 with OptimisticLockRetryPolicy

use of org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy in project camel by apache.

the class OptimisticLockRetryPolicyTest method testExponentialBackOff.

public void testExponentialBackOff() throws Exception {
    OptimisticLockRetryPolicy policy = new OptimisticLockRetryPolicy();
    policy.setRandomBackOff(false);
    policy.setExponentialBackOff(true);
    policy.setMaximumRetryDelay(0L);
    policy.setRetryDelay(50L);
    for (int i = 0; i < 6; i++) {
        long elapsed = doDelay(policy, i);
        assertDelay(50L << i, elapsed);
    }
}
Also used : OptimisticLockRetryPolicy(org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy)

Example 3 with OptimisticLockRetryPolicy

use of org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy in project camel by apache.

the class OptimisticLockRetryPolicyTest method testMaximumRetries.

public void testMaximumRetries() throws Exception {
    OptimisticLockRetryPolicy policy = new OptimisticLockRetryPolicy();
    policy.setRandomBackOff(false);
    policy.setExponentialBackOff(false);
    policy.setMaximumRetryDelay(0L);
    policy.setMaximumRetries(2);
    policy.setRetryDelay(50L);
    for (int i = 0; i < 10; i++) {
        switch(i) {
            case 0:
            case 1:
                assertTrue(policy.shouldRetry(i));
                break;
            default:
                assertFalse(policy.shouldRetry(i));
        }
    }
}
Also used : OptimisticLockRetryPolicy(org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy)

Example 4 with OptimisticLockRetryPolicy

use of org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy in project camel by apache.

the class DistributedOptimisticLockFailingTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:fails").aggregate(header("id"), new BodyInAggregatingStrategy()).aggregationRepository(new AlwaysFailingRepository()).optimisticLocking().optimisticLockRetryPolicy(new OptimisticLockRetryPolicy().maximumRetries(5)).completionSize(2).to("mock:result");
            from("direct:everysecondone").aggregate(header("id"), new BodyInAggregatingStrategy()).aggregationRepository(sharedRepository).optimisticLocking().completionSize(8).to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) OptimisticLockRetryPolicy(org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy)

Example 5 with OptimisticLockRetryPolicy

use of org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy in project camel by apache.

the class OptimisticLockRetryPolicyTest method testRetryDelay.

public void testRetryDelay() throws Exception {
    OptimisticLockRetryPolicy policy = new OptimisticLockRetryPolicy();
    policy.setRandomBackOff(false);
    policy.setExponentialBackOff(false);
    policy.setMaximumRetryDelay(0L);
    policy.setRetryDelay(50L);
    for (int i = 0; i < 10; i++) {
        long elapsed = doDelay(policy, i);
        assertDelay(50L, elapsed);
    }
}
Also used : OptimisticLockRetryPolicy(org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy)

Aggregations

OptimisticLockRetryPolicy (org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy)6 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)1