forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tested coordinated RFS index creation
Signed-off-by: Chris Helma <chelma+github@amazon.com>
- Loading branch information
Showing
5 changed files
with
598 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.rfs.worker; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.rfs.cms.CmsClient; | ||
import com.rfs.common.IndexMetadata; | ||
import com.rfs.common.RfsException; | ||
import com.rfs.transformers.Transformer; | ||
import com.rfs.version_os_2_11.IndexCreator_OS_2_11; | ||
|
||
public class IndexRunnerTest { | ||
|
||
@Test | ||
void run_encountersAnException_asExpected() { | ||
// Setup | ||
GlobalState globalState = Mockito.mock(GlobalState.class); | ||
CmsClient cmsClient = Mockito.mock(CmsClient.class); | ||
String snapshotName = "testSnapshot"; | ||
IndexMetadata.Factory metadataFactory = Mockito.mock(IndexMetadata.Factory.class); | ||
IndexCreator_OS_2_11 creator = Mockito.mock(IndexCreator_OS_2_11.class); | ||
Transformer transformer = Mockito.mock(Transformer.class); | ||
RfsException testException = new RfsException("Unit test"); | ||
|
||
doThrow(testException).when(cmsClient).getIndexEntry(); | ||
when(globalState.getPhase()).thenReturn(GlobalState.Phase.INDEX_IN_PROGRESS); | ||
|
||
// Run the test | ||
try { | ||
IndexRunner testRunner = new IndexRunner(globalState, cmsClient, snapshotName, metadataFactory, creator, transformer); | ||
testRunner.run(); | ||
} catch (IndexRunner.IndexMigrationPhaseFailed e) { | ||
assertEquals(GlobalState.Phase.INDEX_IN_PROGRESS, e.phase); | ||
assertEquals(IndexStep.GetEntry.class, e.nextStep.getClass()); | ||
assertEquals(Optional.empty(), e.cmsEntry); | ||
assertEquals(testException, e.e); | ||
|
||
} catch (Exception e) { | ||
fail("Unexpected exception thrown: " + e.getClass().getName()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.