use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.
the class ConfigTest method testInvalidSaslConfig.
@Test
public void testInvalidSaslConfig() {
Map<String, String> map = new HashMap<>(MANDATORY);
map.put(Config.SASL_ENABLED.key, "true");
MockKube mockKube = new MockKube();
KubernetesClient kubeClient = mockKube.build();
Config config = new Config(map);
Session session = new Session(kubeClient, config);
assertThrows(InvalidConfigurationException.class, () -> session.adminClientProperties());
String username = "admin";
String password = "password";
map.put(Config.SASL_USERNAME.key, username);
map.put(Config.SASL_PASSWORD.key, password);
Config configWithCredentials = new Config(map);
Session sessionWithCredentials = new Session(kubeClient, configWithCredentials);
assertThrows(IllegalArgumentException.class, () -> sessionWithCredentials.adminClientProperties());
}
use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.
the class ConfigTest method testInvalidTlsSecurityProtocolConfig.
@Test
public void testInvalidTlsSecurityProtocolConfig() {
Map<String, String> map = new HashMap<>(MANDATORY);
map.put(Config.SECURITY_PROTOCOL.key, "PLAINTEXT");
map.put(Config.TLS_ENABLED.key, "true");
MockKube mockKube = new MockKube();
KubernetesClient kubeClient = mockKube.build();
Config config = new Config(map);
Session session = new Session(kubeClient, config);
assertThrows(InvalidConfigurationException.class, () -> session.adminClientProperties());
}
use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.
the class ConfigTest method testDefaultConfig.
@Test
public void testDefaultConfig() {
Map<String, String> map = new HashMap<>(MANDATORY);
MockKube mockKube = new MockKube();
KubernetesClient kubeClient = mockKube.build();
Config config = new Config(map);
Session session = new Session(kubeClient, config);
Properties adminClientProps = session.adminClientProperties();
assertThat(adminClientProps.getProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG), is("PLAINTEXT"));
assertNull(adminClientProps.getProperty(SaslConfigs.SASL_MECHANISM));
assertNull(adminClientProps.getProperty(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG));
}
use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.
the class TopicOperatorMockTest method setup.
@BeforeEach
public void setup(VertxTestContext context) throws Exception {
// Create cluster in @BeforeEach instead of @BeforeAll as once the checkpoints causing premature success were fixed,
// tests were failing due to topic "my-topic" already existing, and trying to delete the topics at the end of the test was timing out occasionally.
// So works best when the cluster is recreated for each test to avoid shared state
Map<String, String> config = new HashMap<>();
config.put("zookeeper.connect", "zookeeper:2181");
kafkaCluster = new StrimziKafkaCluster(1, 1, config);
kafkaCluster.start();
MockKube mockKube = new MockKube();
mockKube.withCustomResourceDefinition(Crds.kafkaTopic(), KafkaTopic.class, KafkaTopicList.class, KafkaTopic::getStatus, KafkaTopic::setStatus);
kubeClient = mockKube.build();
adminClient = AdminClient.create(Map.of(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaCluster.getBootstrapServers()));
Config topicConfig = new Config(Map.of(Config.KAFKA_BOOTSTRAP_SERVERS.key, kafkaCluster.getBootstrapServers(), Config.ZOOKEEPER_CONNECT.key, kafkaCluster.getZookeeper().getHost() + ":" + kafkaCluster.getZookeeper().getFirstMappedPort(), Config.ZOOKEEPER_CONNECTION_TIMEOUT_MS.key, "30000", Config.NAMESPACE.key, "myproject", Config.CLIENT_ID.key, "myproject-client-id", Config.FULL_RECONCILIATION_INTERVAL_MS.key, "10000"));
session = new Session(kubeClient, topicConfig);
Checkpoint async = context.checkpoint();
vertx.deployVerticle(session, ar -> {
if (ar.succeeded()) {
deploymentId = ar.result();
topicsConfigWatcher = session.topicConfigsWatcher;
topicWatcher = session.topicWatcher;
topicsWatcher = session.topicsWatcher;
metrics = session.metricsRegistry;
metrics.forEachMeter(meter -> metrics.remove(meter));
async.flag();
} else {
ar.cause().printStackTrace();
context.failNow(new Throwable("Failed to deploy session"));
}
});
if (!context.awaitCompletion(60, TimeUnit.SECONDS)) {
context.failNow(new Throwable("Test timeout"));
}
int timeout = 30_000;
waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicWatcher.started());
waitFor("Topic configs watcher not started", 1_000, timeout, () -> this.topicsConfigWatcher.started());
waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicsWatcher.started());
}
use of io.strimzi.test.mockkube.MockKube 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