Permalink
Browse files

Merge pull request #178 from zznate/javascript_context_fix

In different threads you have to enter the context
  • Loading branch information...
zznate committed Apr 2, 2013
2 parents 179d983 + 242d34f commit fd936612b366a27dccdd5876a47af54844bd74df
@@ -1,5 +1,6 @@
package org.usergrid.vx.server.operations;
+import org.mozilla.javascript.Context;
import org.usergrid.vx.experimental.filter.Filter;
import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.Message;
@@ -19,6 +20,7 @@ public FilterHandler(Filter filter) {
@Override
public void handle(Message<JsonArray> event) {
JsonArray filteredArray = new JsonArray();
+ Context context = Context.enter();
for (Object obj : event.body) {
JsonObject jsonObject = (JsonObject) obj;
Map filtered = filter.filter(jsonObject.toMap());
@@ -65,7 +65,7 @@ public void executeClojureFilter() throws Exception {
Assert.assertEquals(1, results.size());
}
- @Ignore
+
@Test
/* why wont this work */
public void executeJavaScriptPhoneFilter() throws Exception {
@@ -78,15 +78,10 @@ public void executeJavaScriptPhoneFilter() throws Exception {
req.add(Operations.assumeOp("jsFilterks2", "filtercf2", "value", "UTF8Type"));//5
req.add(Operations.setOp("rowa", "col1", "{ \"last\" : \"Peters\", \"first\" : \"john\", \"pnumber\": \"914-555-5555\" }")); //6
req.add(Operations.setOp("rowa", "col2", "{ \"last\" : \"Peters2\", \"first\" : \"john\", \"pnumber\": \"915-555-5555\" }")); //6
- /*
req.add(Operations.createFilterOp("over22", "javascript",
"function over22(row) { x = JSON.parse( row['value'], null ); \n" +
"if ( String(x.pnumber).search(\"914\") != -1 ) { return row } else { return null } \n" +
"}")); // 8
- */
- //req.add(Operations.sliceOp("rowa", "col1", "col3", 10)); //10
- req.add(Operations.createFilterOp("over22", "javascript",
- "function over22(row) { if ( /914/.test(row['value']) ) {return row;} else {return null;} } " )); // 8
req.add(Operations.filterModeOp("over22", true)); //9
req.add(Operations.sliceOp("rowa", "col1", "col3", 10)); //10
IntraClient2 ic2 = new IntraClient2("localhost", 8080);
@@ -95,7 +90,7 @@ public void executeJavaScriptPhoneFilter() throws Exception {
List<Map> results = (List<Map>) res.getOpsRes().get(10);
System.out.println(results);
- Assert.assertEquals("22", results.get(0).get("value"));
+ Assert.assertEquals("{ \"last\" : \"Peters\", \"first\" : \"john\", \"pnumber\": \"914-555-5555\" }", results.get(0).get("value"));
Assert.assertEquals(1, results.size());
}

0 comments on commit fd93661

Please sign in to comment.