forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate FailingFieldPlugin to a single class (elastic#119302)
- Loading branch information
Showing
4 changed files
with
72 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/framework/src/main/java/org/elasticsearch/test/FailingFieldPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.test; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.mapper.OnScriptError; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.ScriptPlugin; | ||
import org.elasticsearch.script.LongFieldScript; | ||
import org.elasticsearch.script.ScriptContext; | ||
import org.elasticsearch.script.ScriptEngine; | ||
import org.elasticsearch.search.lookup.SearchLookup; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class FailingFieldPlugin extends Plugin implements ScriptPlugin { | ||
|
||
@Override | ||
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) { | ||
return new ScriptEngine() { | ||
@Override | ||
public String getType() { | ||
return "failing_field"; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <FactoryType> FactoryType compile( | ||
String name, | ||
String code, | ||
ScriptContext<FactoryType> context, | ||
Map<String, String> params | ||
) { | ||
return (FactoryType) new LongFieldScript.Factory() { | ||
@Override | ||
public LongFieldScript.LeafFactory newFactory( | ||
String fieldName, | ||
Map<String, Object> params, | ||
SearchLookup searchLookup, | ||
OnScriptError onScriptError | ||
) { | ||
return ctx -> new LongFieldScript(fieldName, params, searchLookup, onScriptError, ctx) { | ||
@Override | ||
public void execute() { | ||
throw new IllegalStateException("Accessing failing field"); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Set<ScriptContext<?>> getSupportedContexts() { | ||
return Set.of(LongFieldScript.CONTEXT); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters