|
17 | 17 | package org.apache.kafka.server.log.remote.metadata.storage;
|
18 | 18 |
|
19 | 19 | import org.apache.kafka.clients.admin.Admin;
|
| 20 | +import org.apache.kafka.clients.admin.DescribeTopicsResult; |
20 | 21 | import org.apache.kafka.clients.admin.NewTopic;
|
| 22 | +import org.apache.kafka.clients.admin.TopicDescription; |
| 23 | +import org.apache.kafka.common.KafkaFuture; |
21 | 24 | import org.apache.kafka.common.TopicIdPartition;
|
22 | 25 | import org.apache.kafka.common.TopicPartition;
|
23 | 26 | import org.apache.kafka.common.Uuid;
|
|
46 | 49 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
47 | 50 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
48 | 51 | import static org.mockito.ArgumentMatchers.any;
|
| 52 | +import static org.mockito.ArgumentMatchers.anySet; |
49 | 53 | import static org.mockito.Mockito.doAnswer;
|
| 54 | +import static org.mockito.Mockito.mock; |
50 | 55 | import static org.mockito.Mockito.spy;
|
51 | 56 | import static org.mockito.Mockito.verify;
|
| 57 | +import static org.mockito.Mockito.when; |
52 | 58 |
|
53 | 59 | @ClusterTestDefaults(brokers = 3)
|
54 | 60 | public class TopicBasedRemoteLogMetadataManagerTest {
|
@@ -89,14 +95,33 @@ public void testDoesTopicExist() throws ExecutionException, InterruptedException
|
89 | 95 | }
|
90 | 96 |
|
91 | 97 | @ClusterTest
|
92 |
| - public void testTopicDoesNotExist() { |
| 98 | + public void testTopicDoesNotExist() throws ExecutionException, InterruptedException { |
93 | 99 | try (Admin admin = clusterInstance.admin()) {
|
94 | 100 | String topic = "dummy-test-topic";
|
95 | 101 | boolean doesTopicExist = topicBasedRlmm().doesTopicExist(admin, topic);
|
96 | 102 | assertFalse(doesTopicExist);
|
97 | 103 | }
|
98 | 104 | }
|
99 | 105 |
|
| 106 | + @ClusterTest |
| 107 | + public void testDoesTopicExistWithAdminClientExecutionError() throws ExecutionException, InterruptedException { |
| 108 | + // Create a mock Admin client that throws an ExecutionException (not UnknownTopicOrPartitionException) |
| 109 | + Admin mockAdmin = mock(Admin.class); |
| 110 | + DescribeTopicsResult mockDescribeTopicsResult = mock(DescribeTopicsResult.class); |
| 111 | + KafkaFuture<TopicDescription> mockFuture = mock(KafkaFuture.class); |
| 112 | + |
| 113 | + String topic = "test-topic"; |
| 114 | + |
| 115 | + // Set up the mock to throw a RuntimeException wrapped in ExecutionException |
| 116 | + when(mockAdmin.describeTopics(anySet())).thenReturn(mockDescribeTopicsResult); |
| 117 | + when(mockDescribeTopicsResult.topicNameValues()).thenReturn(Map.of(topic, mockFuture)); |
| 118 | + when(mockFuture.get()).thenThrow(new ExecutionException("Admin client connection error", new RuntimeException("Connection failed"))); |
| 119 | + |
| 120 | + // The method should re-throw the ExecutionException since it's not an UnknownTopicOrPartitionException |
| 121 | + TopicBasedRemoteLogMetadataManager rlmm = topicBasedRlmm(); |
| 122 | + assertThrows(ExecutionException.class, () -> rlmm.doesTopicExist(mockAdmin, topic)); |
| 123 | + } |
| 124 | + |
100 | 125 | @ClusterTest
|
101 | 126 | public void testWithNoAssignedPartitions() {
|
102 | 127 | // This test checks simple lifecycle of TopicBasedRemoteLogMetadataManager with out assigning any leader/follower partitions.
|
|
0 commit comments