[TEST] fix failing script REST tests

This commit is contained in:
Colin Goodheart-Smithe 2015-06-01 11:29:05 +01:00
parent d453699643
commit ee08ab6c5c
6 changed files with 29 additions and 10 deletions

View File

@ -636,6 +636,7 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
public UpdateRequest source(BytesReference source) throws Exception { public UpdateRequest source(BytesReference source) throws Exception {
ScriptParameterParser scriptParameterParser = new ScriptParameterParser(); ScriptParameterParser scriptParameterParser = new ScriptParameterParser();
Map<String, Object> scriptParams = null; Map<String, Object> scriptParams = null;
Script script = null;
XContentType xContentType = XContentFactory.xContentType(source); XContentType xContentType = XContentFactory.xContentType(source);
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(source)) { try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(source)) {
XContentParser.Token token = parser.nextToken(); 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); script = new Script(scriptValue.script(), scriptValue.scriptType(), scriptParameterParser.lang(), scriptParams);
} }
} }
if (script != null) {
this.script = script;
}
} }
return this; return this;
} }

View File

@ -96,6 +96,15 @@ public class TemplateQueryParser implements QueryParser {
return parse(parser, parameterMap); 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 { public static Template parse(XContentParser parser) throws IOException {
return parse(parser, parametersToTypes); return parse(parser, parametersToTypes);
} }

View File

@ -125,7 +125,7 @@ public abstract class AbstractScriptParser<S extends Script> {
return null; return null;
} }
public Script parse(Map<String, Object> config, boolean removeMatchedEntries) { public S parse(Map<String, Object> config, boolean removeMatchedEntries) {
String script = null; String script = null;
ScriptType type = null; ScriptType type = null;
String lang = null; String lang = null;

View File

@ -25,6 +25,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification; import com.google.common.cache.RemovalNotification;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteRequest;
@ -317,7 +318,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
try { try {
XContentParser parser = XContentFactory.xContent(scriptBytes).createParser(scriptBytes); XContentParser parser = XContentFactory.xContent(scriptBytes).createParser(scriptBytes);
parser.nextToken(); parser.nextToken();
Template template = TemplateQueryParser.parse(parser, "params", "script", "template"); Template template = TemplateQueryParser.parse(scriptLang, parser, "params", "script", "template");
if (Strings.hasLength(template.getScript())) { if (Strings.hasLength(template.getScript())) {
//Just try and compile it //Just try and compile it
//This will have the benefit of also adding the script to the cache if it compiles //This will have the benefit of also adding the script to the cache if it compiles

View File

@ -120,17 +120,22 @@ public class Template extends Script {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Script parse(Map<String, Object> config, boolean removeMatchedEntries) { 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") @SuppressWarnings("unchecked")
public static Template parse(XContentParser parser) throws IOException { 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 @Deprecated
public static Template parse(XContentParser parser, Map<String, ScriptType> additionalTemplateFieldNames) throws IOException { 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 @Override
@ -159,9 +164,11 @@ public class Template extends Script {
private XContentType contentType = null; private XContentType contentType = null;
private final Map<String, ScriptType> additionalTemplateFieldNames; 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.additionalTemplateFieldNames = additionalTemplateFieldNames;
this.defaultLang = defaultLang;
} }
@Override @Override
@ -171,7 +178,7 @@ public class Template extends Script {
@Override @Override
protected Template createScript(String script, ScriptType type, String lang, Map<String, Object> params) { 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 @Override
@ -192,7 +199,7 @@ public class Template extends Script {
@Override @Override
protected String getDefaultScriptLang() { protected String getDefaultScriptLang() {
return MustacheScriptEngineService.NAME; return defaultLang;
} }
} }
} }

View File

@ -25,7 +25,6 @@ import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.lucene.util.IOUtils; 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.Slow;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.LuceneTestCase.SuppressFsync; import org.apache.lucene.util.LuceneTestCase.SuppressFsync;
@ -85,7 +84,6 @@ import java.util.Set;
@SuppressCodecs("*") // requires custom completion postings format @SuppressCodecs("*") // requires custom completion postings format
@ClusterScope(randomDynamicTemplates = false) @ClusterScope(randomDynamicTemplates = false)
@TimeoutSuite(millis = 40 * TimeUnits.MINUTE) // timeout the suite after 40min and fail the test. @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 { public abstract class ElasticsearchRestTestCase extends ElasticsearchIntegrationTest {
/** /**