[TEST] fix failing script REST tests
This commit is contained in:
parent
d453699643
commit
ee08ab6c5c
|
@ -636,6 +636,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
public UpdateRequest source(BytesReference source) throws Exception {
|
||||
ScriptParameterParser scriptParameterParser = new ScriptParameterParser();
|
||||
Map<String, Object> scriptParams = null;
|
||||
Script script = null;
|
||||
XContentType xContentType = XContentFactory.xContentType(source);
|
||||
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(source)) {
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
|
@ -675,6 +676,9 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
script = new Script(scriptValue.script(), scriptValue.scriptType(), scriptParameterParser.lang(), scriptParams);
|
||||
}
|
||||
}
|
||||
if (script != null) {
|
||||
this.script = script;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -96,6 +96,15 @@ public class TemplateQueryParser implements QueryParser {
|
|||
return parse(parser, parameterMap);
|
||||
}
|
||||
|
||||
public static Template parse(String defaultLang, XContentParser parser, String... parameters) throws IOException {
|
||||
|
||||
Map<String, ScriptService.ScriptType> parameterMap = new HashMap<>(parametersToTypes);
|
||||
for (String parameter : parameters) {
|
||||
parameterMap.put(parameter, ScriptService.ScriptType.INLINE);
|
||||
}
|
||||
return Template.parse(parser, parameterMap, defaultLang);
|
||||
}
|
||||
|
||||
public static Template parse(XContentParser parser) throws IOException {
|
||||
return parse(parser, parametersToTypes);
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ public abstract class AbstractScriptParser<S extends Script> {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Script parse(Map<String, Object> config, boolean removeMatchedEntries) {
|
||||
public S parse(Map<String, Object> config, boolean removeMatchedEntries) {
|
||||
String script = null;
|
||||
ScriptType type = null;
|
||||
String lang = null;
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.google.common.cache.CacheBuilder;
|
|||
import com.google.common.cache.RemovalListener;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
|
@ -317,7 +318,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
|
|||
try {
|
||||
XContentParser parser = XContentFactory.xContent(scriptBytes).createParser(scriptBytes);
|
||||
parser.nextToken();
|
||||
Template template = TemplateQueryParser.parse(parser, "params", "script", "template");
|
||||
Template template = TemplateQueryParser.parse(scriptLang, parser, "params", "script", "template");
|
||||
if (Strings.hasLength(template.getScript())) {
|
||||
//Just try and compile it
|
||||
//This will have the benefit of also adding the script to the cache if it compiles
|
||||
|
|
|
@ -120,17 +120,22 @@ public class Template extends Script {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Script parse(Map<String, Object> config, boolean removeMatchedEntries) {
|
||||
return new TemplateParser(Collections.EMPTY_MAP).parse(config, removeMatchedEntries);
|
||||
return new TemplateParser(Collections.EMPTY_MAP, MustacheScriptEngineService.NAME).parse(config, removeMatchedEntries);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Template parse(XContentParser parser) throws IOException {
|
||||
return new TemplateParser(Collections.EMPTY_MAP).parse(parser);
|
||||
return new TemplateParser(Collections.EMPTY_MAP, MustacheScriptEngineService.NAME).parse(parser);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Template parse(XContentParser parser, Map<String, ScriptType> additionalTemplateFieldNames) throws IOException {
|
||||
return new TemplateParser(additionalTemplateFieldNames).parse(parser);
|
||||
return new TemplateParser(additionalTemplateFieldNames, MustacheScriptEngineService.NAME).parse(parser);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Template parse(XContentParser parser, Map<String, ScriptType> additionalTemplateFieldNames, String defaultLang) throws IOException {
|
||||
return new TemplateParser(additionalTemplateFieldNames, defaultLang).parse(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -159,9 +164,11 @@ public class Template extends Script {
|
|||
|
||||
private XContentType contentType = null;
|
||||
private final Map<String, ScriptType> additionalTemplateFieldNames;
|
||||
private String defaultLang;
|
||||
|
||||
public TemplateParser(Map<String, ScriptType> additionalTemplateFieldNames) {
|
||||
public TemplateParser(Map<String, ScriptType> additionalTemplateFieldNames, String defaultLang) {
|
||||
this.additionalTemplateFieldNames = additionalTemplateFieldNames;
|
||||
this.defaultLang = defaultLang;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -171,7 +178,7 @@ public class Template extends Script {
|
|||
|
||||
@Override
|
||||
protected Template createScript(String script, ScriptType type, String lang, Map<String, Object> params) {
|
||||
return new Template(script, type, lang == null ? MustacheScriptEngineService.NAME : lang, contentType, params);
|
||||
return new Template(script, type, lang, contentType, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -192,7 +199,7 @@ public class Template extends Script {
|
|||
|
||||
@Override
|
||||
protected String getDefaultScriptLang() {
|
||||
return MustacheScriptEngineService.NAME;
|
||||
return defaultLang;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
|
|||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
||||
import org.apache.lucene.util.LuceneTestCase.SuppressFsync;
|
||||
|
@ -85,7 +84,6 @@ import java.util.Set;
|
|||
@SuppressCodecs("*") // requires custom completion postings format
|
||||
@ClusterScope(randomDynamicTemplates = false)
|
||||
@TimeoutSuite(millis = 40 * TimeUnits.MINUTE) // timeout the suite after 40min and fail the test.
|
||||
@AwaitsFix(bugUrl = "script/10_basic/Indexed script and update/15_script/Script fail due to commit 35a58d874ef56be50a0ad1d7bfb13edb4204d0a3")
|
||||
public abstract class ElasticsearchRestTestCase extends ElasticsearchIntegrationTest {
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue