forked from provectus/kafka-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provectus#211 Feature/clear topic messages (provectus#241)
* added delete action * added test for delete action * added 404 status in contract * fixed typo * added partition parameter * big refactoring
- Loading branch information
1 parent
2b88d1b
commit c4e146a
Showing
10 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
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
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
2 changes: 2 additions & 0 deletions
2
kafka-ui-api/src/test/java/com/provectus/kafka/ui/AbstractBaseTest.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
79 changes: 79 additions & 0 deletions
79
kafka-ui-api/src/test/java/com/provectus/kafka/ui/KafkaConsumerTests.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,79 @@ | ||
package com.provectus.kafka.ui; | ||
|
||
import com.provectus.kafka.ui.model.TopicFormData; | ||
import com.provectus.kafka.ui.model.TopicMessage; | ||
import com.provectus.kafka.ui.producer.KafkaTestProducer; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
@ContextConfiguration(initializers = {AbstractBaseTest.Initializer.class}) | ||
@Log4j2 | ||
@AutoConfigureWebTestClient(timeout = "60000") | ||
public class KafkaConsumerTests extends AbstractBaseTest { | ||
|
||
@Autowired | ||
private WebTestClient webTestClient; | ||
|
||
|
||
@Test | ||
public void shouldDeleteRecords() { | ||
var topicName = UUID.randomUUID().toString(); | ||
webTestClient.post() | ||
.uri("/api/clusters/{clusterName}/topics", LOCAL) | ||
.bodyValue(new TopicFormData() | ||
.name(topicName) | ||
.partitions(1) | ||
.replicationFactor(1) | ||
.configs(Map.of()) | ||
) | ||
.exchange() | ||
.expectStatus() | ||
.isOk(); | ||
|
||
try(KafkaTestProducer<String, String> producer = KafkaTestProducer.forKafka(kafka)) { | ||
Stream.of("one", "two", "three", "four") | ||
.forEach(value -> producer.send(topicName, value)); | ||
} | ||
|
||
webTestClient.get() | ||
.uri("/api/clusters/{clusterName}/topics/{topicName}/messages", LOCAL, topicName) | ||
.exchange() | ||
.expectStatus() | ||
.isOk() | ||
.expectBodyList(TopicMessage.class) | ||
.hasSize(4); | ||
|
||
webTestClient.delete() | ||
.uri("/api/clusters/{clusterName}/topics/{topicName}/messages", LOCAL, topicName) | ||
.exchange() | ||
.expectStatus() | ||
.isOk(); | ||
|
||
webTestClient.get() | ||
.uri("/api/clusters/{clusterName}/topics/{topicName}/messages", LOCAL, topicName) | ||
.exchange() | ||
.expectStatus() | ||
.isOk() | ||
.expectBodyList(TopicMessage.class) | ||
.hasSize(0); | ||
} | ||
|
||
@Test | ||
public void shouldReturn404ForNonExistingTopic() { | ||
var topicName = UUID.randomUUID().toString(); | ||
|
||
webTestClient.delete() | ||
.uri("/api/clusters/{clusterName}/topics/{topicName}/messages", LOCAL, topicName) | ||
.exchange() | ||
.expectStatus() | ||
.isNotFound(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ectus/kafka/ui/KafkaConnectContainer.java → ...a/ui/container/KafkaConnectContainer.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
2 changes: 1 addition & 1 deletion
2
...tus/kafka/ui/SchemaRegistryContainer.java → ...ui/container/SchemaRegistryContainer.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
35 changes: 35 additions & 0 deletions
35
kafka-ui-api/src/test/java/com/provectus/kafka/ui/producer/KafkaTestProducer.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,35 @@ | ||
package com.provectus.kafka.ui.producer; | ||
|
||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.ProducerConfig; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.apache.kafka.common.serialization.StringSerializer; | ||
import org.testcontainers.containers.KafkaContainer; | ||
|
||
import java.util.Map; | ||
|
||
public class KafkaTestProducer<KeyT, ValueT> implements AutoCloseable { | ||
private final KafkaProducer<KeyT, ValueT> producer; | ||
|
||
private KafkaTestProducer(KafkaProducer<KeyT, ValueT> producer) { | ||
this.producer = producer; | ||
} | ||
|
||
public static KafkaTestProducer<String, String> forKafka(KafkaContainer kafkaContainer) { | ||
return new KafkaTestProducer<>(new KafkaProducer<>(Map.of( | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaContainer.getBootstrapServers(), | ||
ProducerConfig.CLIENT_ID_CONFIG, "KafkaTestProducer", | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class, | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class | ||
))); | ||
} | ||
|
||
public void send(String topic, ValueT value) { | ||
producer.send(new ProducerRecord<>(topic, value)); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
producer.close(); | ||
} | ||
} |
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