@@ -636,51 +636,40 @@ public void testSetTopicConfigUncleanLeaderElection() {
636636 }
637637
638638 @ Test
639- public void testGetTopicConfigReadsUncleanLeaderElection () throws Exception {
640- DescribeConfigsResult describeConfigsResultMock = mock (DescribeConfigsResult .class );
641- KafkaFuture <Map <ConfigResource , Config >> describeConfigsKafkaFutureMock = mock (KafkaFuture .class );
642-
643- List <ConfigEntry > configEntries = Arrays .asList (
644- new ConfigEntry ("cleanup.policy" , "compact" ),
645- new ConfigEntry ("retention.ms" , "1111" ),
646- new ConfigEntry ("min.compaction.lag.ms" , "2222" ),
647- new ConfigEntry ("min.insync.replicas" , "3333" ),
648- new ConfigEntry ("unclean.leader.election.enable" , "false" ));
649- Config config = new Config (configEntries );
650- Map <ConfigResource , Config > configMap = new HashMap <>();
651- configMap .put (new ConfigResource (ConfigResource .Type .TOPIC , testPubSubTopic .getName ()), config );
652-
653- when (internalKafkaAdminClientMock .describeConfigs (any ())).thenReturn (describeConfigsResultMock );
654- when (describeConfigsResultMock .all ()).thenReturn (describeConfigsKafkaFutureMock );
655- when (describeConfigsKafkaFutureMock .get ()).thenReturn (configMap );
656-
657- PubSubTopicConfiguration topicConfiguration = kafkaAdminAdapter .getTopicConfig (testPubSubTopic );
658-
659- assertTrue (topicConfiguration .getUncleanLeaderElectionEnable ().isPresent ());
660- assertFalse (topicConfiguration .getUncleanLeaderElectionEnable ().get ());
661- }
662-
663- @ Test
664- public void testGetTopicConfigWithoutUncleanLeaderElection () throws Exception {
665- DescribeConfigsResult describeConfigsResultMock = mock (DescribeConfigsResult .class );
666- KafkaFuture <Map <ConfigResource , Config >> describeConfigsKafkaFutureMock = mock (KafkaFuture .class );
667-
668- List <ConfigEntry > configEntries = Arrays .asList (
669- new ConfigEntry ("cleanup.policy" , "compact" ),
670- new ConfigEntry ("retention.ms" , "1111" ),
671- new ConfigEntry ("min.compaction.lag.ms" , "2222" ),
672- new ConfigEntry ("min.insync.replicas" , "3333" ));
673- Config config = new Config (configEntries );
674- Map <ConfigResource , Config > configMap = new HashMap <>();
675- configMap .put (new ConfigResource (ConfigResource .Type .TOPIC , testPubSubTopic .getName ()), config );
676-
677- when (internalKafkaAdminClientMock .describeConfigs (any ())).thenReturn (describeConfigsResultMock );
678- when (describeConfigsResultMock .all ()).thenReturn (describeConfigsKafkaFutureMock );
679- when (describeConfigsKafkaFutureMock .get ()).thenReturn (configMap );
680-
681- PubSubTopicConfiguration topicConfiguration = kafkaAdminAdapter .getTopicConfig (testPubSubTopic );
639+ public void testGetTopicConfigUncleanLeaderElection () throws Exception {
640+ // Test with and without unclean.leader.election.enable in the topic config
641+ for (Optional <String > uncleanValue : new Optional [] { Optional .of ("false" ), Optional .empty () }) {
642+ reset (internalKafkaAdminClientMock );
682643
683- assertFalse (topicConfiguration .getUncleanLeaderElectionEnable ().isPresent ());
644+ DescribeConfigsResult describeConfigsResultMock = mock (DescribeConfigsResult .class );
645+ KafkaFuture <Map <ConfigResource , Config >> describeConfigsKafkaFutureMock = mock (KafkaFuture .class );
646+
647+ List <ConfigEntry > configEntries = new ArrayList <>(
648+ Arrays .asList (
649+ new ConfigEntry ("cleanup.policy" , "compact" ),
650+ new ConfigEntry ("retention.ms" , "1111" ),
651+ new ConfigEntry ("min.compaction.lag.ms" , "2222" ),
652+ new ConfigEntry ("min.insync.replicas" , "3333" )));
653+ uncleanValue .ifPresent (v -> configEntries .add (new ConfigEntry ("unclean.leader.election.enable" , v )));
654+ Config config = new Config (configEntries );
655+ Map <ConfigResource , Config > configMap = new HashMap <>();
656+ configMap .put (new ConfigResource (ConfigResource .Type .TOPIC , testPubSubTopic .getName ()), config );
657+
658+ when (internalKafkaAdminClientMock .describeConfigs (any ())).thenReturn (describeConfigsResultMock );
659+ when (describeConfigsResultMock .all ()).thenReturn (describeConfigsKafkaFutureMock );
660+ when (describeConfigsKafkaFutureMock .get ()).thenReturn (configMap );
661+
662+ PubSubTopicConfiguration topicConfiguration = kafkaAdminAdapter .getTopicConfig (testPubSubTopic );
663+
664+ if (uncleanValue .isPresent ()) {
665+ assertTrue (topicConfiguration .getUncleanLeaderElectionEnable ().isPresent ());
666+ assertEquals (
667+ topicConfiguration .getUncleanLeaderElectionEnable ().get (),
668+ (Boolean ) Boolean .parseBoolean (uncleanValue .get ()));
669+ } else {
670+ assertFalse (topicConfiguration .getUncleanLeaderElectionEnable ().isPresent ());
671+ }
672+ }
684673 }
685674
686675 @ Test
0 commit comments