Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE: Fix KafkaConsumerGroupTests on Windows #261

Merged
merged 8 commits into from
Aug 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 40 additions & 41 deletions api/src/test/java/io/kafbat/ui/KafkaConsumerGroupTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand All @@ -32,7 +31,6 @@ public class KafkaConsumerGroupTests extends AbstractIntegrationTest {
@Test
void shouldNotFoundWhenNoSuchConsumerGroupId() {
String groupId = "groupA";
String expError = "The group id does not exist";
webTestClient
.delete()
.uri("/api/clusters/{clusterName}/consumer-groups/{groupId}", LOCAL, groupId)
Expand All @@ -47,12 +45,13 @@ void shouldOkWhenConsumerGroupIsNotActive() {

//Create a consumer and subscribe to the topic
String groupId = UUID.randomUUID().toString();
val consumer = createTestConsumerWithGroupId(groupId);
consumer.subscribe(List.of(topicName));
consumer.poll(Duration.ofMillis(100));
try (val consumer = createTestConsumerWithGroupId(groupId)) {
consumer.subscribe(List.of(topicName));
consumer.poll(Duration.ofMillis(100));

//Unsubscribe from all topics to be able to delete this consumer
consumer.unsubscribe();
//Unsubscribe from all topics to be able to delete this consumer
consumer.unsubscribe();
}

//Delete the consumer when it's INACTIVE and check
webTestClient
Expand All @@ -69,24 +68,24 @@ void shouldBeBadRequestWhenConsumerGroupIsActive() {

//Create a consumer and subscribe to the topic
String groupId = UUID.randomUUID().toString();
val consumer = createTestConsumerWithGroupId(groupId);
consumer.subscribe(List.of(topicName));
consumer.poll(Duration.ofMillis(100));
try (val consumer = createTestConsumerWithGroupId(groupId)) {
consumer.subscribe(List.of(topicName));
consumer.poll(Duration.ofMillis(100));

//Try to delete the consumer when it's ACTIVE
String expError = "The group is not empty";
webTestClient
.delete()
.uri("/api/clusters/{clusterName}/consumer-groups/{groupId}", LOCAL, groupId)
.exchange()
.expectStatus()
.isBadRequest();
//Try to delete the consumer when it's ACTIVE
webTestClient
.delete()
.uri("/api/clusters/{clusterName}/consumer-groups/{groupId}", LOCAL, groupId)
.exchange()
.expectStatus()
.isBadRequest();
}
}

@Test
void shouldReturnConsumerGroupsWithPagination() throws Exception {
try (var groups1 = startConsumerGroups(3, "cgPageTest1");
var groups2 = startConsumerGroups(2, "cgPageTest2")) {
try (var ignored = startConsumerGroups(3, "cgPageTest1");
var ignored1 = startConsumerGroups(2, "cgPageTest2")) {
webTestClient
.get()
.uri("/api/clusters/{clusterName}/consumer-groups/paged?perPage=3&search=cgPageTest", LOCAL)
Expand Down Expand Up @@ -114,19 +113,19 @@ void shouldReturnConsumerGroupsWithPagination() throws Exception {
});

webTestClient
.get()
.uri("/api/clusters/{clusterName}/consumer-groups/paged?perPage=10&&search"
+ "=cgPageTest&orderBy=NAME&sortOrder=DESC", LOCAL)
.exchange()
.expectStatus()
.isOk()
.expectBody(ConsumerGroupsPageResponseDTO.class)
.value(page -> {
assertThat(page.getPageCount()).isEqualTo(1);
assertThat(page.getConsumerGroups().size()).isEqualTo(5);
assertThat(page.getConsumerGroups())
.isSortedAccordingTo(Comparator.comparing(ConsumerGroupDTO::getGroupId).reversed());
});
.get()
.uri("/api/clusters/{clusterName}/consumer-groups/paged?perPage=10&&search"
+ "=cgPageTest&orderBy=NAME&sortOrder=DESC", LOCAL)
.exchange()
.expectStatus()
.isOk()
.expectBody(ConsumerGroupsPageResponseDTO.class)
.value(page -> {
assertThat(page.getPageCount()).isEqualTo(1);
assertThat(page.getConsumerGroups().size()).isEqualTo(5);
assertThat(page.getConsumerGroups())
.isSortedAccordingTo(Comparator.comparing(ConsumerGroupDTO::getGroupId).reversed());
});

webTestClient
.get()
Expand All @@ -149,14 +148,14 @@ private Closeable startConsumerGroups(int count, String consumerGroupPrefix) {
String topicName = createTopicWithRandomName();
var consumers =
Stream.generate(() -> {
String groupId = consumerGroupPrefix + RandomStringUtils.randomAlphabetic(5);
val consumer = createTestConsumerWithGroupId(groupId);
consumer.subscribe(List.of(topicName));
consumer.poll(Duration.ofMillis(100));
return consumer;
})
.limit(count)
.collect(Collectors.toList());
String groupId = consumerGroupPrefix + RandomStringUtils.randomAlphabetic(5);
val consumer = createTestConsumerWithGroupId(groupId);
consumer.subscribe(List.of(topicName));
consumer.poll(Duration.ofMillis(100));
return consumer;
})
.limit(count)
.toList();
return () -> {
consumers.forEach(KafkaConsumer::close);
deleteTopic(topicName);
Expand Down
Loading