11package com .linkedin .datahub .upgrade .system .elasticsearch .steps ;
22
3+ import static org .mockito .Mockito .atLeastOnce ;
4+
35import com .linkedin .datahub .upgrade .UpgradeContext ;
46import com .linkedin .datahub .upgrade .UpgradeStepResult ;
57import com .linkedin .gms .factory .config .ConfigurationProvider ;
@@ -60,7 +62,7 @@ public void setUp() throws IOException {
6062 Mockito .when (configurationProvider .getPlatformAnalytics ()).thenReturn (platformAnalytics );
6163 Mockito .when (configurationProvider .getElasticSearch ()).thenReturn (elasticSearch );
6264 Mockito .when (elasticSearch .getIndex ()).thenReturn (index );
63- Mockito .when (index .getPrefix ()).thenReturn ("test_" );
65+ Mockito .when (index .getFinalPrefix ()).thenReturn ("test_" );
6466
6567 Mockito .when (upgradeContext .opContext ()).thenReturn (opContext );
6668
@@ -279,7 +281,7 @@ public void testExecutable_WithEmptyPrefix() throws Exception {
279281 // Arrange
280282 Mockito .when (platformAnalytics .isEnabled ()).thenReturn (true );
281283 Mockito .when (searchEngineType .isOpenSearch ()).thenReturn (false );
282- Mockito .when (index .getPrefix ()).thenReturn ("" ); // Empty prefix
284+ Mockito .when (index .getFinalPrefix ()).thenReturn ("" ); // Empty prefix
283285
284286 // Act
285287 Function <UpgradeContext , UpgradeStepResult > executable = step .executable ();
@@ -291,44 +293,7 @@ public void testExecutable_WithEmptyPrefix() throws Exception {
291293 Assert .assertEquals (result .result (), DataHubUpgradeState .SUCCEEDED );
292294
293295 // Verify empty prefix was used and no underscore separator was added
294- Mockito .verify (index ).getPrefix ();
295-
296- // Verify that the low-level requests were made with correct names (no underscore prefix)
297- Mockito .verify (searchClient , Mockito .atLeast (2 )).performLowLevelRequest (Mockito .any ());
298-
299- // Verify specific endpoint calls were made
300- Mockito .verify (searchClient )
301- .performLowLevelRequest (
302- Mockito .argThat (
303- request ->
304- request .getEndpoint ().equals ("/_ilm/policy/datahub_usage_event_policy" )));
305- Mockito .verify (searchClient )
306- .performLowLevelRequest (
307- Mockito .argThat (
308- request ->
309- request
310- .getEndpoint ()
311- .equals ("/_index_template/datahub_usage_event_index_template" )));
312- }
313-
314- @ Test
315- public void testExecutable_WithNullPrefix () throws Exception {
316- // Arrange
317- Mockito .when (platformAnalytics .isEnabled ()).thenReturn (true );
318- Mockito .when (searchEngineType .isOpenSearch ()).thenReturn (false );
319- Mockito .when (index .getPrefix ()).thenReturn (null ); // Null prefix
320-
321- // Act
322- Function <UpgradeContext , UpgradeStepResult > executable = step .executable ();
323- UpgradeStepResult result = executable .apply (upgradeContext );
324-
325- // Assert
326- Assert .assertNotNull (result );
327- Assert .assertEquals (result .stepId (), "CreateUsageEventIndicesStep" );
328- Assert .assertEquals (result .result (), DataHubUpgradeState .SUCCEEDED );
329-
330- // Verify null prefix was handled and no underscore separator was added
331- Mockito .verify (index ).getPrefix ();
296+ Mockito .verify (index , atLeastOnce ()).getFinalPrefix ();
332297
333298 // Verify that the low-level requests were made with correct names (no underscore prefix)
334299 Mockito .verify (searchClient , Mockito .atLeast (2 )).performLowLevelRequest (Mockito .any ());
@@ -353,7 +318,7 @@ public void testExecutable_WithNonEmptyPrefix() throws Exception {
353318 // Arrange
354319 Mockito .when (platformAnalytics .isEnabled ()).thenReturn (true );
355320 Mockito .when (searchEngineType .isOpenSearch ()).thenReturn (false );
356- Mockito .when (index .getPrefix ()).thenReturn ("prod " ); // Non-empty prefix
321+ Mockito .when (index .getFinalPrefix ()).thenReturn ("prod_ " ); // Non-empty prefix
357322
358323 // Act
359324 Function <UpgradeContext , UpgradeStepResult > executable = step .executable ();
@@ -365,7 +330,7 @@ public void testExecutable_WithNonEmptyPrefix() throws Exception {
365330 Assert .assertEquals (result .result (), DataHubUpgradeState .SUCCEEDED );
366331
367332 // Verify non-empty prefix was used and underscore separator was added
368- Mockito .verify (index ). getPrefix ();
333+ Mockito .verify (index , atLeastOnce ()). getFinalPrefix ();
369334
370335 // Verify that the low-level requests were made with correct names (with underscore prefix)
371336 Mockito .verify (searchClient )
@@ -387,8 +352,8 @@ public void testExecutable_WithSpecificPrefix() throws Exception {
387352 // Arrange
388353 Mockito .when (platformAnalytics .isEnabled ()).thenReturn (true );
389354 Mockito .when (searchEngineType .isOpenSearch ()).thenReturn (false );
390- Mockito .when (index .getPrefix ())
391- .thenReturn ("kbcpyv7ss3-staging-test " ); // Specific prefix from issue
355+ Mockito .when (index .getFinalPrefix ())
356+ .thenReturn ("kbcpyv7ss3-staging-test_ " ); // Specific prefix from issue
392357
393358 // Act
394359 Function <UpgradeContext , UpgradeStepResult > executable = step .executable ();
@@ -400,7 +365,7 @@ public void testExecutable_WithSpecificPrefix() throws Exception {
400365 Assert .assertEquals (result .result (), DataHubUpgradeState .SUCCEEDED );
401366
402367 // Verify specific prefix was used and underscore separator was added
403- Mockito .verify (index ). getPrefix ();
368+ Mockito .verify (index , atLeastOnce ()). getFinalPrefix ();
404369
405370 // Verify that the low-level requests were made with correct names (with underscore prefix)
406371 Mockito .verify (searchClient )
@@ -426,7 +391,7 @@ public void testExecutable_OpenSearchPath_WithEmptyPrefix() throws Exception {
426391 // Arrange
427392 Mockito .when (platformAnalytics .isEnabled ()).thenReturn (true );
428393 Mockito .when (searchEngineType .isOpenSearch ()).thenReturn (true );
429- Mockito .when (index .getPrefix ()).thenReturn ("" ); // Empty prefix
394+ Mockito .when (index .getFinalPrefix ()).thenReturn ("" ); // Empty prefix
430395
431396 // Act
432397 Function <UpgradeContext , UpgradeStepResult > executable = step .executable ();
@@ -439,7 +404,7 @@ public void testExecutable_OpenSearchPath_WithEmptyPrefix() throws Exception {
439404
440405 // Verify OpenSearch path was taken and empty prefix was used
441406 Mockito .verify (searchEngineType ).isOpenSearch ();
442- Mockito .verify (index ). getPrefix ();
407+ Mockito .verify (index , atLeastOnce ()). getFinalPrefix ();
443408
444409 // Verify that the low-level requests were made with correct names (no underscore prefix)
445410 // Note: createIsmPolicy makes 2 calls - one for creation and one for update attempt
@@ -464,7 +429,7 @@ public void testExecutable_OpenSearchPath_WithNonEmptyPrefix() throws Exception
464429 // Arrange
465430 Mockito .when (platformAnalytics .isEnabled ()).thenReturn (true );
466431 Mockito .when (searchEngineType .isOpenSearch ()).thenReturn (true );
467- Mockito .when (index .getPrefix ()).thenReturn ("prod " ); // Non-empty prefix
432+ Mockito .when (index .getFinalPrefix ()).thenReturn ("prod_ " ); // Non-empty prefix
468433
469434 // Act
470435 Function <UpgradeContext , UpgradeStepResult > executable = step .executable ();
@@ -477,7 +442,7 @@ public void testExecutable_OpenSearchPath_WithNonEmptyPrefix() throws Exception
477442
478443 // Verify OpenSearch path was taken and non-empty prefix was used
479444 Mockito .verify (searchEngineType ).isOpenSearch ();
480- Mockito .verify (index ). getPrefix ();
445+ Mockito .verify (index , atLeastOnce ()). getFinalPrefix ();
481446
482447 // Verify that the low-level requests were made with correct names (with underscore prefix)
483448 // Note: createIsmPolicy makes 2 calls - one for creation and one for update attempt
0 commit comments