Search in sources :

Example 31 with BackOff

use of io.strimzi.operator.common.BackOff in project strimzi-kafka-operator 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 32 with BackOff

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

the class ZookeeperLeaderFinderTest method testFinderHandlesFailureByLeaderFoundOnThirdAttempt.

@Test
public void testFinderHandlesFailureByLeaderFoundOnThirdAttempt(VertxTestContext context) throws InterruptedException {
    int desiredLeaderId = 1;
    String leaderPod = "my-cluster-kafka-1";
    int succeedOnAttempt = 2;
    int[] ports = startMockZks(context, 2, (id, attempt) -> attempt == succeedOnAttempt && id == desiredLeaderId);
    TestingZookeeperLeaderFinder finder = new TestingZookeeperLeaderFinder(this::backoff, ports);
    Checkpoint a = context.checkpoint();
    finder.findZookeeperLeader(Reconciliation.DUMMY_RECONCILIATION, treeSet(createPodWithId(0), createPodWithId(1)), dummySecret(), dummySecret()).onComplete(context.succeeding(leader -> context.verify(() -> {
        assertThat(leader, is(leaderPod));
        for (FakeZk zk : zks) {
            assertThat("Unexpected number of attempts for node " + zk.id, zk.attempts.get(), is(succeedOnAttempt + 1));
        }
        a.flag();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) BiFunction(java.util.function.BiFunction) AfterAll(org.junit.jupiter.api.AfterAll) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Ca(io.strimzi.operator.cluster.model.Ca) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) NetClientOptions(io.vertx.core.net.NetClientOptions) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Logger(org.apache.logging.log4j.Logger) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) BackOff(io.strimzi.operator.common.BackOff) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestUtils.map(io.strimzi.test.TestUtils.map) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) Integer.parseInt(java.lang.Integer.parseInt) TimeUnit(java.util.concurrent.TimeUnit) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) NetServer(io.vertx.core.net.NetServer) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(io.vertx.junit5.Checkpoint) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 33 with BackOff

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

the class ZookeeperLeaderFinderTest method testSecretWithMissingClusterOperatorKeyThrowsException.

@Test
public void testSecretWithMissingClusterOperatorKeyThrowsException(VertxTestContext context) {
    SecretOperator mock = mock(SecretOperator.class);
    ZookeeperLeaderFinder finder = new ZookeeperLeaderFinder(vertx, this::backoff);
    Mockito.reset(mock);
    when(mock.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER)))).thenReturn(Future.succeededFuture(new SecretBuilder().withNewMetadata().withName(KafkaResources.clusterCaCertificateSecretName(CLUSTER)).withNamespace(NAMESPACE).endMetadata().withData(emptyMap()).build()));
    Secret secretWithMissingClusterOperatorKey = new SecretBuilder().withNewMetadata().withName(ClusterOperator.secretName(CLUSTER)).withNamespace(NAMESPACE).endMetadata().withData(emptyMap()).build();
    Checkpoint a = context.checkpoint();
    finder.findZookeeperLeader(Reconciliation.DUMMY_RECONCILIATION, treeSet(createPodWithId(0), createPodWithId(1)), dummySecret(), secretWithMissingClusterOperatorKey).onComplete(context.failing(e -> context.verify(() -> {
        assertThat(e, instanceOf(RuntimeException.class));
        assertThat(e.getMessage(), is("The Secret testns/testcluster-cluster-operator-certs is missing the key cluster-operator.key"));
        a.flag();
    })));
}
Also used : SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) BiFunction(java.util.function.BiFunction) AfterAll(org.junit.jupiter.api.AfterAll) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Ca(io.strimzi.operator.cluster.model.Ca) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) NetClientOptions(io.vertx.core.net.NetClientOptions) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Logger(org.apache.logging.log4j.Logger) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) BackOff(io.strimzi.operator.common.BackOff) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestUtils.map(io.strimzi.test.TestUtils.map) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) Integer.parseInt(java.lang.Integer.parseInt) TimeUnit(java.util.concurrent.TimeUnit) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) NetServer(io.vertx.core.net.NetServer) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 34 with BackOff

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

the class ZookeeperLeaderFinderTest method test0PodsClusterReturnsUnknowLeader.

@Test
public void test0PodsClusterReturnsUnknowLeader(VertxTestContext context) {
    ZookeeperLeaderFinder finder = new ZookeeperLeaderFinder(vertx, this::backoff);
    Checkpoint a = context.checkpoint();
    finder.findZookeeperLeader(Reconciliation.DUMMY_RECONCILIATION, emptySet(), dummySecret(), dummySecret()).onComplete(context.succeeding(leader -> {
        context.verify(() -> assertThat(leader, is(ZookeeperLeaderFinder.UNKNOWN_LEADER)));
        a.flag();
    }));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) BiFunction(java.util.function.BiFunction) AfterAll(org.junit.jupiter.api.AfterAll) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) Ca(io.strimzi.operator.cluster.model.Ca) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) NetClientOptions(io.vertx.core.net.NetClientOptions) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) Logger(org.apache.logging.log4j.Logger) Secret(io.fabric8.kubernetes.api.model.Secret) Checkpoint(io.vertx.junit5.Checkpoint) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) BackOff(io.strimzi.operator.common.BackOff) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) ZookeeperCluster(io.strimzi.operator.cluster.model.ZookeeperCluster) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ClusterOperator(io.strimzi.operator.cluster.ClusterOperator) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestUtils.map(io.strimzi.test.TestUtils.map) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.when(org.mockito.Mockito.when) Integer.parseInt(java.lang.Integer.parseInt) TimeUnit(java.util.concurrent.TimeUnit) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) NetServer(io.vertx.core.net.NetServer) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(io.vertx.junit5.Checkpoint) Test(org.junit.jupiter.api.Test)

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