You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2008/08/10 23:48:39 UTC
svn commit: r684600 - in /cxf/trunk/rt/javascript/src/test:
java/org/apache/cxf/javascript/GreeterClientTest.java
java/org/apache/cxf/javascript/JavascriptTestUtilities.java
resources/org/apache/cxf/javascript/GreeterTests.js
Author: bimargulies
Date: Sun Aug 10 14:48:38 2008
New Revision: 684600
URL: http://svn.apache.org/viewvc?rev=684600&view=rev
Log:
Fix multi-request test to use a CountDownLatch and avoid invalid order assumptions.
Modified:
cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GreeterClientTest.java
cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/GreeterTests.js
Modified: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GreeterClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GreeterClientTest.java?rev=684600&r1=684599&r2=684600&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GreeterClientTest.java (original)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/GreeterClientTest.java Sun Aug 10 14:48:38 2008
@@ -22,6 +22,7 @@
import java.io.File;
import java.net.URL;
+import org.apache.cxf.javascript.JavascriptTestUtilities.CountDownNotifier;
import org.apache.cxf.javascript.JavascriptTestUtilities.JSRunnable;
import org.apache.cxf.javascript.JavascriptTestUtilities.Notifier;
import org.junit.Before;
@@ -84,8 +85,8 @@
}
private Void sayHiClosureCaller(Context context) {
- Notifier notifier =
- testUtilities.rhinoCallConvert("requestClosureTest", Notifier.class,
+ CountDownNotifier notifier =
+ testUtilities.rhinoCallConvert("requestClosureTest", CountDownNotifier.class,
testUtilities.javaToJS(getAddress()));
boolean notified = notifier.waitForJavascript(1000 * 10);
Modified: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java?rev=684600&r1=684599&r2=684600&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java (original)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/JavascriptTestUtilities.java Sun Aug 10 14:48:38 2008
@@ -23,6 +23,8 @@
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
@@ -124,6 +126,42 @@
// CHECKSTYLE:ON
}
+ public static class CountDownNotifier extends ScriptableObject {
+
+ private CountDownLatch latch;
+
+ public CountDownNotifier() {
+ }
+
+ @Override
+ public String getClassName() {
+ return "org_apache_cxf_count_down_notifier";
+ }
+
+ public synchronized boolean waitForJavascript(long timeout) {
+ while (true) {
+ try {
+ return latch.await(timeout, TimeUnit.MILLISECONDS);
+ // if it returns at all, we're done.
+ } catch (InterruptedException ie) {
+ // empty on purpose.
+ }
+ }
+
+ }
+
+ // CHECKSTYLE:OFF
+
+ public void jsConstructor(int count) {
+ latch = new CountDownLatch(count);
+ }
+
+ public void jsFunction_count() {
+ latch.countDown();
+ }
+ // CHECKSTYLE:ON
+ }
+
public JavascriptTestUtilities(Class<?> classpathReference) {
super(classpathReference);
}
@@ -143,9 +181,10 @@
ScriptableObject.defineClass(rhinoScope, JsAssert.class);
ScriptableObject.defineClass(rhinoScope, Trace.class);
ScriptableObject.defineClass(rhinoScope, Notifier.class);
+ ScriptableObject.defineClass(rhinoScope, CountDownNotifier.class);
+
// so that the stock test for IE can gracefully fail.
- rhinoContext.evaluateString(rhinoScope, "var window = new Object();",
- "<internal>", 0, null);
+ rhinoContext.evaluateString(rhinoScope, "var window = new Object();", "<internal>", 0, null);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
@@ -241,8 +280,9 @@
}
/**
- * Call a method on a Javascript object and convert result to specified class. Convert to the
- * requested class.
+ * Call a method on a Javascript object and convert result to specified class. Convert to the requested
+ * class.
+ *
* @param <T> type
* @param clazz class object.
* @param that Javascript object.
@@ -256,6 +296,7 @@
/**
* Call a method on a Javascript object inside context brackets.
+ *
* @param <T> return type.
* @param clazz class for the return type.
* @param that object
@@ -263,9 +304,8 @@
* @param args arguments. Caller must run javaToJS as appropriate
* @return return value.
*/
- public <T> T rhinoCallMethodInContext(final Class<T> clazz, final Scriptable that,
- final String methodName,
- final Object... args) {
+ public <T> T rhinoCallMethodInContext(final Class<T> clazz, final Scriptable that,
+ final String methodName, final Object... args) {
// we end up performing the cast twice to make the compiler happy.
return runInsideContext(clazz, new JSRunnable<T>() {
public T run(Context context) {
@@ -275,8 +315,7 @@
}
/**
- * Evaluate a Javascript expression, converting the return value to a
- * convenient Java type.
+ * Evaluate a Javascript expression, converting the return value to a convenient Java type.
*
* @param <T> The desired type
* @param jsExpression the javascript expression.
@@ -288,14 +327,12 @@
}
/**
- * Call a JavaScript function within the Context. Optionally, require it to
- * throw an exception equal to a supplied object. If the exception is called
- * for, this function will either return null or Assert.
+ * Call a JavaScript function within the Context. Optionally, require it to throw an exception equal to a
+ * supplied object. If the exception is called for, this function will either return null or Assert.
*
* @param expectingException Exception desired, or null.
* @param functionName Function to call.
- * @param args args for the function. Be sure to Javascript-ify them as
- * appropriate.
+ * @param args args for the function. Be sure to Javascript-ify them as appropriate.
* @return
*/
public Object rhinoCallExpectingExceptionInContext(final Object expectingException,
@@ -308,8 +345,8 @@
}
/**
- * Call a Javascript function, identified by name, on a set of arguments.
- * Optionally, expect it to throw an exception.
+ * Call a Javascript function, identified by name, on a set of arguments. Optionally, expect it to throw
+ * an exception.
*
* @param expectingException
* @param functionName
@@ -363,15 +400,13 @@
readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
}
- ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo,
- null,
- prefixManager,
- nameManager);
+ ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null,
+ prefixManager, nameManager);
serviceBuilder.walk();
String serviceJavascript = serviceBuilder.getCode();
readStringIntoRhino(serviceJavascript, serviceInfo.getName() + ".js");
}
-
+
public static String scriptableToString(Scriptable scriptable) {
StringBuilder builder = new StringBuilder();
for (Object propid : scriptable.getIds()) {
Modified: cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/GreeterTests.js
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/GreeterTests.js?rev=684600&r1=684599&r2=684600&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/GreeterTests.js (original)
+++ cxf/trunk/rt/javascript/src/test/resources/org/apache/cxf/javascript/GreeterTests.js Sun Aug 10 14:48:38 2008
@@ -58,11 +58,16 @@
globalResponseObject = responseObject;
}
+function closure_success1(responseObject)
+{
+ globalResponseObject = responseObject;
+ globalNotifier.count();
+}
-function success2(responseObject)
+function closure_success2(responseObject)
{
globalSecondResponseObject = responseObject;
- globalNotifier.notify();
+ globalNotifier.count();
}
function sayHiTest(url)
@@ -84,14 +89,14 @@
{
org_apache_cxf_trace.trace("Enter sayHi.");
resetGlobals();
- globalNotifier = new org_apache_cxf_notifier();
+ globalNotifier = new org_apache_cxf_count_down_notifier(2);
var intf;
intf = new cxf_apache_org_jstest_Greeter();
intf.url = url;
- intf.sayHi(success1, testErrorCallback);
- intf.sayHi(success2, testErrorCallback);
+ intf.sayHi(closure_success1, testErrorCallback);
+ intf.sayHi(closure_success2, testErrorCallback);
// Return the notifier as a convenience to the Java code.
return globalNotifier;