Search in sources :

Example 26 with BackOff

use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.

the class KafkaConnectApiMockTest method testStatusWithBackOffOtherExceptionStillFails.

@Test
public void testStatusWithBackOffOtherExceptionStillFails(VertxTestContext context) {
    Queue<Future<Map<String, Object>>> statusResults = new ArrayBlockingQueue<>(1);
    statusResults.add(Future.failedFuture(new ConnectRestException(null, null, 500, null, null)));
    KafkaConnectApi api = new MockKafkaConnectApi(vertx, statusResults);
    Checkpoint async = context.checkpoint();
    api.statusWithBackOff(Reconciliation.DUMMY_RECONCILIATION, backOff, "some-host", 8083, "some-connector").onComplete(context.failing(res -> async.flag()));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BackOff(io.strimzi.operator.common.BackOff) Vertx(io.vertx.core.Vertx) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Checkpoint(io.vertx.junit5.Checkpoint) Queue(java.util.Queue) Collections(java.util.Collections) Checkpoint(io.vertx.junit5.Checkpoint) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test)

Example 27 with BackOff

use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.

the class KafkaConnectApiMockTest method testStatusWithBackOffSucceedingImmediately.

@Test
public void testStatusWithBackOffSucceedingImmediately(VertxTestContext context) {
    Queue<Future<Map<String, Object>>> statusResults = new ArrayBlockingQueue<>(1);
    statusResults.add(Future.succeededFuture(Collections.emptyMap()));
    KafkaConnectApi api = new MockKafkaConnectApi(vertx, statusResults);
    Checkpoint async = context.checkpoint();
    api.statusWithBackOff(Reconciliation.DUMMY_RECONCILIATION, backOff, "some-host", 8083, "some-connector").onComplete(context.succeeding(res -> async.flag()));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BackOff(io.strimzi.operator.common.BackOff) Vertx(io.vertx.core.Vertx) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Checkpoint(io.vertx.junit5.Checkpoint) Queue(java.util.Queue) Collections(java.util.Collections) Checkpoint(io.vertx.junit5.Checkpoint) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test)

Example 28 with BackOff

use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.

the class KafkaConnectApiMockTest method testStatusWithBackOffFailingRepeatedly.

@Test
public void testStatusWithBackOffFailingRepeatedly(VertxTestContext context) {
    Queue<Future<Map<String, Object>>> statusResults = new ArrayBlockingQueue<>(4);
    statusResults.add(Future.failedFuture(new ConnectRestException(null, null, 404, null, null)));
    statusResults.add(Future.failedFuture(new ConnectRestException(null, null, 404, null, null)));
    statusResults.add(Future.failedFuture(new ConnectRestException(null, null, 404, null, null)));
    statusResults.add(Future.failedFuture(new ConnectRestException(null, null, 404, null, null)));
    KafkaConnectApi api = new MockKafkaConnectApi(vertx, statusResults);
    Checkpoint async = context.checkpoint();
    api.statusWithBackOff(Reconciliation.DUMMY_RECONCILIATION, backOff, "some-host", 8083, "some-connector").onComplete(context.failing(res -> async.flag()));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BackOff(io.strimzi.operator.common.BackOff) Vertx(io.vertx.core.Vertx) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Checkpoint(io.vertx.junit5.Checkpoint) Queue(java.util.Queue) Collections(java.util.Collections) Checkpoint(io.vertx.junit5.Checkpoint) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test)

Example 29 with BackOff

use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.

the class KafkaConnectApiMockTest method testStatusWithBackOffSuccedingEventually.

@Test
public void testStatusWithBackOffSuccedingEventually(VertxTestContext context) {
    Queue<Future<Map<String, Object>>> statusResults = new ArrayBlockingQueue<>(3);
    statusResults.add(Future.failedFuture(new ConnectRestException(null, null, 404, null, null)));
    statusResults.add(Future.failedFuture(new ConnectRestException(null, null, 404, null, null)));
    statusResults.add(Future.succeededFuture(Collections.emptyMap()));
    KafkaConnectApi api = new MockKafkaConnectApi(vertx, statusResults);
    Checkpoint async = context.checkpoint();
    api.statusWithBackOff(Reconciliation.DUMMY_RECONCILIATION, backOff, "some-host", 8083, "some-connector").onComplete(context.succeeding(res -> async.flag()));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BackOff(io.strimzi.operator.common.BackOff) Vertx(io.vertx.core.Vertx) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Reconciliation(io.strimzi.operator.common.Reconciliation) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Checkpoint(io.vertx.junit5.Checkpoint) Queue(java.util.Queue) Collections(java.util.Collections) Checkpoint(io.vertx.junit5.Checkpoint) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test)

Example 30 with BackOff

use of io.strimzi.operator.common.BackOff in project strimzi-kafka-operator by strimzi.

the class ZookeeperLeaderFinder method zookeeperLeaderWithBackoff.

private Future<String> zookeeperLeaderWithBackoff(Reconciliation reconciliation, Set<String> pods, NetClientOptions netClientOptions) {
    Promise<String> result = Promise.promise();
    BackOff backOff = backOffSupplier.get();
    Handler<Long> handler = new Handler<Long>() {

        @Override
        public void handle(Long tid) {
            zookeeperLeader(reconciliation, pods, netClientOptions).onComplete(leader -> {
                if (leader.succeeded()) {
                    if (!UNKNOWN_LEADER.equals(leader.result())) {
                        result.complete(leader.result());
                    } else {
                        rescheduleOrComplete(reconciliation, tid);
                    }
                } else {
                    LOGGER.debugOp("Ignoring error", leader.cause());
                    if (backOff.done()) {
                        result.complete(UNKNOWN_LEADER);
                    } else {
                        rescheduleOrComplete(reconciliation, tid);
                    }
                }
            });
        }

        void rescheduleOrComplete(Reconciliation reconciliation, Long tid) {
            if (backOff.done()) {
                LOGGER.warnCr(reconciliation, "Giving up trying to find the leader of {}/{} after {} attempts taking {}ms", reconciliation.name(), reconciliation.namespace(), backOff.maxAttempts(), backOff.totalDelayMs());
                result.complete(UNKNOWN_LEADER);
            } else {
                // Schedule ourselves to run again
                long delay = backOff.delayMs();
                LOGGER.infoCr(reconciliation, "No leader found for cluster {} in namespace {}; " + "backing off for {}ms (cumulative {}ms)", reconciliation.name(), reconciliation.namespace(), delay, backOff.cumulativeDelayMs());
                if (delay < 1) {
                    this.handle(tid);
                } else {
                    vertx.setTimer(delay, this);
                }
            }
        }
    };
    handler.handle(null);
    return result.future();
}
Also used : Reconciliation(io.strimzi.operator.common.Reconciliation) Handler(io.vertx.core.Handler) BackOff(io.strimzi.operator.common.BackOff)

Aggregations

BackOff (io.strimzi.operator.common.BackOff)34 Reconciliation (io.strimzi.operator.common.Reconciliation)34 Future (io.vertx.core.Future)32 Vertx (io.vertx.core.Vertx)32 Checkpoint (io.vertx.junit5.Checkpoint)32 VertxExtension (io.vertx.junit5.VertxExtension)32 VertxTestContext (io.vertx.junit5.VertxTestContext)32 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)32 AfterAll (org.junit.jupiter.api.AfterAll)30 BeforeAll (org.junit.jupiter.api.BeforeAll)30 Test (org.junit.jupiter.api.Test)30 List (java.util.List)24 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)24 AfterEach (org.junit.jupiter.api.AfterEach)24 Promise (io.vertx.core.Promise)22 LogManager (org.apache.logging.log4j.LogManager)22 Logger (org.apache.logging.log4j.Logger)22 CoreMatchers.is (org.hamcrest.CoreMatchers.is)22 Mockito.mock (org.mockito.Mockito.mock)22 Mockito.when (org.mockito.Mockito.when)22