Skip to content

Commit

Permalink
Fix type cast in test
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chu <[email protected]>
  • Loading branch information
noCharger committed May 18, 2023
1 parent 499f0d5 commit 110b4c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* {@link SearchSourceBuilder}. The class allows retrieving and modifying specific properties of the search request.
*/
public class SearchRequestMap implements Map<String, Object> {
private static final String UNSUPPORTED_OP_ERR = "Method not supported in Search pipeline script";
private static final String UNSUPPORTED_OP_ERR = " Method not supported in Search pipeline script";

private final SearchSourceBuilder source;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import org.opensearch.script.ScriptType;
import org.opensearch.script.SearchScript;
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.search.pipeline.common.helpers.SearchRequestMap;
import org.opensearch.test.AbstractBuilderTestCase;

import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.stream.Collectors;

public class ScriptProcessorTest extends AbstractBuilderTestCase {

Expand All @@ -30,14 +32,17 @@ public void testScriptProcessor() throws Exception {
String scriptName = "test-search-script";
ScriptService scriptService = new ScriptService(
Settings.builder().build(),
Collections.singletonMap(
Map.of(
Script.DEFAULT_SCRIPT_LANG,
new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, Collections.singletonMap(scriptName, ctx -> {
Object source = ctx.get("source");
if (source instanceof Map) {
Map<String, Object> sourceMap = (Map<String, Object>) ctx.get("source");
Integer size = (Integer) sourceMap.get("size");
sourceMap.put("size", size + 99);
new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, Map.of(scriptName, ctx -> {
Object sourceObj = ctx.get("source");
if (sourceObj instanceof Map) {
Map<String, Object> source = (SearchRequestMap) sourceObj;
Object sizeObj = source.get("size");
if(sizeObj instanceof Integer) {
Integer size = (Integer) sizeObj;
source.put("size", size + 99);
}
}
return null;
}), Collections.emptyMap())
Expand Down

0 comments on commit 110b4c7

Please sign in to comment.