Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4634: Fix scripting engine tests to work with Java 8's "Nashorn" Javascript implementation

Uwe Schindlerbf368745b96a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 46c88b07639..f259522e558 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
----------------------
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestScriptTransformer.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestScriptTransformer.java
index 79aa3c20c7a..cf08bb97902 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestScriptTransformer.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestScriptTransformer.java
@@ -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;
}
diff --git a/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js b/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js
index 72bb102e0c0..b1856b15d85 100644
--- a/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js
+++ b/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js
@@ -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);
}
diff --git a/solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java b/solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java
index d186bd5be49..4fb644cb5c3 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java
@@ -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());
}
diff --git a/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java b/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java
index 8c125b63e3a..9dad69cbdfb 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java
@@ -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);
}
};