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:
Uwe Schindler 2013-03-23 00:53:25 +00:00
parent a3692c23dd
commit bf368745b9
5 changed files with 41 additions and 38 deletions

View File

@ -78,6 +78,9 @@ Bug Fixes
* SOLR-4543: setting shardHandlerFactory in solr.xml/solr.properties does not work.
(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
----------------------

View File

@ -53,9 +53,9 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
EntityProcessorWrapper sep = new EntityProcessorWrapper(new SqlEntityProcessor(), null, null);
sep.init(context);
sep.applyTransformer(map);
assertEquals(map.get("name"), "Hello Scott");
assertEquals("Hello Scott", map.get("name").toString());
} 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"));
throw e;
}
@ -86,9 +86,9 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
EntityProcessorWrapper sep = new EntityProcessorWrapper(new SqlEntityProcessor(), null, null);
sep.init(context);
sep.applyTransformer(map);
assertEquals(map.get("name"), "Hello Scott");
assertEquals("Hello Scott", map.get("name").toString());
} 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"));
throw e;
}
@ -104,7 +104,7 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
DIHConfiguration dc = di.readFromXml(document);
assertTrue(dc.getScript().getText().indexOf("checkNextToken") > -1);
} 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"));
throw e;
}
@ -131,7 +131,7 @@ public class TestScriptTransformer extends AbstractDataImportHandlerTestCase {
sep.applyTransformer(map);
assertNull(map.get("$hasMore"));
} 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"));
throw e;
}

View File

@ -1,12 +1,14 @@
var Assert = Packages.org.junit.Assert;
function processAdd(cmd) {
functionMessages.add("processAdd0");
testCase.assertNotNull(req);
testCase.assertNotNull(rsp);
testCase.assertNotNull(logger);
testCase.assertNotNull(cmd);
testCase.assertNotNull(params);
testCase.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.assertNotNull(req);
Assert.assertNotNull(rsp);
Assert.assertNotNull(logger);
Assert.assertNotNull(cmd);
Assert.assertNotNull(params);
Assert.assertTrue(1 == params.get('intValue').intValue()); // had issues with assertTrue(1, params.get('intValue').intValue()) casting to wrong variant
Assert.assertTrue(params.get('boolValue').booleanValue());
// Integer.valueOf is needed here to get a tru java object, because
// all javascript numbers are floating point (ie: java.lang.Double)
@ -18,40 +20,40 @@ function processAdd(cmd) {
function processDelete(cmd) {
functionMessages.add("processDelete0");
testCase.assertNotNull(req);
testCase.assertNotNull(rsp);
testCase.assertNotNull(logger);
testCase.assertNotNull(cmd);
Assert.assertNotNull(req);
Assert.assertNotNull(rsp);
Assert.assertNotNull(logger);
Assert.assertNotNull(cmd);
}
function processMergeIndexes(cmd) {
functionMessages.add("processMergeIndexes0");
testCase.assertNotNull(req);
testCase.assertNotNull(rsp);
testCase.assertNotNull(logger);
testCase.assertNotNull(cmd);
Assert.assertNotNull(req);
Assert.assertNotNull(rsp);
Assert.assertNotNull(logger);
Assert.assertNotNull(cmd);
}
function processCommit(cmd) {
functionMessages.add("processCommit0");
testCase.assertNotNull(req);
testCase.assertNotNull(rsp);
testCase.assertNotNull(logger);
testCase.assertNotNull(cmd);
Assert.assertNotNull(req);
Assert.assertNotNull(rsp);
Assert.assertNotNull(logger);
Assert.assertNotNull(cmd);
}
function processRollback(cmd) {
functionMessages.add("processRollback0");
testCase.assertNotNull(req);
testCase.assertNotNull(rsp);
testCase.assertNotNull(logger);
testCase.assertNotNull(cmd);
Assert.assertNotNull(req);
Assert.assertNotNull(rsp);
Assert.assertNotNull(logger);
Assert.assertNotNull(cmd);
}
function finish() {
functionMessages.add("finish0");
testCase.assertNotNull(req);
testCase.assertNotNull(rsp);
testCase.assertNotNull(logger);
Assert.assertNotNull(req);
Assert.assertNotNull(rsp);
Assert.assertNotNull(logger);
}

View File

@ -69,7 +69,7 @@ public class ScriptEngineTest extends LuceneTestCase {
ScriptEngine engine = manager.getEngineByName("JavaScript");
assertNotNull(engine);
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);
assertEquals(3, result.intValue());
}
@ -79,7 +79,7 @@ public class ScriptEngineTest extends LuceneTestCase {
assertNotNull(engine);
StringReader reader = new StringReader("function add(a,b) { return a + b }");
engine.eval(reader);
Double result = (Double) ((Invocable)engine).invokeFunction("add", 1, 2);
Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2);
assertNotNull(result);
assertEquals(3, result.intValue());
}
@ -90,7 +90,7 @@ public class ScriptEngineTest extends LuceneTestCase {
engine.put("b", 2);
assertNotNull(engine);
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);
assertEquals(3, result.intValue());
}
@ -103,7 +103,7 @@ public class ScriptEngineTest extends LuceneTestCase {
assertNotNull(engine);
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);
assertEquals(3, result.intValue());
}

View File

@ -81,7 +81,6 @@ public class StatelessScriptUpdateProcessorFactoryTest extends UpdateProcessorTe
factory.setScriptEngineCustomizer(new ScriptEngineCustomizer() {
@Override
public void customize(ScriptEngine engine) {
engine.put("testCase", StatelessScriptUpdateProcessorFactoryTest.this);
engine.put("functionMessages", functionMessages);
}
});
@ -127,7 +126,6 @@ public class StatelessScriptUpdateProcessorFactoryTest extends UpdateProcessorTe
ScriptEngineCustomizer customizer = new ScriptEngineCustomizer() {
@Override
public void customize(ScriptEngine engine) {
engine.put("testCase", StatelessScriptUpdateProcessorFactoryTest.this);
engine.put("functionMessages", functionMessages);
}
};