use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class K8sImplTest method testList.
@Test
public void testList(VertxTestContext context) {
Checkpoint async = context.checkpoint();
List<KafkaTopic> mockKafkaTopicsList = Collections.singletonList(new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("unrelated").withLabels(Collections.singletonMap("foo", "bar")).build()).build());
KubernetesClient mockClient = mock(KubernetesClient.class);
MixedOperation<KafkaTopic, KafkaTopicList, Resource<KafkaTopic>> mockResources = mock(MixedOperation.class);
when(mockClient.resources(any(Class.class), any(Class.class))).thenReturn(mockResources);
when(mockClient.resources(any(Class.class), any(Class.class))).thenReturn(mockResources);
when(mockResources.withLabels(any())).thenReturn(mockResources);
when(mockResources.inNamespace(any())).thenReturn(mockResources);
when(mockResources.list()).thenAnswer(invocation -> {
KafkaTopicList ktl = new KafkaTopicList();
ktl.setItems(mockKafkaTopicsList);
return ktl;
});
K8sImpl k8s = new K8sImpl(vertx, mockClient, new Labels("foo", "bar"), "default");
k8s.listResources().onComplete(context.succeeding(kafkaTopics -> context.verify(() -> {
assertThat(kafkaTopics, is(mockKafkaTopicsList));
async.flag();
})));
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class TopicOperatorBaseIT method alterTopicConfigInKube.
protected String alterTopicConfigInKube(String resourceName, String key, Function<String, String> mutator) {
// now change the topic resource
Object retention = operation().inNamespace(NAMESPACE).withName(resourceName).get().getSpec().getConfig().getOrDefault(key, "12341233");
String currentValue = retention instanceof Integer ? retention.toString() : (String) retention;
String newValue = mutator.apply(currentValue);
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().addToConfig(key, newValue).endSpec().build();
operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
return newValue;
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class TopicOperatorIT method testKafkaTopicModifiedNameChanged.
@Test
public void testKafkaTopicModifiedNameChanged() throws Exception {
// create the topicResource
String topicName = "test-kafkatopic-modified-name-changed";
KafkaTopic topicResource = createKafkaTopicResource(topicName);
// now change the topicResource
String changedName = topicName.toUpperCase(Locale.ENGLISH);
LOGGER.info("Changing Topic Resource spec.topicName from {} to {}", topicName, changedName);
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).get()).editOrNewSpec().withTopicName(changedName).endSpec().build();
operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).replace(changedTopic);
// We expect this to cause a warning event
waitForEvent(topicResource, "Kafka topics cannot be renamed, but KafkaTopic's spec.topicName has changed.", TopicOperator.EventType.WARNING);
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class TopicOperatorIT method testInvalidConfig.
@Test
public void testInvalidConfig() throws Exception {
String topicName = "topic-invalid-config";
String expectedMessage = "Invalid config value for resource ConfigResource(type=TOPIC, name='" + topicName + "'): Invalid value x for configuration min.insync.replicas: Not a number of type INT";
String resourceName = createTopic(topicName, new NewTopic(topicName, 2, (short) 1));
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().addToConfig("min.insync.replicas", "x").endSpec().build();
KafkaTopic replaced = operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
assertStatusNotReady(topicName, InvalidRequestException.class, expectedMessage);
// Now modify Kafka-side to cause another reconciliation: We want the same status.
alterTopicConfigInKafka(topicName, "compression.type", value -> "snappy".equals(value) ? "lz4" : "snappy");
// Wait for a periodic reconciliation
Thread.sleep(RECONCILIATION_INTERVAL + 10_000);
assertStatusNotReady(topicName, InvalidRequestException.class, expectedMessage);
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi by strimzi.
the class TopicOperatorMockTest method testCreatedWithDefaultsInKube.
@Test
public void testCreatedWithDefaultsInKube(VertxTestContext context) throws InterruptedException, ExecutionException {
int retention = 100_000_000;
KafkaTopic kt = new KafkaTopicBuilder().withNewMetadata().withName("my-topic").withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_KIND_LABEL, "topic").endMetadata().withNewSpec().addToConfig("retention.bytes", retention).endSpec().build();
testCreatedInKube(context, kt);
}
Aggregations