Author: markt
Date: Mon May 26 22:54:20 2014
New Revision: 1597662
URL: http://svn.apache.org/r1597662
Log:
Refactor test to enable a clean server shutdown. This prevents the web
application class loader complaining about a still running thread on server
stop.
Modified:
tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
Modified:
tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java?rev=1597662&r1=1597661&r2=1597662&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
(original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
Mon May 26 22:54:20 2014
@@ -361,6 +361,9 @@ public class TestWsWebSocketContainer ex
long timeout = System.currentTimeMillis() - lastSend;
+ // Clear the server side block and prevent and further blocks to allow
+ // the server to shutdown cleanly
+ BlockingPojo.clearBlock();
String msg = "Time out was [" + timeout + "] ms";
@@ -462,6 +465,8 @@ public class TestWsWebSocketContainer ex
(ServerContainer) sce.getServletContext().getAttribute(
Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
try {
+ // Reset blocking state
+ BlockingPojo.resetBlock();
sc.addEndpoint(BlockingPojo.class);
} catch (DeploymentException e) {
throw new IllegalStateException(e);
@@ -472,11 +477,35 @@ public class TestWsWebSocketContainer ex
@ServerEndpoint("/block")
public static class BlockingPojo {
+
+ private static Object monitor = new Object();
+ // Enable blockign by default
+ private static boolean block = true;
+
+ /**
+ * Clear any current block.
+ */
+ public static void clearBlock() {
+ synchronized (monitor) {
+ BlockingPojo.block = false;
+ monitor.notifyAll();
+ }
+ }
+
+ public static void resetBlock() {
+ synchronized (monitor) {
+ block = true;
+ }
+ }
@SuppressWarnings("unused")
@OnMessage
public void echoTextMessage(Session session, String msg, boolean last)
{
try {
- Thread.sleep(60000);
+ synchronized (monitor) {
+ while (block) {
+ monitor.wait();
+ }
+ }
} catch (InterruptedException e) {
// Ignore
}
@@ -488,7 +517,11 @@ public class TestWsWebSocketContainer ex
public void echoBinaryMessage(Session session, ByteBuffer msg,
boolean last) {
try {
- Thread.sleep(TIMEOUT_MS * 10);
+ synchronized (monitor) {
+ while (block) {
+ monitor.wait();
+ }
+ }
} catch (InterruptedException e) {
// Ignore
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]