JBoss Remoting SVN: r6452 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2012-07-18 18:33:13 -0400 (Wed, 18 Jul 2012)
New Revision: 6452
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SemaphoreGrowthTestCase.java
Log:
JBREM-1305: Fixed it.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SemaphoreGrowthTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SemaphoreGrowthTestCase.java 2012-07-18 19:11:55 UTC (rev 6451)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SemaphoreGrowthTestCase.java 2012-07-18 22:33:13 UTC (rev 6452)
@@ -22,7 +22,6 @@
package org.jboss.test.remoting.transport.socket.timeout;
import java.net.InetAddress;
-import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.Map;
@@ -34,8 +33,8 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.CannotConnectException;
import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationFailureException;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.ServerInvocationHandler;
@@ -68,8 +67,8 @@
protected InvokerLocator serverLocator;
protected Connector connector;
protected TestInvocationHandler invocationHandler;
- protected CountDown latch = new CountDown(2);
-
+ protected CountDown latch0 = new CountDown(1);
+ protected CountDown latch1 = new CountDown(2);
public void setUp() throws Exception
{
@@ -107,41 +106,47 @@
client.connect();
log.info("client is connected");
- // Test connection.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Make first call, attempt to increase semaphore count.
+ // Make first two calls, attempt to increase semaphore count.
+ CallThread ct0 = new CallThread(client, "20000", "longwait", latch0, 0);
+ ct0.start();
+ Thread.sleep(500);
try
{
- client.invoke("longwait");
- fail("First call unexpectedly succeeded");
+ log.info("Making second invocation");
+ HashMap metadata = new HashMap();
+ metadata.put("timeout", "1000");
+ client.invoke("unused", metadata);
+ fail("Second call unexpectedly succeeded");
}
- catch (InvocationFailureException e)
+ catch (CannotConnectException e)
{
- if (e.getCause() instanceof SocketTimeoutException)
+ if (e.getCause() instanceof IllegalStateException && e.getMessage().indexOf("are in use") > -1)
{
- log.info("First call gets expected timeout");
+ log.info("Second call gets expected timeout");
}
else
{
- fail("First call got unexpected exception wrapped in CannotConnectException: " + e);
+ fail("Second call got unexpected exception wrapped in CannotConnectException: " + e);
}
}
catch (Throwable t)
{
- fail("First call got unexpected exception: " + t);
+ fail("Second call got unexpected exception: " + t);
}
// Verify that semaphore count has not been increased.
- CallThread ct0 = new CallThread(client, "shortwait", 0);
- CallThread ct1 = new CallThread(client, "nowait", 1);
- ct0.start();
+ latch0.acquire();
+ CallThread ct1 = new CallThread(client, "10000", "shortwait", latch1, 1);
+ CallThread ct2 = new CallThread(client, "1000", "nowait", latch1, 2);
+ ct1.start();
Thread.sleep(500);
- ct1.start();
- latch.acquire();
- log.info("Delay for third call: " + ct1.delay);
- assertTrue("Second call was not delayed", ct1.delay > 2000);
+ ct2.start();
+ latch1.acquire();
+ log.info("Exception for fourth call: " + ct2.t);
+ assertTrue("Fourth call should have timed out",
+ ct2.t != null &&
+ ct2.t.getCause() instanceof IllegalStateException &&
+ ct2.t.getMessage().indexOf("are in use") > -1);
client.disconnect();
shutdownServer();
@@ -213,34 +218,43 @@
public void setInvoker(ServerInvoker invoker) {}
}
+
class CallThread extends Thread
{
Client client;
+ String timeout;
String command;
+ CountDown latch;
int id;
- long delay;
+ Throwable t;
- public CallThread(Client client, String command, int id)
+ public CallThread(Client client, String timeout, String command, CountDown latch, int id)
{
this.client = client;
+ this.timeout = timeout;
this.command = command;
+ this.latch = latch;
this.id = id;
}
public void run()
{
try
{
- long start = System.currentTimeMillis();
+ HashMap metadata = new HashMap();
+ metadata.put("timeout", timeout);
log.info("CallThread " + id + " making invocation: " + command);
- client.invoke(command);
- delay = System.currentTimeMillis() - start;
+ client.invoke(command, metadata);
log.info("CallThread " + id + " back from invocation");
- latch.release();
}
catch (Throwable t)
{
log.info("Thread " + id + " got exception: " + t.getMessage());
+ this.t = t;
}
+ finally
+ {
+ latch.release();
+ }
}
}
}
\ No newline at end of file