Skip to content

Commit

Permalink
Increasing test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <[email protected]>
  • Loading branch information
joshpalis committed Aug 16, 2024
1 parent d02955b commit 9e4e61d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/opensearch/flowframework/util/ParseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,20 @@ public static void flattenSettings(String prefix, Map<String, Object> settings,
}
}
}

/**
* Ensures index is prepended to flattened setting keys
* @param originalSettings the original settings map
*/
public static Map<String, Object> prependIndexToSettings(Map<String, Object> originalSettings) {
Map<String, Object> newSettings = new HashMap<>();
originalSettings.entrySet().stream().forEach(x -> {
if (!x.getKey().startsWith("index.")) {
newSettings.put("index." + x.getKey(), x.getValue());
} else {
newSettings.put(x.getKey(), x.getValue());
}
});
return newSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ public PlainActionFuture<WorkflowData> execute(
} else {
// Create index setting configuration can be a mix of flattened or expanded settings
// prepend index. to ensure successful setting comparison
updatedSettings.entrySet().stream().forEach(x -> {
if (!x.getKey().startsWith("index.")) {
flattenedSettings.put("index." + x.getKey(), x.getValue());
} else {
flattenedSettings.put(x.getKey(), x.getValue());
}
});

flattenedSettings.putAll(ParseUtils.prependIndexToSettings(updatedSettings));
}

Map<String, Object> filteredSettings = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,21 @@ public void testFlattenSettings() throws Exception {
assertTrue(flattenedSettings.entrySet().stream().allMatch(x -> x.getKey().startsWith("index.")));

}

public void testPrependIndexToSettings() throws Exception {

Map<String, Object> indexSettingsMap = Map.ofEntries(
Map.entry("knn", "true"),
Map.entry("number_of_shards", "2"),
Map.entry("number_of_replicas", "1"),
Map.entry("default_pipeline", "_none"),
Map.entry("search", Map.of("default_pipeine", "_none"))
);
Map<String, Object> prependedSettings = ParseUtils.prependIndexToSettings(indexSettingsMap);
assertEquals(5, prependedSettings.size());

// every setting should start with index
assertTrue(prependedSettings.entrySet().stream().allMatch(x -> x.getKey().startsWith("index.")));

}
}

0 comments on commit 9e4e61d

Please sign in to comment.