Search in sources :

Example 11 with BackOff

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

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

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

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

the class KafkaConnectApiTest method test.

@IsolatedTest
@SuppressWarnings({ "unchecked", "checkstyle:MethodLength", "checkstyle:NPathComplexity" })
public void test(VertxTestContext context) {
    KafkaConnectApi client = new KafkaConnectApiImpl(vertx);
    Checkpoint async = context.checkpoint();
    client.listConnectorPlugins(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT).onComplete(context.succeeding(connectorPlugins -> context.verify(() -> {
        assertThat(connectorPlugins.size(), greaterThanOrEqualTo(2));
        ConnectorPlugin fileSink = connectorPlugins.stream().filter(connector -> "org.apache.kafka.connect.file.FileStreamSinkConnector".equals(connector.getConnectorClass())).findFirst().orElse(null);
        assertNotNull(fileSink);
        assertThat(fileSink.getType(), is("sink"));
        assertThat(fileSink.getVersion(), is(not(emptyString())));
        ConnectorPlugin fileSource = connectorPlugins.stream().filter(connector -> "org.apache.kafka.connect.file.FileStreamSourceConnector".equals(connector.getConnectorClass())).findFirst().orElse(null);
        assertNotNull(fileSource);
        assertThat(fileSource.getType(), is("source"));
        assertThat(fileSource.getVersion(), is(not(emptyString())));
    }))).compose(connectorPlugins -> client.list("localhost", PORT)).onComplete(context.succeeding(connectorNames -> context.verify(() -> assertThat(connectorNames, is(empty()))))).compose(connectorNames -> {
        JsonObject o = new JsonObject().put("connector.class", "FileStreamSource").put("tasks.max", "1").put("file", "/dev/null").put("topic", "my-topic");
        return client.createOrUpdatePutRequest(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, "test", o);
    }).onComplete(context.succeeding()).compose(created -> {
        Promise<Map<String, Object>> promise = Promise.promise();
        Handler<Long> handler = new Handler<Long>() {

            @Override
            public void handle(Long timerId) {
                client.status(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, "test").onComplete(result -> {
                    if (result.succeeded()) {
                        Map<String, Object> status = result.result();
                        if ("RUNNING".equals(((Map) status.getOrDefault("connector", emptyMap())).get("state"))) {
                            promise.complete(status);
                            return;
                        } else {
                            System.err.println(status);
                        }
                    } else {
                        result.cause().printStackTrace();
                    }
                    vertx.setTimer(1000, this);
                });
            }
        };
        vertx.setTimer(1000, handler);
        return promise.future();
    }).onComplete(context.succeeding(status -> context.verify(() -> {
        assertThat(status.get("name"), is("test"));
        Map<String, Object> connectorStatus = (Map<String, Object>) status.getOrDefault("connector", emptyMap());
        assertThat(connectorStatus.get("state"), is("RUNNING"));
        assertThat(connectorStatus.get("worker_id"), is("localhost:18083"));
        System.out.println("help " + connectorStatus);
        List<Map> tasks = (List<Map>) status.get("tasks");
        for (Map an : tasks) {
            assertThat(an.get("state"), is("RUNNING"));
            assertThat(an.get("worker_id"), is("localhost:18083"));
        }
    }))).compose(status -> client.getConnectorConfig(Reconciliation.DUMMY_RECONCILIATION, new BackOff(10), "localhost", PORT, "test")).onComplete(context.succeeding(config -> context.verify(() -> {
        assertThat(config, is(TestUtils.map("connector.class", "FileStreamSource", "file", "/dev/null", "tasks.max", "1", "name", "test", "topic", "my-topic")));
    }))).compose(config -> client.getConnectorConfig(Reconciliation.DUMMY_RECONCILIATION, new BackOff(10), "localhost", PORT, "does-not-exist")).onComplete(context.failing(error -> context.verify(() -> {
        assertThat(error, instanceOf(ConnectRestException.class));
        assertThat(((ConnectRestException) error).getStatusCode(), is(404));
    }))).recover(error -> Future.succeededFuture()).compose(ignored -> client.pause("localhost", PORT, "test")).onComplete(context.succeeding()).compose(ignored -> client.resume("localhost", PORT, "test")).onComplete(context.succeeding()).compose(ignored -> client.restart("localhost", PORT, "test")).onComplete(context.succeeding()).compose(ignored -> client.restartTask("localhost", PORT, "test", 0)).onComplete(context.succeeding()).compose(ignored -> {
        JsonObject o = new JsonObject().put("connector.class", "ThisConnectorDoesNotExist").put("tasks.max", "1").put("file", "/dev/null").put("topic", "my-topic");
        return client.createOrUpdatePutRequest(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, "broken", o);
    }).onComplete(context.failing(error -> context.verify(() -> {
        assertThat(error, instanceOf(ConnectRestException.class));
        assertThat(error.getMessage(), containsString("Failed to find any class that implements Connector and which name matches ThisConnectorDoesNotExist"));
    }))).recover(e -> Future.succeededFuture()).compose(ignored -> {
        JsonObject o = new JsonObject().put("connector.class", "FileStreamSource").put("tasks.max", "dog").put("file", "/dev/null").put("topic", "my-topic");
        return client.createOrUpdatePutRequest(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, "broken2", o);
    }).onComplete(context.failing(error -> context.verify(() -> {
        assertThat(error, instanceOf(ConnectRestException.class));
        assertThat(error.getMessage(), containsString("Invalid value dog for configuration tasks.max: Not a number of type INT"));
    }))).recover(e -> Future.succeededFuture()).compose(createResponse -> client.list("localhost", PORT)).onComplete(context.succeeding(connectorNames -> context.verify(() -> assertThat(connectorNames, is(singletonList("test")))))).compose(connectorNames -> client.delete(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, "test")).onComplete(context.succeeding()).compose(deletedConnector -> client.list("localhost", PORT)).onComplete(context.succeeding(connectorNames -> assertThat(connectorNames, is(empty())))).compose(connectorNames -> client.delete(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, "never-existed")).onComplete(context.failing(error -> {
        assertThat(error, instanceOf(ConnectRestException.class));
        assertThat(error.getMessage(), containsString("Connector never-existed not found"));
        async.flag();
    }));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) BackOff(io.strimzi.operator.common.BackOff) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) IsolatedTest(io.strimzi.test.annotations.IsolatedTest) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Files(java.nio.file.Files) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) ConnectorPlugin(io.strimzi.api.kafka.model.connect.ConnectorPlugin) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) File(java.io.File) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Checkpoint(io.vertx.junit5.Checkpoint) Connect(org.apache.kafka.connect.runtime.Connect) Matchers.is(org.hamcrest.Matchers.is) Handler(io.vertx.core.Handler) Matchers.containsString(org.hamcrest.Matchers.containsString) ConnectDistributed(org.apache.kafka.connect.cli.ConnectDistributed) JsonObject(io.vertx.core.json.JsonObject) Handler(io.vertx.core.Handler) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) BackOff(io.strimzi.operator.common.BackOff) ConnectorPlugin(io.strimzi.api.kafka.model.connect.ConnectorPlugin) Checkpoint(io.vertx.junit5.Checkpoint) JsonObject(io.vertx.core.json.JsonObject) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) IsolatedTest(io.strimzi.test.annotations.IsolatedTest)

Example 15 with BackOff

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

the class KafkaConnectAssemblyOperatorMockTest method createConnectCluster.

private Future<Void> createConnectCluster(VertxTestContext context, KafkaConnectApi kafkaConnectApi, boolean reconciliationPaused) {
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, KubernetesVersion.V1_21);
    ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(vertx, this.mockClient, new ZookeeperLeaderFinder(vertx, // Retry up to 3 times (4 attempts), with overall max delay of 35000ms
    () -> new BackOff(5_000, 2, 4)), new DefaultAdminClientProvider(), new DefaultZookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, FeatureGates.NONE, 60_000L);
    ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
    this.kco = new KafkaConnectAssemblyOperator(vertx, pfa, supplier, config, foo -> kafkaConnectApi);
    Promise created = Promise.promise();
    LOGGER.info("Reconciling initially -> create");
    kco.reconcile(new Reconciliation("test-trigger", KafkaConnect.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME)).onComplete(context.succeeding(v -> context.verify(() -> {
        if (!reconciliationPaused) {
            assertThat(mockClient.apps().deployments().inNamespace(NAMESPACE).withName(KafkaConnectResources.deploymentName(CLUSTER_NAME)).get(), is(notNullValue()));
            assertThat(mockClient.configMaps().inNamespace(NAMESPACE).withName(KafkaConnectResources.metricsAndLogConfigMapName(CLUSTER_NAME)).get(), is(notNullValue()));
            assertThat(mockClient.services().inNamespace(NAMESPACE).withName(KafkaConnectResources.serviceName(CLUSTER_NAME)).get(), is(notNullValue()));
            assertThat(mockClient.policy().v1().podDisruptionBudget().inNamespace(NAMESPACE).withName(KafkaConnectResources.deploymentName(CLUSTER_NAME)).get(), is(notNullValue()));
        } else {
            assertThat(mockClient.apps().deployments().inNamespace(NAMESPACE).withName(KafkaConnectResources.deploymentName(CLUSTER_NAME)).get(), is(nullValue()));
            verify(mockClient, never()).resources(KafkaConnect.class);
        }
        created.complete();
    })));
    return created.future();
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) KafkaConnectorList(io.strimzi.api.kafka.KafkaConnectorList) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) MockKube(io.strimzi.test.mockkube.MockKube) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) Resource(io.fabric8.kubernetes.client.dsl.Resource) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) Collections.emptyList(java.util.Collections.emptyList) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Checkpoint(io.vertx.junit5.Checkpoint) Condition(io.strimzi.api.kafka.model.status.Condition) KafkaConnectList(io.strimzi.api.kafka.KafkaConnectList) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BackOff(io.strimzi.operator.common.BackOff) Crds(io.strimzi.api.kafka.Crds) FeatureGates(io.strimzi.operator.cluster.FeatureGates) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) TestUtils(io.strimzi.test.TestUtils) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Promise(io.vertx.core.Promise) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) Mockito.never(org.mockito.Mockito.never) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.DefaultZookeeperScalerProvider) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Promise(io.vertx.core.Promise) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Reconciliation(io.strimzi.operator.common.Reconciliation) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) DefaultZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.DefaultZookeeperScalerProvider) BackOff(io.strimzi.operator.common.BackOff) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider)

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