@@ -305,12 +305,27 @@ public void testCreateOrUpdateRealTimeTopic() {
305305 anyBoolean (),
306306 any (Optional .class ));
307307
308- // Case 2: Real-time topic does not exist, unclean leader election config is set to false
308+ // Case 2: Real-time topic does not exist
309309 VeniceControllerClusterConfig clusterConfig = mock (VeniceControllerClusterConfig .class );
310- when (clusterConfig .getUncleanLeaderElectionEnableRealTimeTopics ()).thenReturn (Optional .of (false ));
311310 when (veniceHelixAdmin .getControllerConfig (clusterName )).thenReturn (clusterConfig );
312311 when (topicManager .containsTopic (pubSubTopic )).thenReturn (false );
313312 veniceHelixAdmin .createOrUpdateRealTimeTopic (clusterName , store , version , pubSubTopic );
313+ verify (topicManager , times (1 )).createTopic (
314+ eq (pubSubTopic ),
315+ eq (partitionCount ),
316+ anyInt (),
317+ anyLong (),
318+ anyBoolean (),
319+ any (Optional .class ),
320+ anyBoolean (),
321+ anyBoolean (),
322+ any (Optional .class ));
323+
324+ // Case 3: Unclean leader election config is set to false
325+ reset (topicManager );
326+ when (clusterConfig .getUncleanLeaderElectionEnableRealTimeTopics ()).thenReturn (Optional .of (false ));
327+ when (topicManager .containsTopic (pubSubTopic )).thenReturn (false );
328+ veniceHelixAdmin .createOrUpdateRealTimeTopic (clusterName , store , version , pubSubTopic );
314329 verify (topicManager , times (1 )).createTopic (
315330 eq (pubSubTopic ),
316331 eq (partitionCount ),
@@ -321,29 +336,26 @@ public void testCreateOrUpdateRealTimeTopic() {
321336 anyBoolean (),
322337 anyBoolean (),
323338 eq (Optional .of (false )));
324- }
325339
326- @ Test
327- public void testCreateOrUpdateRealTimeTopicWithUncleanLeaderElectionUnset () {
328- int partitionCount = 10 ;
329- Store store = mock (Store .class , RETURNS_DEEP_STUBS );
330- when (store .getName ()).thenReturn (storeName );
331- Version version = mock (Version .class );
332- when (version .getStoreName ()).thenReturn (storeName );
333- when (version .getPartitionCount ()).thenReturn (partitionCount );
334- PubSubTopicRepository pubSubTopicRepository = new PubSubTopicRepository ();
335- PubSubTopic pubSubTopic = pubSubTopicRepository .getTopic (storeName + "_rt" );
336- TopicManager topicManager = mock (TopicManager .class );
337- VeniceHelixAdmin veniceHelixAdmin = mock (VeniceHelixAdmin .class );
338- when (veniceHelixAdmin .getTopicManager ()).thenReturn (topicManager );
339- doCallRealMethod ().when (veniceHelixAdmin )
340- .createOrUpdateRealTimeTopic (eq (clusterName ), eq (store ), eq (version ), any (PubSubTopic .class ));
341- when (veniceHelixAdmin .getPubSubTopicRepository ()).thenReturn (pubSubTopicRepository );
340+ // Case 4: Unclean leader election config is set to true
341+ reset (topicManager );
342+ when (clusterConfig .getUncleanLeaderElectionEnableRealTimeTopics ()).thenReturn (Optional .of (true ));
343+ when (topicManager .containsTopic (pubSubTopic )).thenReturn (false );
344+ veniceHelixAdmin .createOrUpdateRealTimeTopic (clusterName , store , version , pubSubTopic );
345+ verify (topicManager , times (1 )).createTopic (
346+ eq (pubSubTopic ),
347+ eq (partitionCount ),
348+ anyInt (),
349+ anyLong (),
350+ anyBoolean (),
351+ any (Optional .class ),
352+ anyBoolean (),
353+ anyBoolean (),
354+ eq (Optional .of (true )));
342355
343- // When unclean leader election config is not set, Optional.empty() should be passed
344- VeniceControllerClusterConfig clusterConfig = mock ( VeniceControllerClusterConfig . class );
356+ // Case 5: Unclean leader election config is not set (empty)
357+ reset ( topicManager );
345358 when (clusterConfig .getUncleanLeaderElectionEnableRealTimeTopics ()).thenReturn (Optional .empty ());
346- when (veniceHelixAdmin .getControllerConfig (clusterName )).thenReturn (clusterConfig );
347359 when (topicManager .containsTopic (pubSubTopic )).thenReturn (false );
348360 veniceHelixAdmin .createOrUpdateRealTimeTopic (clusterName , store , version , pubSubTopic );
349361 verify (topicManager , times (1 )).createTopic (
0 commit comments