use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.
the class ZookeeperLeaderFinderTest method testSecretsCorrupted.
@Test
public void testSecretsCorrupted(VertxTestContext context) {
SecretOperator mock = mock(SecretOperator.class);
ZookeeperLeaderFinder finder = new ZookeeperLeaderFinder(vertx, this::backoff);
when(mock.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER)))).thenReturn(Future.succeededFuture(new SecretBuilder().withNewMetadata().withName(KafkaResources.clusterCaCertificateSecretName(CLUSTER)).withNamespace(NAMESPACE).endMetadata().withData(map(Ca.CA_CRT, "notacert")).build()));
Secret secretWithBadCertificate = new SecretBuilder().withNewMetadata().withName(ClusterOperator.secretName(CLUSTER)).withNamespace(NAMESPACE).endMetadata().withData(map("cluster-operator.key", "notacert", "cluster-operator.crt", "notacert", "cluster-operator.p12", "notatruststore", "cluster-operator.password", "notapassword")).build();
Checkpoint a = context.checkpoint();
finder.findZookeeperLeader(Reconciliation.DUMMY_RECONCILIATION, treeSet(createPodWithId(0), createPodWithId(1)), dummySecret(), secretWithBadCertificate).onComplete(context.failing(e -> context.verify(() -> {
assertThat(e, instanceOf(RuntimeException.class));
assertThat(e.getMessage(), is("Bad/corrupt certificate found in data.cluster-operator\\.crt of Secret testcluster-cluster-operator-certs in namespace testns"));
a.flag();
})));
}
use of io.strimzi.operator.common.BackOff in project strimzi 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();
})));
}
use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.
the class ZookeeperLeaderFinderTest method testLeaderFoundFirstAttempt.
@Test
public void testLeaderFoundFirstAttempt(VertxTestContext context) throws InterruptedException {
int leader = 1;
String leaderPod = "my-cluster-kafka-1";
int[] ports = startMockZks(context, 2, (id, attempt) -> id == leader);
ZookeeperLeaderFinder 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(l -> context.verify(() -> {
assertThat(l, is(leaderPod));
for (FakeZk zk : zks) {
assertThat("Unexpected number of attempts for node " + zk.id, zk.attempts.get(), is(1));
}
a.flag();
})));
}
use of io.strimzi.operator.common.BackOff in project strimzi by strimzi.
the class ZookeeperLeaderFinderTest method testReturnUnknownLeaderDuringNetworkExceptions.
@Test
public void testReturnUnknownLeaderDuringNetworkExceptions(VertxTestContext context) throws InterruptedException {
int[] ports = startMockZks(context, 2, (id, attempt) -> false);
// Close ports to ensure closed ports are used so as to mock network problems
stopZks();
ZookeeperLeaderFinder 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(ZookeeperLeaderFinder.UNKNOWN_LEADER));
for (FakeZk zk : zks) {
assertThat("Unexpected number of attempts for node " + zk.id, zk.attempts.get(), is(0));
}
a.flag();
})));
}
use of io.strimzi.operator.common.BackOff in project strimzi-kafka-operator by strimzi.
the class ConnectorMockTest method setup.
@SuppressWarnings({ "checkstyle:MethodLength" })
@BeforeEach
public void setup(VertxTestContext testContext) {
vertx = Vertx.vertx();
client = new MockKube().withCustomResourceDefinition(Crds.kafkaConnect(), KafkaConnect.class, KafkaConnectList.class, KafkaConnect::getStatus, KafkaConnect::setStatus).end().withCustomResourceDefinition(Crds.kafkaConnector(), KafkaConnector.class, KafkaConnectorList.class, KafkaConnector::getStatus, KafkaConnector::setStatus).end().build();
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, KubernetesVersion.V1_18);
setupMockConnectAPI();
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client, 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, 10_000);
ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(map(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_FULL_RECONCILIATION_INTERVAL_MS, Long.toString(Long.MAX_VALUE)), KafkaVersionTestUtils.getKafkaVersionLookup());
kafkaConnectOperator = new KafkaConnectAssemblyOperator(vertx, pfa, ros, config, x -> api);
Checkpoint async = testContext.checkpoint();
// Fail test if watcher closes for any reason
kafkaConnectOperator.createWatch(NAMESPACE, e -> testContext.failNow(e)).onComplete(testContext.succeeding()).compose(watch -> AbstractConnectOperator.createConnectorWatch(kafkaConnectOperator, NAMESPACE, null)).onComplete(testContext.succeeding(v -> async.flag()));
}
Aggregations