Skip to content

Commit 42d83b7

Browse files
pthirunclaude
andcommitted
Combine all three unclean leader election test cases into single test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 80915f7 commit 42d83b7

1 file changed

Lines changed: 13 additions & 31 deletions

File tree

internal/venice-common/src/test/java/com/linkedin/venice/pubsub/adapter/kafka/admin/ApacheKafkaAdminAdapterTest.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,15 @@ public void testGetAllTopicRetentionsThrowsException() throws ExecutionException
598598
}
599599

600600
@Test
601-
public void testSetTopicConfigWithUncleanLeaderElectionSet() {
602-
for (boolean enabled: new boolean[] { false, true }) {
603-
// Reset mock state between iterations
601+
public void testSetTopicConfigUncleanLeaderElection() {
602+
// Test all three cases: false, true, and absent (Optional.empty)
603+
Optional<Boolean>[] cases = new Optional[] { Optional.of(false), Optional.of(true), Optional.empty() };
604+
for (Optional<Boolean> uncleanSetting: cases) {
604605
reset(internalKafkaAdminClientMock);
605606

606607
PubSubTopicConfiguration topicConfiguration =
607608
new PubSubTopicConfiguration(Optional.of(1111L), true, Optional.of(222), 333L, Optional.empty());
608-
topicConfiguration.setUncleanLeaderElectionEnable(Optional.of(enabled));
609+
topicConfiguration.setUncleanLeaderElectionEnable(uncleanSetting);
609610

610611
AlterConfigsResult alterConfigsResultMock = mock(AlterConfigsResult.class);
611612
KafkaFuture<Void> alterConfigsKafkaFutureMock = mock(KafkaFuture.class);
@@ -622,37 +623,18 @@ public void testSetTopicConfigWithUncleanLeaderElectionSet() {
622623
assertEquals(resourceConfigMap.size(), 1);
623624
for (Map.Entry<ConfigResource, Config> entry: resourceConfigMap.entrySet()) {
624625
Config config = entry.getValue();
625-
assertEquals(config.get(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG).value(), Boolean.toString(enabled));
626+
if (uncleanSetting.isPresent()) {
627+
assertEquals(
628+
config.get(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG).value(),
629+
Boolean.toString(uncleanSetting.get()));
630+
} else {
631+
// When unset, the property should not be present
632+
assertTrue(config.get(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG) == null);
633+
}
626634
}
627635
}
628636
}
629637

630-
@Test
631-
public void testSetTopicConfigWithUncleanLeaderElectionEmpty() {
632-
PubSubTopicConfiguration topicConfiguration =
633-
new PubSubTopicConfiguration(Optional.of(1111L), true, Optional.of(222), 333L, Optional.empty());
634-
// uncleanLeaderElectionEnable defaults to Optional.empty()
635-
636-
AlterConfigsResult alterConfigsResultMock = mock(AlterConfigsResult.class);
637-
KafkaFuture<Void> alterConfigsKafkaFutureMock = mock(KafkaFuture.class);
638-
639-
Map<ConfigResource, Config> resourceConfigMap = new HashMap<>();
640-
when(internalKafkaAdminClientMock.alterConfigs(any())).thenAnswer(invocation -> {
641-
resourceConfigMap.putAll(invocation.getArgument(0));
642-
return alterConfigsResultMock;
643-
});
644-
when(alterConfigsResultMock.all()).thenReturn(alterConfigsKafkaFutureMock);
645-
646-
kafkaAdminAdapter.setTopicConfig(testPubSubTopic, topicConfiguration);
647-
648-
assertEquals(resourceConfigMap.size(), 1);
649-
for (Map.Entry<ConfigResource, Config> entry: resourceConfigMap.entrySet()) {
650-
Config config = entry.getValue();
651-
// When unset, the property should not be present
652-
assertTrue(config.get(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG) == null);
653-
}
654-
}
655-
656638
@Test
657639
public void testGetTopicConfigReadsUncleanLeaderElection() throws Exception {
658640
DescribeConfigsResult describeConfigsResultMock = mock(DescribeConfigsResult.class);

0 commit comments

Comments
 (0)