Search in sources :

Example 1 with RetryStrategy

use of com.hazelcast.jet.retry.RetryStrategy in project hazelcast by hazelcast.

the class CdcSourceP method init.

@Override
protected void init(@Nonnull Context context) {
    // workaround for https://github.com/hazelcast/hazelcast-jet/issues/2603
    DriverManager.getDrivers();
    String name = getName(properties);
    this.logger = context.logger();
    RetryStrategy retryStrategy = getRetryStrategy(properties);
    log(logger, name, "retry strategy", retryStrategy);
    this.reconnectTracker = new RetryTracker(retryStrategy);
    snapshotting = !NONE.equals(context.processingGuarantee());
    if (!snapshotting) {
        this.commitPeriod = getCommitPeriod(properties);
        log(logger, name, "commit period", commitPeriod);
        if (commitPeriod > 0) {
            lastCommitTime = System.nanoTime();
        }
    }
    this.clearStateOnReconnect = getClearStateOnReconnect(properties);
    log(logger, name, "clear state on reconnect", clearStateOnReconnect);
}
Also used : RetryTracker(com.hazelcast.jet.retry.impl.RetryTracker) RetryStrategy(com.hazelcast.jet.retry.RetryStrategy)

Example 2 with RetryStrategy

use of com.hazelcast.jet.retry.RetryStrategy in project hazelcast by hazelcast.

the class RetryTrackerTest method when_reset.

@Test
public void when_reset() {
    RetryStrategy strategy = RetryStrategies.custom().maxAttempts(1).build();
    RetryTracker tracker = new RetryTracker(strategy, timeSupplier);
    assertFalse(tracker.needsToWait());
    // 1st retry
    tracker.attemptFailed();
    assertTrue(tracker.shouldTryAgain());
    advanceTime(tracker.getNextWaitTimeMs());
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertFalse(tracker.shouldTryAgain());
    tracker.reset();
    // 1st retry
    tracker.attemptFailed();
    assertTrue(tracker.shouldTryAgain());
    advanceTime(tracker.getNextWaitTimeMs());
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertFalse(tracker.shouldTryAgain());
}
Also used : RetryStrategy(com.hazelcast.jet.retry.RetryStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with RetryStrategy

use of com.hazelcast.jet.retry.RetryStrategy in project hazelcast by hazelcast.

the class RetryTrackerTest method when_attemptsZero_doNotRetry.

@Test
public void when_attemptsZero_doNotRetry() {
    RetryStrategy strategy = RetryStrategies.custom().maxAttempts(0).build();
    RetryTracker tracker = new RetryTracker(strategy, timeSupplier);
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertFalse(tracker.shouldTryAgain());
}
Also used : RetryStrategy(com.hazelcast.jet.retry.RetryStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with RetryStrategy

use of com.hazelcast.jet.retry.RetryStrategy in project hazelcast by hazelcast.

the class RetryTrackerTest method when_attemptsPositive_doRetry.

@Test
public void when_attemptsPositive_doRetry() {
    RetryStrategy strategy = RetryStrategies.custom().maxAttempts(2).build();
    RetryTracker tracker = new RetryTracker(strategy, timeSupplier);
    assertFalse(tracker.needsToWait());
    // 1st retry
    tracker.attemptFailed();
    assertTrue(tracker.shouldTryAgain());
    advanceTime(tracker.getNextWaitTimeMs());
    assertFalse(tracker.needsToWait());
    // 2nd retry
    tracker.attemptFailed();
    assertTrue(tracker.shouldTryAgain());
    advanceTime(tracker.getNextWaitTimeMs());
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertFalse(tracker.shouldTryAgain());
}
Also used : RetryStrategy(com.hazelcast.jet.retry.RetryStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with RetryStrategy

use of com.hazelcast.jet.retry.RetryStrategy in project hazelcast by hazelcast.

the class RetryTrackerTest method when_constantRetryPeriod.

@Test
public void when_constantRetryPeriod() {
    RetryStrategy strategy = RetryStrategies.custom().intervalFunction(IntervalFunction.constant(1000)).build();
    RetryTracker tracker = new RetryTracker(strategy, timeSupplier);
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertTrue(tracker.needsToWait());
    advanceTime(999);
    assertTrue(tracker.needsToWait());
    advanceTime(1);
    assertFalse(tracker.needsToWait());
    tracker.attemptFailed();
    assertTrue(tracker.needsToWait());
    advanceTime(999);
    assertTrue(tracker.needsToWait());
    advanceTime(1);
    assertFalse(tracker.needsToWait());
}
Also used : RetryStrategy(com.hazelcast.jet.retry.RetryStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

RetryStrategy (com.hazelcast.jet.retry.RetryStrategy)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 IntervalFunction (com.hazelcast.jet.retry.IntervalFunction)1 RetryTracker (com.hazelcast.jet.retry.impl.RetryTracker)1