Skip to content

Commit

Permalink
Addressed PR Comments
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Sep 22, 2023
1 parent e89914b commit 44da4d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CompletableFuture<WorkflowData> execute(List<WorkflowData> 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<String, Object> getContent() {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ public void setUp() throws Exception {

@Override
public Map<String, Object> getContent() {
// See CreateIndexRequest ParseFields for source of content keys needed
return Map.of("index-name", "demo", "type", "knn");
}

@Override
public Map<String, String> getParams() {
// See RestCreateIndexAction for source of param keys needed
return Map.of();
return Map.ofEntries(Map.entry("index-name", "demo"), Map.entry("type", "knn"));
}

};
Expand All @@ -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<String, Object> outputData = Map.of("index-name", "demo");
assertEquals(outputData, future.get().getContent());
Expand All @@ -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());
}
}
6 changes: 2 additions & 4 deletions src/test/resources/template/datademo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
"nodes": [
{
"id": "create_index",
"index_name": "demo",
"type": "knn"
"index_name": "demo"
},
{
"id": "create_another_index",
"index_name": "second_demo",
"type": "knn"
"index_name": "second_demo"
}
],
"edges": [
Expand Down

0 comments on commit 44da4d5

Please sign in to comment.