mirror of https://github.com/apache/lucene.git
SOLR-4634: Fix scripting engine tests to work with Java 8's "Nashorn" Javascript implementation
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1460069 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a3692c23dd
commit
bf368745b9
|
@ -78,6 +78,9 @@ Bug Fixes
|
||||||
* SOLR-4543: setting shardHandlerFactory in solr.xml/solr.properties does not work.
|
* SOLR-4543: setting shardHandlerFactory in solr.xml/solr.properties does not work.
|
||||||
(Ryan Ernst, Robert Muir via Erick Erickson)
|
(Ryan Ernst, Robert Muir via Erick Erickson)
|
||||||
|
|
||||||
|
* SOLR-4634: Fix scripting engine tests to work with Java 8's "Nashorn" Javascript
|
||||||
|
implementation. (Uwe Schindler)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
|
||||||
EntityProcessorWrapper sep = new EntityProcessorWrapper(new SqlEntityProcessor(), null, null);
|
EntityProcessorWrapper sep = new EntityProcessorWrapper(new SqlEntityProcessor(), null, null);
|
||||||
sep.init(context);
|
sep.init(context);
|
||||||
sep.applyTransformer(map);
|
sep.applyTransformer(map);
|
||||||
assertEquals(map.get("name"), "Hello Scott");
|
assertEquals("Hello Scott", map.get("name").toString());
|
||||||
} catch (DataImportHandlerException e) {
|
} catch (DataImportHandlerException e) {
|
||||||
assumeFalse("This JVM does not have Rhino installed. Test Skipped.", e
|
assumeFalse("This JVM does not have JavaScript installed. Test Skipped.", e
|
||||||
.getMessage().startsWith("Cannot load Script Engine for language"));
|
.getMessage().startsWith("Cannot load Script Engine for language"));
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -86,9 +86,9 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
|
||||||
EntityProcessorWrapper sep = new EntityProcessorWrapper(new SqlEntityProcessor(), null, null);
|
EntityProcessorWrapper sep = new EntityProcessorWrapper(new SqlEntityProcessor(), null, null);
|
||||||
sep.init(context);
|
sep.init(context);
|
||||||
sep.applyTransformer(map);
|
sep.applyTransformer(map);
|
||||||
assertEquals(map.get("name"), "Hello Scott");
|
assertEquals("Hello Scott", map.get("name").toString());
|
||||||
} catch (DataImportHandlerException e) {
|
} catch (DataImportHandlerException e) {
|
||||||
assumeFalse("This JVM does not have Rhino installed. Test Skipped.", e
|
assumeFalse("This JVM does not have JavaScript installed. Test Skipped.", e
|
||||||
.getMessage().startsWith("Cannot load Script Engine for language"));
|
.getMessage().startsWith("Cannot load Script Engine for language"));
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
|
||||||
DIHConfiguration dc = di.readFromXml(document);
|
DIHConfiguration dc = di.readFromXml(document);
|
||||||
assertTrue(dc.getScript().getText().indexOf("checkNextToken") > -1);
|
assertTrue(dc.getScript().getText().indexOf("checkNextToken") > -1);
|
||||||
} catch (DataImportHandlerException e) {
|
} catch (DataImportHandlerException e) {
|
||||||
assumeFalse("This JVM does not have Rhino installed. Test Skipped.", e
|
assumeFalse("This JVM does not have JavaScript installed. Test Skipped.", e
|
||||||
.getMessage().startsWith("Cannot load Script Engine for language"));
|
.getMessage().startsWith("Cannot load Script Engine for language"));
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
|
||||||
sep.applyTransformer(map);
|
sep.applyTransformer(map);
|
||||||
assertNull(map.get("$hasMore"));
|
assertNull(map.get("$hasMore"));
|
||||||
} catch (DataImportHandlerException e) {
|
} catch (DataImportHandlerException e) {
|
||||||
assumeFalse("This JVM does not have Rhino installed. Test Skipped.", e
|
assumeFalse("This JVM does not have JavaScript installed. Test Skipped.", e
|
||||||
.getMessage().startsWith("Cannot load Script Engine for language"));
|
.getMessage().startsWith("Cannot load Script Engine for language"));
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
|
var Assert = Packages.org.junit.Assert;
|
||||||
|
|
||||||
function processAdd(cmd) {
|
function processAdd(cmd) {
|
||||||
functionMessages.add("processAdd0");
|
functionMessages.add("processAdd0");
|
||||||
testCase.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
testCase.assertNotNull(rsp);
|
Assert.assertNotNull(rsp);
|
||||||
testCase.assertNotNull(logger);
|
Assert.assertNotNull(logger);
|
||||||
testCase.assertNotNull(cmd);
|
Assert.assertNotNull(cmd);
|
||||||
testCase.assertNotNull(params);
|
Assert.assertNotNull(params);
|
||||||
testCase.assertTrue(1 == params.get('intValue').intValue()); // had issues with assertTrue(1, params.get('intValue').intValue()) casting to wrong variant
|
Assert.assertTrue(1 == params.get('intValue').intValue()); // had issues with assertTrue(1, params.get('intValue').intValue()) casting to wrong variant
|
||||||
testCase.assertTrue(params.get('boolValue').booleanValue());
|
Assert.assertTrue(params.get('boolValue').booleanValue());
|
||||||
|
|
||||||
// Integer.valueOf is needed here to get a tru java object, because
|
// Integer.valueOf is needed here to get a tru java object, because
|
||||||
// all javascript numbers are floating point (ie: java.lang.Double)
|
// all javascript numbers are floating point (ie: java.lang.Double)
|
||||||
|
@ -18,40 +20,40 @@ function processAdd(cmd) {
|
||||||
|
|
||||||
function processDelete(cmd) {
|
function processDelete(cmd) {
|
||||||
functionMessages.add("processDelete0");
|
functionMessages.add("processDelete0");
|
||||||
testCase.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
testCase.assertNotNull(rsp);
|
Assert.assertNotNull(rsp);
|
||||||
testCase.assertNotNull(logger);
|
Assert.assertNotNull(logger);
|
||||||
testCase.assertNotNull(cmd);
|
Assert.assertNotNull(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processMergeIndexes(cmd) {
|
function processMergeIndexes(cmd) {
|
||||||
functionMessages.add("processMergeIndexes0");
|
functionMessages.add("processMergeIndexes0");
|
||||||
testCase.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
testCase.assertNotNull(rsp);
|
Assert.assertNotNull(rsp);
|
||||||
testCase.assertNotNull(logger);
|
Assert.assertNotNull(logger);
|
||||||
testCase.assertNotNull(cmd);
|
Assert.assertNotNull(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processCommit(cmd) {
|
function processCommit(cmd) {
|
||||||
functionMessages.add("processCommit0");
|
functionMessages.add("processCommit0");
|
||||||
testCase.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
testCase.assertNotNull(rsp);
|
Assert.assertNotNull(rsp);
|
||||||
testCase.assertNotNull(logger);
|
Assert.assertNotNull(logger);
|
||||||
testCase.assertNotNull(cmd);
|
Assert.assertNotNull(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processRollback(cmd) {
|
function processRollback(cmd) {
|
||||||
functionMessages.add("processRollback0");
|
functionMessages.add("processRollback0");
|
||||||
testCase.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
testCase.assertNotNull(rsp);
|
Assert.assertNotNull(rsp);
|
||||||
testCase.assertNotNull(logger);
|
Assert.assertNotNull(logger);
|
||||||
testCase.assertNotNull(cmd);
|
Assert.assertNotNull(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
function finish() {
|
function finish() {
|
||||||
functionMessages.add("finish0");
|
functionMessages.add("finish0");
|
||||||
testCase.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
testCase.assertNotNull(rsp);
|
Assert.assertNotNull(rsp);
|
||||||
testCase.assertNotNull(logger);
|
Assert.assertNotNull(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class ScriptEngineTest extends LuceneTestCase {
|
||||||
ScriptEngine engine = manager.getEngineByName("JavaScript");
|
ScriptEngine engine = manager.getEngineByName("JavaScript");
|
||||||
assertNotNull(engine);
|
assertNotNull(engine);
|
||||||
engine.eval("function add(a,b) { return a + b }");
|
engine.eval("function add(a,b) { return a + b }");
|
||||||
Double result = (Double) ((Invocable)engine).invokeFunction("add", 1, 2);
|
Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(3, result.intValue());
|
assertEquals(3, result.intValue());
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public class ScriptEngineTest extends LuceneTestCase {
|
||||||
assertNotNull(engine);
|
assertNotNull(engine);
|
||||||
StringReader reader = new StringReader("function add(a,b) { return a + b }");
|
StringReader reader = new StringReader("function add(a,b) { return a + b }");
|
||||||
engine.eval(reader);
|
engine.eval(reader);
|
||||||
Double result = (Double) ((Invocable)engine).invokeFunction("add", 1, 2);
|
Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(3, result.intValue());
|
assertEquals(3, result.intValue());
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public class ScriptEngineTest extends LuceneTestCase {
|
||||||
engine.put("b", 2);
|
engine.put("b", 2);
|
||||||
assertNotNull(engine);
|
assertNotNull(engine);
|
||||||
engine.eval("function add() { return a + b }");
|
engine.eval("function add() { return a + b }");
|
||||||
Double result = (Double) ((Invocable)engine).invokeFunction("add", 1, 2);
|
Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(3, result.intValue());
|
assertEquals(3, result.intValue());
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class ScriptEngineTest extends LuceneTestCase {
|
||||||
|
|
||||||
assertNotNull(engine);
|
assertNotNull(engine);
|
||||||
engine.eval("def add(a,b); a + b; end");
|
engine.eval("def add(a,b); a + b; end");
|
||||||
Long result = (Long) ((Invocable)engine).invokeFunction("add", 1, 2);
|
Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(3, result.intValue());
|
assertEquals(3, result.intValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,6 @@ public class StatelessScriptUpdateProcessorFactoryTest extends UpdateProcessorTe
|
||||||
factory.setScriptEngineCustomizer(new ScriptEngineCustomizer() {
|
factory.setScriptEngineCustomizer(new ScriptEngineCustomizer() {
|
||||||
@Override
|
@Override
|
||||||
public void customize(ScriptEngine engine) {
|
public void customize(ScriptEngine engine) {
|
||||||
engine.put("testCase", StatelessScriptUpdateProcessorFactoryTest.this);
|
|
||||||
engine.put("functionMessages", functionMessages);
|
engine.put("functionMessages", functionMessages);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -127,7 +126,6 @@ public class StatelessScriptUpdateProcessorFactoryTest extends UpdateProcessorTe
|
||||||
ScriptEngineCustomizer customizer = new ScriptEngineCustomizer() {
|
ScriptEngineCustomizer customizer = new ScriptEngineCustomizer() {
|
||||||
@Override
|
@Override
|
||||||
public void customize(ScriptEngine engine) {
|
public void customize(ScriptEngine engine) {
|
||||||
engine.put("testCase", StatelessScriptUpdateProcessorFactoryTest.this);
|
|
||||||
engine.put("functionMessages", functionMessages);
|
engine.put("functionMessages", functionMessages);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue