aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Auge2018-05-01 14:20:44 -0400
committerRaymond Auge2018-05-01 14:20:44 -0400
commit85b726fa7b6684ca58d90178098196787fba2336 (patch)
treef49b98954960c4a2e1a60750396c86d47030428a
parent2d4acfd11bfc2872c443a83642ce52e840bb2ae7 (diff)
downloadrt.equinox.bundles-85b726fa7b6684ca58d90178098196787fba2336.zip
rt.equinox.bundles-85b726fa7b6684ca58d90178098196787fba2336.tar.gz
rt.equinox.bundles-85b726fa7b6684ca58d90178098196787fba2336.tar.xz
Bug 530247 - [http] test ServletTest.test_AsyncOutput1 fails on everything but windows during build with OOM
Signed-off-by: Raymond Auge <raymond.auge@liferay.com>
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java20
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/AsyncOutputServlet.java22
2 files changed, 27 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
index 881eb7b..d299c77 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
@@ -13,13 +13,16 @@
*******************************************************************************/
package org.eclipse.equinox.http.servlet.tests;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.CookieHandler;
@@ -75,8 +78,8 @@ import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
-import org.eclipse.equinox.http.servlet.RangeAwareServletContextHelper;
import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.RangeAwareServletContextHelper;
import org.eclipse.equinox.http.servlet.context.ContextPathCustomizer;
import org.eclipse.equinox.http.servlet.session.HttpSessionInvalidator;
import org.eclipse.equinox.http.servlet.testbase.BaseTest;
@@ -3783,8 +3786,7 @@ public class ServletTest extends BaseTest {
}
}
- //Disable @Test
- // TODO this test takes large amounts of memory and can fail with OOM on build machines see bug 530247
+ @Test
public void test_AsyncOutput1() throws Exception {
Servlet s1 = new AsyncOutputServlet();
Collection<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
@@ -3795,13 +3797,13 @@ public class ServletTest extends BaseTest {
servletProps1.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, true);
registrations.add(getBundleContext().registerService(Servlet.class, s1, servletProps1));
- String output1 = requestAdvisor.request("asyncOutput");
+ String output1 = requestAdvisor.request("asyncOutput?iterations=2");
- Assert.assertTrue("write(int)", output1.startsWith("0123456789"));
+ Assert.assertEquals("write(int)", "01234567890123456789", output1);
- String output2 = requestAdvisor.request("asyncOutput?bytes=true");
+ String output2 = requestAdvisor.request("asyncOutput?bytes=true&iterations=4");
- Assert.assertTrue("write(byte[], int, int)", output2.startsWith("0123456789"));
+ Assert.assertEquals("write(byte[], int, int)", "0123456789012345678901234567890123456789", output2);
} finally {
for (ServiceRegistration<?> registration : registrations) {
registration.unregister();
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/AsyncOutputServlet.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/AsyncOutputServlet.java
index 7f1d71a..19768d8 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/AsyncOutputServlet.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/AsyncOutputServlet.java
@@ -32,19 +32,23 @@ public class AsyncOutputServlet extends HttpServlet {
resp.flushBuffer();
AsyncContext async = req.startAsync(req, resp);
ServletOutputStream out = resp.getOutputStream();
- out.setWriteListener(new AsyncWriter(async, Boolean.parseBoolean(req.getParameter("bytes"))));
+ out.setWriteListener(new AsyncWriter(
+ async,
+ Integer.parseInt(req.getParameter("iterations") == null ? "1" : req.getParameter("iterations")),
+ Boolean.parseBoolean(req.getParameter("bytes"))));
}
private class AsyncWriter implements WriteListener {
private final AsyncContext async;
-
private final boolean writeBytes;
+ private final int iterations;
private boolean eof;
- public AsyncWriter(AsyncContext async, boolean writeBytes) {
+ public AsyncWriter(AsyncContext async, int iterations, boolean writeBytes) {
this.async = async;
+ this.iterations = iterations;
this.writeBytes = writeBytes;
}
@@ -58,6 +62,8 @@ public class AsyncOutputServlet extends HttpServlet {
return;
}
+ int count = 0;
+
if (writeBytes) {
byte[] buf = new byte[10];
for (int i = 0; i < buf.length; ++i) {
@@ -66,14 +72,18 @@ public class AsyncOutputServlet extends HttpServlet {
do {
out.write(buf);
- } while (out.isReady());
+ } while (out.isReady() && (++count < iterations));
} else {
int i = -1;
do {
- out.write('0' + (++i % 10));
- } while (out.isReady());
+ int b = '0' + (++i % 10);
+ out.write(b);
+ } while (out.isReady() && (++count < (iterations * 10)));
}
+ out.close();
+ async.complete();
+
eof = true;
}