-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update of unit tests to use KRaft - part 6 (#10436)
Signed-off-by: Jakub Scholz <www@scholzj.com>
- Loading branch information
Showing
6 changed files
with
1,314 additions
and
691 deletions.
There are no files selected for viewing
220 changes: 122 additions & 98 deletions
220
...o/strimzi/operator/cluster/operator/assembly/KafkaAssemblyOperatorCustomCertMockTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
672 changes: 177 additions & 495 deletions
672
...mzi/operator/cluster/operator/assembly/KafkaAssemblyOperatorManualRollingUpdatesTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
850 changes: 850 additions & 0 deletions
850
...ator/cluster/operator/assembly/KafkaAssemblyOperatorManualRollingUpdatesZooBasedTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
.../operator/cluster/operator/assembly/KafkaAssemblyOperatorNonParametrizedZooBasedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright Strimzi authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.strimzi.operator.cluster.operator.assembly; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.strimzi.api.kafka.model.kafka.Kafka; | ||
import io.strimzi.api.kafka.model.kafka.KafkaBuilder; | ||
import io.strimzi.api.kafka.model.kafka.KafkaList; | ||
import io.strimzi.api.kafka.model.kafka.listener.GenericKafkaListenerBuilder; | ||
import io.strimzi.api.kafka.model.kafka.listener.KafkaListenerType; | ||
import io.strimzi.certs.OpenSslCertManager; | ||
import io.strimzi.operator.cluster.ClusterOperatorConfig; | ||
import io.strimzi.operator.cluster.KafkaVersionTestUtils; | ||
import io.strimzi.operator.cluster.PlatformFeaturesAvailability; | ||
import io.strimzi.operator.cluster.ResourceUtils; | ||
import io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier; | ||
import io.strimzi.operator.cluster.operator.resource.kubernetes.CrdOperator; | ||
import io.strimzi.operator.common.Reconciliation; | ||
import io.strimzi.operator.common.model.InvalidResourceException; | ||
import io.strimzi.operator.common.model.PasswordGenerator; | ||
import io.strimzi.platform.KubernetesVersion; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.WorkerExecutor; | ||
import io.vertx.junit5.Checkpoint; | ||
import io.vertx.junit5.VertxExtension; | ||
import io.vertx.junit5.VertxTestContext; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(VertxExtension.class) | ||
public class KafkaAssemblyOperatorNonParametrizedZooBasedTest { | ||
private static final String NAMESPACE = "test"; | ||
private static final String NAME = "my-kafka"; | ||
private static final OpenSslCertManager CERT_MANAGER = new OpenSslCertManager(); | ||
@SuppressWarnings("SpellCheckingInspection") | ||
private static final PasswordGenerator PASSWORD_GENERATOR = new PasswordGenerator(12, | ||
"abcdefghijklmnopqrstuvwxyz" + | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
"abcdefghijklmnopqrstuvwxyz" + | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + | ||
"0123456789"); | ||
|
||
private static Vertx vertx; | ||
private static WorkerExecutor sharedWorkerExecutor; | ||
|
||
@BeforeAll | ||
public static void before() { | ||
vertx = Vertx.vertx(); | ||
sharedWorkerExecutor = vertx.createSharedWorkerExecutor("kubernetes-ops-pool"); | ||
} | ||
|
||
@AfterAll | ||
public static void after() { | ||
sharedWorkerExecutor.close(); | ||
vertx.close(); | ||
} | ||
|
||
/** | ||
* Tests that KRaft cluster cannot be deployed without using NodePools | ||
* | ||
* @param context Test context | ||
*/ | ||
@Test | ||
public void testOptionalCustomResourceFieldsValidation(VertxTestContext context) { | ||
Kafka kafka = new KafkaBuilder() | ||
.withNewMetadata() | ||
.withName(NAME) | ||
.withNamespace(NAMESPACE) | ||
.endMetadata() | ||
.withNewSpec() | ||
.withNewKafka() | ||
.withListeners(new GenericKafkaListenerBuilder() | ||
.withName("listener") | ||
.withPort(9092) | ||
.withTls(true) | ||
.withType(KafkaListenerType.INTERNAL) | ||
.withNewKafkaListenerAuthenticationTlsAuth() | ||
.endKafkaListenerAuthenticationTlsAuth() | ||
.build()) | ||
.endKafka() | ||
.endSpec() | ||
.build(); | ||
|
||
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false); | ||
|
||
CrdOperator<KubernetesClient, Kafka, KafkaList> mockKafkaOps = supplier.kafkaOperator; | ||
when(mockKafkaOps.getAsync(eq(NAMESPACE), eq(NAME))).thenReturn(Future.succeededFuture(kafka)); | ||
|
||
ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(KafkaVersionTestUtils.getKafkaVersionLookup()); | ||
|
||
KafkaAssemblyOperator kao = new KafkaAssemblyOperator( | ||
vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.MINIMAL_SUPPORTED_VERSION), | ||
CERT_MANAGER, | ||
PASSWORD_GENERATOR, | ||
supplier, | ||
config); | ||
|
||
Checkpoint async = context.checkpoint(); | ||
kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME)) | ||
.onComplete(context.failing(v -> context.verify(() -> { | ||
assertThat(v, instanceOf(InvalidResourceException.class)); | ||
|
||
assertThat(v.getMessage(), containsString("The .spec.zookeeper section of the Kafka custom resource is missing. This section is required for a ZooKeeper-based cluster.")); | ||
assertThat(v.getMessage(), containsString("The .spec.kafka.replicas property of the Kafka custom resource is missing. This property is required for a ZooKeeper-based Kafka cluster that is not using Node Pools.")); | ||
assertThat(v.getMessage(), containsString("The .spec.kafka.storage section of the Kafka custom resource is missing. This section is required for a ZooKeeper-based Kafka cluster that is not using Node Pools.")); | ||
|
||
async.flag(); | ||
}))); | ||
} | ||
} |