-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* added pagination for get topics api * frontend fix * - fixed merge conflicts - renamed pageSize to perPage
- Loading branch information
1 parent
909e196
commit a8ed4ff
Showing
7 changed files
with
166 additions
and
17 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
101 changes: 101 additions & 0 deletions
101
kafka-ui-api/src/test/java/com/provectus/kafka/ui/service/ClusterServiceTest.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,101 @@ | ||
package com.provectus.kafka.ui.service; | ||
|
||
import com.provectus.kafka.ui.mapper.ClusterMapper; | ||
import com.provectus.kafka.ui.model.InternalTopic; | ||
import com.provectus.kafka.ui.model.KafkaCluster; | ||
import com.provectus.kafka.ui.model.Topic; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mapstruct.factory.Mappers; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ClusterServiceTest { | ||
@InjectMocks | ||
private ClusterService clusterService; | ||
|
||
@Mock | ||
private ClustersStorage clustersStorage; | ||
@Spy | ||
private final ClusterMapper clusterMapper = Mappers.getMapper(ClusterMapper.class); | ||
|
||
@Test | ||
public void shouldListFirst20Topics() { | ||
var topicName = UUID.randomUUID().toString(); | ||
|
||
when(clustersStorage.getClusterByName(topicName)) | ||
.thenReturn(Optional.of(KafkaCluster.builder() | ||
.topics( | ||
IntStream.rangeClosed(1, 100).boxed() | ||
.map(Objects::toString) | ||
.collect(Collectors.toMap(Function.identity(), e -> InternalTopic.builder() | ||
.partitions(Map.of()) | ||
.name(e) | ||
.build())) | ||
) | ||
.build())); | ||
|
||
var topics = clusterService.getTopics(topicName, Optional.empty(), Optional.empty()); | ||
assertThat(topics.getPageCount()).isEqualTo(5); | ||
assertThat(topics.getTopics()).hasSize(20); | ||
assertThat(topics.getTopics()).map(Topic::getName).isSorted(); | ||
} | ||
|
||
@Test | ||
public void shouldCalculateCorrectPageCountForNonDivisiblePageSize() { | ||
var topicName = UUID.randomUUID().toString(); | ||
|
||
when(clustersStorage.getClusterByName(topicName)) | ||
.thenReturn(Optional.of(KafkaCluster.builder() | ||
.topics( | ||
IntStream.rangeClosed(1, 100).boxed() | ||
.map(Objects::toString) | ||
.collect(Collectors.toMap(Function.identity(), e -> InternalTopic.builder() | ||
.partitions(Map.of()) | ||
.name(e) | ||
.build())) | ||
) | ||
.build())); | ||
|
||
var topics = clusterService.getTopics(topicName, Optional.of(4), Optional.of(33)); | ||
assertThat(topics.getPageCount()).isEqualTo(4); | ||
assertThat(topics.getTopics()).hasSize(1) | ||
.first().extracting(Topic::getName).isEqualTo("99"); | ||
} | ||
|
||
@Test | ||
public void shouldCorrectlyHandleNonPositivePageNumberAndPageSize() { | ||
var topicName = UUID.randomUUID().toString(); | ||
|
||
when(clustersStorage.getClusterByName(topicName)) | ||
.thenReturn(Optional.of(KafkaCluster.builder() | ||
.topics( | ||
IntStream.rangeClosed(1, 100).boxed() | ||
.map(Objects::toString) | ||
.collect(Collectors.toMap(Function.identity(), e -> InternalTopic.builder() | ||
.partitions(Map.of()) | ||
.name(e) | ||
.build())) | ||
) | ||
.build())); | ||
|
||
var topics = clusterService.getTopics(topicName, Optional.of(0), Optional.of(-1)); | ||
assertThat(topics.getPageCount()).isEqualTo(5); | ||
assertThat(topics.getTopics()).hasSize(20); | ||
assertThat(topics.getTopics()).map(Topic::getName).isSorted(); | ||
} | ||
} |
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
a8ed4ff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there plans to be included in the docker image?
I discovered this today when I migrated several topics. 🤣