Revision: 6090 Author: jlaba...@google.com Date: Fri Sep 4 13:10:40 2009 Log: Increasing the timeout of JsonpRequestTest and forcing the server to flush results faster.
Patch by: jlabanca Review by: jat (desk) http://code.google.com/p/google-web-toolkit/source/detail?r=6090 Modified: /trunk/user/test/com/google/gwt/jsonp/client/JsonpRequestTest.java /trunk/user/test/com/google/gwt/jsonp/server/EchoServlet.java ======================================= --- /trunk/user/test/com/google/gwt/jsonp/client/JsonpRequestTest.java Mon Aug 31 07:42:01 2009 +++ /trunk/user/test/com/google/gwt/jsonp/client/JsonpRequestTest.java Fri Sep 4 13:10:40 2009 @@ -25,27 +25,38 @@ public class JsonpRequestTest extends GWTTestCase { /** - * The maximum amount of time to wait for a response in milliseconds. + * The maximum amount of time to wait for a response in milliseconds. */ - private static final int RESPONSE_DELAY = 1500; + private static final int RESPONSE_DELAY = 2500; + + /** + * The current Id of the async callback. + */ + protected static int currentId; /** * Checks that an error is received. */ private class AssertFailureCallback<T> implements AsyncCallback<T> { private String expectedMessage; + private int id; public AssertFailureCallback(String expectedMessage) { + id = ++currentId; this.expectedMessage = expectedMessage; } public void onFailure(Throwable throwable) { - assertEquals(expectedMessage, throwable.getMessage()); - finishTest(); + if (id == currentId) { + assertEquals(expectedMessage, throwable.getMessage()); + finishTest(); + } } public void onSuccess(T value) { - fail(); + if (id == currentId) { + fail(); + } } } @@ -54,18 +65,24 @@ */ private class AssertSuccessCallback<T> implements AsyncCallback<T> { private T expectedValue; + private int id; private AssertSuccessCallback(T expectedValue) { + this.id = ++currentId; this.expectedValue = expectedValue; } public void onFailure(Throwable throwable) { - fail(); + if (id == currentId) { + fail(); + } } public void onSuccess(T value) { - assertEquals(expectedValue, value); - finishTest(); + if (id == currentId) { + assertEquals(expectedValue, value); + finishTest(); + } } } @@ -103,33 +120,33 @@ } public void testBooleanFalse() { + delayTestFinish(RESPONSE_DELAY); jsonp.requestBoolean(echo("false"), new AssertSuccessCallback<Boolean>( Boolean.FALSE)); - delayTestFinish(RESPONSE_DELAY); } public void testBooleanTrue() { + delayTestFinish(RESPONSE_DELAY); jsonp.requestBoolean(echo("true"), new AssertSuccessCallback<Boolean>( Boolean.TRUE)); - delayTestFinish(RESPONSE_DELAY); } public void testDouble() { + delayTestFinish(RESPONSE_DELAY); jsonp.requestDouble(echo("123.456"), new AssertSuccessCallback<Double>( 123.456)); - delayTestFinish(RESPONSE_DELAY); } public void testFailureCallback() { + delayTestFinish(RESPONSE_DELAY); jsonp.setFailureCallbackParam("failureCallback"); jsonp.requestString(echoFailure("ERROR"), new AssertFailureCallback<String>("ERROR")); - delayTestFinish(RESPONSE_DELAY); } public void testInteger() { - jsonp.requestInteger(echo("123"), new AssertSuccessCallback<Integer>(123)); delayTestFinish(RESPONSE_DELAY); + jsonp.requestInteger(echo("123"), new AssertSuccessCallback<Integer>(123)); } /** @@ -137,46 +154,47 @@ * only a 'callback' parameter, and sends back the error to it. */ public void testNoFailureCallback() { + delayTestFinish(RESPONSE_DELAY); jsonp.setFailureCallbackParam(null); jsonp.requestString(echoFailure("ERROR"), new AssertSuccessCallback<String>("ERROR")); - delayTestFinish(RESPONSE_DELAY); } public void testNullBoolean() { - jsonp.requestBoolean(echo("null"), new AssertSuccessCallback<Boolean>(null)); delayTestFinish(RESPONSE_DELAY); + jsonp.requestBoolean(echo("null"), new AssertSuccessCallback<Boolean>(null)); } public void testNullDouble() { - jsonp.requestDouble(echo("null"), new AssertSuccessCallback<Double>(null)); delayTestFinish(RESPONSE_DELAY); + jsonp.requestDouble(echo("null"), new AssertSuccessCallback<Double>(null)); } public void testNullInteger() { - jsonp.requestInteger(echo("null"), new AssertSuccessCallback<Integer>(null)); delayTestFinish(RESPONSE_DELAY); + jsonp.requestInteger(echo("null"), new AssertSuccessCallback<Integer>(null)); } public void testNullString() { - jsonp.requestString(echo("null"), new AssertSuccessCallback<String>(null)); delayTestFinish(RESPONSE_DELAY); + jsonp.requestString(echo("null"), new AssertSuccessCallback<String>(null)); } public void testString() { + delayTestFinish(RESPONSE_DELAY); jsonp.requestString(echo("'Hello'"), new AssertSuccessCallback<String>( "Hello")); - delayTestFinish(RESPONSE_DELAY); } public void testTimeout() { - jsonp.requestString(echoTimeout(), new AssertTimeoutExceptionCallback<String>()); delayTestFinish(jsonp.getTimeout() + 500); + jsonp.requestString(echoTimeout(), + new AssertTimeoutExceptionCallback<String>()); } public void testVoid() { - jsonp.send(echo(null), new AssertSuccessCallback<Void>(null)); delayTestFinish(RESPONSE_DELAY); + jsonp.send(echo(null), new AssertSuccessCallback<Void>(null)); } @Override ======================================= --- /trunk/user/test/com/google/gwt/jsonp/server/EchoServlet.java Thu Apr 16 15:13:33 2009 +++ /trunk/user/test/com/google/gwt/jsonp/server/EchoServlet.java Fri Sep 4 13:10:40 2009 @@ -56,6 +56,7 @@ value = ""; } res.getWriter().println(callback + "(" + value + ");"); + res.getWriter().flush(); break; } @@ -64,11 +65,13 @@ String error = req.getParameter("error"); if (failureCallback != null) { res.getWriter().println(failureCallback + "('" + error + "');"); + res.getWriter().flush(); } else { // If no failure callback is defined, send the error through the // success callback. String callback = req.getParameter("callback"); res.getWriter().println(callback + "('" + error + "');"); + res.getWriter().flush(); } break; } --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---