From 34ec1afa87613aa05891ef0c79d47ed69d422903 Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Fri, 22 Sep 2023 14:07:21 -0700 Subject: [PATCH] Addressed PR Comments Signed-off-by: Owais Kazi --- .../workflow/CreateIndex/CreateIndexStep.java | 4 ++-- .../CreateIndex/CreateIndexStepTests.java | 20 +++++++------------ src/test/resources/template/datademo.json | 8 ++------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStep.java b/src/main/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStep.java index 3d62e08f7..ebef2cae8 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStep.java @@ -51,7 +51,7 @@ public CompletableFuture execute(List data) { @Override public void onResponse(CreateIndexResponse createIndexResponse) { - logger.info("created index:{}", createIndexResponse.index()); + logger.info("created index: {}", createIndexResponse.index()); future.complete(new WorkflowData() { @Override public Map getContent() { @@ -108,7 +108,7 @@ public String getName() { * @return index mapping * @throws IOException IOException if mapping file can't be read correctly */ - public static String getIndexMappings(String mapping) throws IOException { + private static String getIndexMappings(String mapping) throws IOException { URL url = CreateIndexStep.class.getClassLoader().getResource(mapping); return Resources.toString(url, Charsets.UTF_8); } diff --git a/src/test/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStepTests.java b/src/test/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStepTests.java index e316ea7cb..638dea251 100644 --- a/src/test/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStepTests.java +++ b/src/test/java/org/opensearch/flowframework/workflow/CreateIndex/CreateIndexStepTests.java @@ -49,14 +49,7 @@ public void setUp() throws Exception { @Override public Map getContent() { - // See CreateIndexRequest ParseFields for source of content keys needed - return Map.of("index-name", "demo", "type", "knn"); - } - - @Override - public Map getParams() { - // See RestCreateIndexAction for source of param keys needed - return Map.of(); + return Map.ofEntries(Map.entry("index-name", "demo"), Map.entry("type", "knn")); } }; @@ -80,7 +73,7 @@ public void testCreateIndexStep() throws ExecutionException, InterruptedExceptio verify(indicesAdminClient, times(1)).create(any(CreateIndexRequest.class), actionListenerCaptor.capture()); actionListenerCaptor.getValue().onResponse(new CreateIndexResponse(true, true, "demo")); - assertTrue(future.isDone()); + assertTrue(future.isDone() && !future.isCompletedExceptionally()); Map outputData = Map.of("index-name", "demo"); assertEquals(outputData, future.get().getContent()); @@ -96,10 +89,11 @@ public void testCreateIndexStepFailure() throws ExecutionException, InterruptedE assertFalse(future.isDone()); verify(indicesAdminClient, times(1)).create(any(CreateIndexRequest.class), actionListenerCaptor.capture()); - actionListenerCaptor.getValue().onFailure(new Exception()); - - assertTrue(future.isDone()); - assertThrows(Exception.class, () -> future.get().getContent()); + actionListenerCaptor.getValue().onFailure(new Exception("Failed to create an index")); + assertTrue(future.isCompletedExceptionally()); + ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get().getContent()); + assertTrue(ex.getCause() instanceof Exception); + assertEquals("Failed to create an index", ex.getCause().getMessage()); } } diff --git a/src/test/resources/template/datademo.json b/src/test/resources/template/datademo.json index 79f79594a..5d30784cb 100644 --- a/src/test/resources/template/datademo.json +++ b/src/test/resources/template/datademo.json @@ -2,14 +2,10 @@ "sequence": { "nodes": [ { - "id": "create_index", - "index_name": "demo", - "type": "knn" + "id": "create_index" }, { - "id": "create_another_index", - "index_name": "second_demo", - "type": "knn" + "id": "create_another_index" } ], "edges": [