JBoss Remoting SVN: r6170 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:21:50 -0500 (Wed, 15 Dec 2010)
New Revision: 6170
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java
Log:
JBREM-1144: Added USE_SERVER_CONNECTION_IDENTITY and SERVER_ID.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java 2010-12-15 23:21:17 UTC (rev 6169)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java 2010-12-15 23:21:50 UTC (rev 6170)
@@ -89,7 +89,8 @@
* all connections it participated in are now gone.
*/
public static final String USE_CLIENT_CONNECTION_IDENTITY = "useClientConnectionIdentity";
-// public static final String USE_SERVER_CONNECTION_IDENTITY = "useServerConnectionIdentity";
+ public static final String USE_SERVER_CONNECTION_IDENTITY = "useServerConnectionIdentity";
+ public static final String SERVER_ID = "serverID";
/**
* A flag for indicating that when a client side Remoting unmarshaller uses the Thread
13 years, 11 months
JBoss Remoting SVN: r6169 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:21:17 -0500 (Wed, 15 Dec 2010)
New Revision: 6169
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-1144: Declares connection broken when it sees a new serverId, if useServerConnectionIdentity is set to true.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java 2010-12-15 23:20:59 UTC (rev 6168)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java 2010-12-15 23:21:17 UTC (rev 6169)
@@ -244,6 +244,8 @@
private MicroRemoteClientInvoker sharedInvoker;
private LeasePinger leasePinger;
private boolean useClientConnectionIdentity;
+ private boolean useServerConnectionIdentity;
+ private String serverId;
// Constructors ---------------------------------------------------------------------------------
@@ -738,6 +740,27 @@
" to a boolean: must be a String");
}
}
+ o = config.get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if (o != null)
+ {
+ if (o instanceof String)
+ {
+ try
+ {
+ useServerConnectionIdentity = Boolean.valueOf(((String) o)).booleanValue();
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " value" +
+ " to a boolean: " + o);
+ }
+ }
+ else
+ {
+ log.warn(this + " could not convert " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " value" +
+ " to a boolean: must be a String");
+ }
+ }
}
}
@@ -791,6 +814,12 @@
{
Map metadata = new HashMap();
metadata.put(ServerInvoker.INVOKER_SESSION_ID, invokerSessionId);
+
+ if (useServerConnectionIdentity)
+ {
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ }
+
InvocationRequest ir =
new InvocationRequest(null, Subsystem.SELF, "$PING$", metadata, null, null);
@@ -800,12 +829,63 @@
if (o instanceof Boolean && !((Boolean) o).booleanValue())
{
// Server indicates lease has stopped.
- throw new Exception("server indicates lease has stopped");
+ throw new Exception();
}
+ if (o instanceof InvocationResponse)
+ {
+ Object result = ((InvocationResponse) o).getResult();
+ if (result instanceof Boolean && !((Boolean) result).booleanValue())
+ {
+ // Server indicates lease has stopped.
+ throw new Exception();
+ }
+ if (useServerConnectionIdentity)
+ {
+ Map map = ((InvocationResponse) o).getPayload();
+ if (map != null)
+ {
+ String s = (String) map.get(Remoting.SERVER_ID);
+ if (s != null)
+ {
+ if (serverId == null)
+ {
+ serverId = s;
+ pingWorked = true;
+ if (trace) log.trace(this + " set serverId to " + serverId);
+ }
+ else
+ {
+ pingWorked = s.equals(serverId);
+ if (!pingWorked)
+ {
+ if (trace) log.trace(this + " detected new serverId: " + s + " != " + serverId);
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
- if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
-
- pingWorked = true;
+ if (pingWorked)
+ {
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+ }
+ else
+ {
+ if (trace) { log.trace("ConnectionValidator did not get successful ping response " + clientInvoker);}
+ }
}
catch (Throwable t)
{
@@ -823,17 +903,69 @@
{
// Sending null client id as don't want to trigger lease on server side. This also means
// that client connection validator will NOT impact client lease, so can not depend on it
- // to maintain client lease with the server.
- InvocationRequest ir =
- new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+ // to maintain client lease with the server
+
+ InvocationRequest ir = null;
+ if (useServerConnectionIdentity)
+ {
+ Map metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", metadata, null, null);
+ }
+ else
+ {
+ ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+ }
if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); }
- clientInvoker.invoke(ir);
+ Object o = clientInvoker.invoke(ir);
+ if (useServerConnectionIdentity && o instanceof InvocationResponse)
+ {
+ Map map = ((InvocationResponse) o).getPayload();
+ if (map != null)
+ {
+ String s = (String) map.get(Remoting.SERVER_ID);
+ if (s != null)
+ {
+ if (serverId == null)
+ {
+ serverId = s;
+ pingWorked = true;
+ if (trace) log.trace(this + " set serverId to " + serverId);
+ }
+ else
+ {
+ pingWorked = s.equals(serverId);
+ if (!pingWorked)
+ {
+ if (trace) log.trace(this + " detected new serverId: " + s + " != " + serverId);
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
- if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
-
- pingWorked = true;
+ if (pingWorked)
+ {
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+ }
+ else
+ {
+ if (trace) { log.trace("ConnectionValidator did not get successful ping response " + clientInvoker);}
+ }
}
catch (Throwable t)
{
13 years, 11 months
JBoss Remoting SVN: r6168 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:20:59 -0500 (Wed, 15 Dec 2010)
New Revision: 6168
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1144: Added useServerConnectionIdentity variable.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2010-12-15 23:19:09 UTC (rev 6167)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2010-12-15 23:20:59 UTC (rev 6168)
@@ -220,6 +220,8 @@
private Set connectionListeners = new HashSet();
private boolean useClientConnectionIdentity;
+
+ private boolean useServerConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -318,6 +320,27 @@
}
}
}
+ o = configuration.get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if (o instanceof String)
+ {
+ useServerConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
+ }
+ else if (o != null)
+ {
+ log.warn("value of " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " must be a String: " + o);
+ }
+ else
+ {
+ if (locator.getParameters() != null)
+ {
+ o = locator.getParameters().get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if (o != null)
+ {
+ useServerConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
+ this.configuration.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, o);
+ }
+ }
+ }
}
Map tempMap = new HashMap();
13 years, 11 months
JBoss Remoting SVN: r6167 - remoting2/branches/2.x.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:19:09 -0500 (Wed, 15 Dec 2010)
New Revision: 6167
Modified:
remoting2/branches/2.x/build.xml
Log:
JBREM-1144: Added server identity versioning tests for versions that have a ConnectionValidator.
Modified: remoting2/branches/2.x/build.xml
===================================================================
--- remoting2/branches/2.x/build.xml 2010-12-15 23:10:41 UTC (rev 6166)
+++ remoting2/branches/2.x/build.xml 2010-12-15 23:19:09 UTC (rev 6167)
@@ -2364,6 +2364,8 @@
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2376,12 +2378,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.5.2.SP2/jboss-remoting.jar${extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_5_2_SP2-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.5.2.SP2/jboss-remoting.jar${extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2394,12 +2400,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.5.2/jboss-remoting.jar${extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_5_2-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.5.2/jboss-remoting.jar${extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2412,12 +2422,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.5.1/jboss-remoting.jar${extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_5_1-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.5.1/jboss-remoting.jar${extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2430,12 +2444,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.5.0.SP2/jboss-remoting.jar${extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_5_0_SP2-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.5.0.SP2/jboss-remoting.jar${extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2448,12 +2466,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.5.0.SP1/jboss-remoting.jar${extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_5_0_SP1-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.5.0.SP1/jboss-remoting.jar${extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2466,12 +2488,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.5.0.GA/jboss-remoting.jar${extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_5_0_GA-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.5.0.GA/jboss-remoting.jar${extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2484,12 +2510,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.4.0.SP1/jboss-remoting.jar${old.extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_4_0_SP1-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.4.0.SP1/jboss-remoting.jar${old.extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2502,12 +2532,16 @@
<param name="client.classpath" value="${etc.dir}/lib/2.4.0.GA/jboss-remoting.jar${old.extended.classpath}"/>
<param name="server.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_4_0_GA-server"/>
<param name="server.classpath" value="${etc.dir}/lib/2.4.0.GA/jboss-remoting.jar${old.extended.classpath}"/>
<param name="client.classpath" value="${output.lib.dir}/jboss-remoting.jar${extended.classpath}"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2524,6 +2558,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_3_SP2-server"/>
@@ -2535,6 +2571,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2551,6 +2589,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_3_SP1-server"/>
@@ -2562,6 +2602,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2578,6 +2620,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_3-server"/>
@@ -2589,6 +2633,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2605,6 +2651,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP11-server"/>
@@ -2616,6 +2664,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2632,6 +2682,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP10-server"/>
@@ -2643,6 +2695,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2659,6 +2713,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP9-server"/>
@@ -2670,6 +2726,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2686,6 +2744,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP7-server"/>
@@ -2697,6 +2757,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2713,6 +2775,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP4-server"/>
@@ -2724,6 +2788,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2740,6 +2806,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP2-server"/>
@@ -2751,6 +2819,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2767,6 +2837,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_SP1-server"/>
@@ -2778,6 +2850,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="true"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -2794,6 +2868,8 @@
<param name="client.version" value=""/>
<param name="server.version" value="2"/>
<param name="check_connection" value="false"/>
+ <param name="clientImplementsServerIdentity" value="false"/>
+ <param name="serverImplementsServerIdentity" value="true"/>
</antcall>
<antcall target="tests.versioning.all_transports_pre_2.4" inheritrefs="true">
<param name="jboss-junit-configuration" value="2_2_2_GA-server"/>
@@ -2805,6 +2881,8 @@
<param name="server.version" value=""/>
<param name="check_connection" value="false"/>
<param name="check_content_type" value="false"/>
+ <param name="clientImplementsServerIdentity" value="true"/>
+ <param name="serverImplementsServerIdentity" value="false"/>
</antcall>
<!-- ******************************************************************************** -->
@@ -3095,6 +3173,8 @@
<mkdir dir="${output.tests.results}"/>
<mkdir dir="${output.tests.tmp}"/>
<echo>Running: ${jboss-junit-configuration}</echo>
+ <echo>clientImplementsServerIdentity: ${clientImplementsServerIdentity}</echo>
+ <echo>serverImplementsServerIdentity: ${serverImplementsServerIdentity}</echo>
<junit printsummary="true" fork="yes" includeantruntime="true" tempdir="${output.tests.tmp}">
<classpath>
<path refid="basic.third_party.classpath"/>
@@ -3108,6 +3188,8 @@
<jvmarg value="-Dserver.pre_2_0_compatible=${server.pre_2_0_compatible}"/>
<jvmarg value="-Dremoting.metadata=check_connection=${check_connection}"/>
<jvmarg value="-Dcheck_content_type=${check_content_type}"/>
+ <jvmarg value="-DclientImplementsServerIdentity=${clientImplementsServerIdentity}"/>
+ <jvmarg value="-DserverImplementsServerIdentity=${serverImplementsServerIdentity}"/>
<!--sysproperty key="${java.security.manager.key}" value="${java.security.manager}"/>
<sysproperty key="java.security.policy" value="${java.security.policy}"/>
<sysproperty key="java.security.debug" value="${java.security.debug}"/>
@@ -3124,6 +3206,7 @@
<fileset dir="${tests.compile.dir}">
<include name="**/remoting/versioning/transport/**/*TestCase.class"/>
<include name="**/remoting/versioning/lease/**/*TestCase.class"/>
+ <include name="**/remoting/versioning/identity/*TestCase.class"/>
<exclude name="**/multiplex/**"/>
</fileset>
</batchtest>
@@ -3135,6 +3218,8 @@
<mkdir dir="${output.tests.results}"/>
<mkdir dir="${output.tests.tmp}"/>
<echo>Running: ${jboss-junit-configuration}</echo>
+ <echo>clientImplementsServerIdentity: ${clientImplementsServerIdentity}</echo>
+ <echo>serverImplementsServerIdentity: ${serverImplementsServerIdentity}</echo>
<junit printsummary="true" fork="yes" includeantruntime="true" tempdir="${output.tests.tmp}">
<classpath>
<path refid="basic.third_party.classpath"/>
@@ -3148,6 +3233,8 @@
<jvmarg value="-Dserver.pre_2_0_compatible=${server.pre_2_0_compatible}"/>
<jvmarg value="-Dremoting.metadata=check_connection=${check_connection}"/>
<jvmarg value="-Dcheck_content_type=${check_content_type}"/>
+ <jvmarg value="-DclientImplementsServerIdentity=${clientImplementsServerIdentity}"/>
+ <jvmarg value="-DserverImplementsServerIdentity=${serverImplementsServerIdentity}"/>
<!--sysproperty key="${java.security.manager.key}" value="${java.security.manager}"/>
<sysproperty key="java.security.policy" value="${java.security.policy}"/>
<sysproperty key="java.security.debug" value="${java.security.debug}"/>
@@ -3164,6 +3251,7 @@
<fileset dir="${tests.compile.dir}">
<include name="**/remoting/versioning/transport/**/*TestCase.class"/>
<include name="**/remoting/versioning/lease/**/*TestCase.class"/>
+ <include name="**/remoting/versioning/identity/*TestCase.class"/>
<exclude name="**/VersionRMISerializableMarshallerTestCase.class"/>
<exclude name="**/multiplex/**"/>
</fileset>
13 years, 11 months
JBoss Remoting SVN: r6166 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning: identity and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:10:41 -0500 (Wed, 15 Dec 2010)
New Revision: 6166
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestClientParent.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java
Log:
JBREM-1144: New versioning tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestClientParent.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestClientParent.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestClientParent.java 2010-12-15 23:10:41 UTC (rev 6166)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.versioning.identity;
+
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Dec 15, 2010
+ * </p>
+ */
+public class ServerIdentityVersionTestClientParent extends TestCase
+{
+ protected void setOut(final PrintStream ps)
+ {
+ System.setOut(ps);
+ }
+
+
+ protected void setErr(final PrintStream ps)
+ {
+ System.setErr(ps);
+ }
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityVersionTestServer.java 2010-12-15 23:10:41 UTC (rev 6166)
@@ -0,0 +1,226 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.remoting.versioning.identity;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.socket.LRUPool;
+import org.jboss.remoting.transport.socket.ServerSocketWrapper;
+import org.jboss.remoting.transport.socket.ServerThread;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.util.id.GUID;
+
+
+/**
+ * Versioning tests for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityVersionTestServer extends ServerTestCase
+{
+ public static int PORT = 6543;
+
+ private static Logger log = Logger.getLogger(ServerIdentityVersionTestServer.class);
+
+ protected String host;
+ protected int port;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ final ServerIdentityVersionTestServer p = new ServerIdentityVersionTestServer();
+ Thread.sleep(300000);
+ p.tearDown();
+ }
+ catch (Exception e)
+ {
+ log.error("Error", e);
+ }
+ }
+
+ public void setUp() throws Exception
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+
+ host = InetAddress.getLocalHost().getHostAddress();
+
+ // Start server.
+ setupServer(true);
+
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Bounce server.
+ shutdownServer();
+ log.info("SHUT DOWN SERVER");
+ setupServer(true);
+ log.info("SET UP NEW SERVER");
+
+ Thread.sleep(15000);
+ shutdownServer();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }.start();
+ }
+
+
+ public void tearDown() throws Exception
+ {
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean useLeasing) throws Exception
+ {
+ String locatorURI = getTransport() + "://" + host + ":" + PORT + "/?" + Remoting.USE_SERVER_CONNECTION_IDENTITY + "=true";
+ if (useLeasing)
+ {
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE + "=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE_PERIOD + "=20000";
+ }
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ if (useLeasing)
+ {
+ connector.addConnectionListener(new TestConnectionListener());
+ }
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ {
+ // Remoting versions 1.x and 2.2.x don't necessarily shut down all of their
+ // ServerThreads, so an exiting connection could connect to a ServerThread
+ // associated with the old ServerInvoker.
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field clientpoolField = SocketServerInvoker.class.getDeclaredField("clientpool");
+ clientpoolField.setAccessible(true);
+ Field socketWrapperField = ServerThread.class.getDeclaredField("socketWrapper");
+ socketWrapperField.setAccessible(true);
+ LRUPool clientpool = (LRUPool) clientpoolField.get(invoker);
+ Set threads = clientpool.getContents();
+ Iterator it = threads.iterator();
+ while (it.hasNext())
+ {
+ ServerThread t = (ServerThread) it.next();
+ ServerSocketWrapper socketWrapper = (ServerSocketWrapper) socketWrapperField.get(t);
+ socketWrapper.close();
+ log.info(this + " closed " + socketWrapper);
+ }
+
+ connector.stop();
+ }
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean connectionFailed;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ connectionFailed = true;
+ this.throwable = throwable;
+ log.info(this + " received connection notification: connectionFailed: " + connectionFailed);
+ }
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestCase.java 2010-12-15 23:10:41 UTC (rev 6166)
@@ -0,0 +1,169 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.test.remoting.versioning.identity;
+
+import org.apache.log4j.Level;
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 29, 2010
+ * </p>
+ */
+public class ServerIdentityWithLeasingVersionTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+ addTestClasses("org.jboss.test.remoting.versioning.identity.ServerIdentityWithLeasingVersionTestClient",
+ 1,
+ "org.jboss.test.remoting.versioning.identity.ServerIdentityVersionTestServer");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedServerClasspath()
+ {
+ return System.getProperty("server.path");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedClientClasspath()
+ {
+ return System.getProperty("client.path");
+ }
+
+ protected String getClientJVMArguments()
+ {
+ String prop = System.getProperty("client.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("client.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("client.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ System.out.println("client arg: " + args);
+ return args;
+ }
+
+
+ protected String getServerJVMArguments()
+ {
+ String prop = System.getProperty("server.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("server.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("server.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ prop = System.getProperty("clientImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DclientImplementsServerIdentity=" + prop;
+ }
+ prop = System.getProperty("serverImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DserverImplementsServerIdentity=" + prop;
+ }
+ System.out.println("server arg: " + args);
+ return args;
+ }
+
+
+ protected Level getTestHarnessLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ protected Level getTestLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ /**
+ * How long to wait for test results to be returned from the client(s). If goes longer than the
+ * specified limit, will throw an exception and kill the running test cases. Default value is
+ * RESULTS_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getResultsTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long for the server test case to wait for tear down message. If exceeds timeout,
+ * will throw exception. The default value is TEARDOWN_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getTearDownTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long to allow each of the test cases to run their tests. If exceeds this timeout
+ * will throw exception and kill tests. The default value is RUN_TEST_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getRunTestTimeout()
+ {
+ return 60000;
+ }
+
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithLeasingVersionTestClient.java 2010-12-15 23:10:41 UTC (rev 6166)
@@ -0,0 +1,220 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.versioning.identity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+
+
+/**
+ * Versioning Unit tests for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityWithLeasingVersionTestClient extends ServerIdentityVersionTestClientParent
+{
+ private static Logger log = Logger.getLogger(ServerIdentityWithLeasingVersionTestClient.class);
+ private String host;
+ private boolean clientImplementsServerIdentity;
+ private boolean serverImplementsServerIdentity;
+ protected ByteArrayOutputStream baosOut;
+ protected PrintStream originalOutPrintStream;
+ protected ByteArrayOutputStream baosErr;
+ protected PrintStream originalErrPrintStream;
+
+ public void setUp() throws Exception
+ {
+ clientImplementsServerIdentity = Boolean.getBoolean("clientImplementsServerIdentity");
+ serverImplementsServerIdentity = Boolean.getBoolean("serverImplementsServerIdentity");
+ host = InetAddress.getLocalHost().getHostAddress();
+
+ if (clientImplementsServerIdentity && serverImplementsServerIdentity)
+ {
+ originalOutPrintStream = System.out;
+ baosOut = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baosOut);
+ setOut(ps);
+
+ originalErrPrintStream = System.err;
+ baosErr = new ByteArrayOutputStream();
+ ps = new PrintStream(baosErr);
+ setErr(ps);
+ }
+
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+
+ log.info(this + " clientImplementsServerIdentity: " + clientImplementsServerIdentity);
+ log.info(this + " serverImplementsServerIdentity: " + serverImplementsServerIdentity);
+ log.info(this + " host: " + host);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testServerIdentityWithLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ InvokerLocator clientLocator = new InvokerLocator(createLocatorURI());
+ log.info(this + "clientLocator: " + clientLocator);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Run appropriate test.
+ if (clientImplementsServerIdentity && serverImplementsServerIdentity)
+ {
+ assertTrue(doServerIdentitySupportedTest(client));
+ }
+ else
+ {
+ assertTrue(doServerIdentityUnsupportedTest(client));
+ }
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+
+
+ protected String createLocatorURI() throws UnknownHostException
+ {
+ String locatorURI = getTransport() + "://" + host + ":" + ServerIdentityVersionTestServer.PORT + "/?" + Remoting.USE_SERVER_CONNECTION_IDENTITY + "=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE + "=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE_PERIOD + "=20000";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ return locatorURI;
+ }
+
+
+ protected boolean doServerIdentitySupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity supported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "10000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "10000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Verify listener is notified if server bounces (assuming the server identity
+ // facility is available.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+
+ setOut(originalOutPrintStream);
+ String sOut = new String(baosOut.toByteArray());
+ System.out.println(sOut);
+ setErr(originalErrPrintStream);
+ String sErr = new String(baosErr.toByteArray());
+ System.out.println(sErr);
+
+ return listener.connectionFailed && (sOut.indexOf("detected new serverId:") > -1 || sErr.indexOf("detected new serverId:") > -1);
+
+ }
+
+
+ protected boolean doServerIdentityUnsupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity unsupported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "1000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow ConnectionValidator to run for a while.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+ return !listener.connectionFailed;
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean connectionFailed;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ connectionFailed = true;
+ this.throwable = throwable;
+ log.info(this + " received connection notification: connectionFailed: " + connectionFailed);
+ }
+
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestCase.java 2010-12-15 23:10:41 UTC (rev 6166)
@@ -0,0 +1,169 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.test.remoting.versioning.identity;
+
+import org.apache.log4j.Level;
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 29, 2010
+ * </p>
+ */
+public class ServerIdentityWithoutLeasingVersionTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+ addTestClasses("org.jboss.test.remoting.versioning.identity.ServerIdentityWithoutLeasingVersionTestClient",
+ 1,
+ "org.jboss.test.remoting.versioning.identity.ServerIdentityVersionTestServer");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedServerClasspath()
+ {
+ return System.getProperty("server.path");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedClientClasspath()
+ {
+ return System.getProperty("client.path");
+ }
+
+ protected String getClientJVMArguments()
+ {
+ String prop = System.getProperty("client.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("client.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("client.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ System.out.println("client arg: " + args);
+ return args;
+ }
+
+
+ protected String getServerJVMArguments()
+ {
+ String prop = System.getProperty("server.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("server.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("server.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ prop = System.getProperty("clientImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DclientImplementsServerIdentity=" + prop;
+ }
+ prop = System.getProperty("serverImplementsServerIdentity");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -DserverImplementsServerIdentity=" + prop;
+ }
+ System.out.println("server arg: " + args);
+ return args;
+ }
+
+
+ protected Level getTestHarnessLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ protected Level getTestLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ /**
+ * How long to wait for test results to be returned from the client(s). If goes longer than the
+ * specified limit, will throw an exception and kill the running test cases. Default value is
+ * RESULTS_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getResultsTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long for the server test case to wait for tear down message. If exceeds timeout,
+ * will throw exception. The default value is TEARDOWN_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getTearDownTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long to allow each of the test cases to run their tests. If exceeds this timeout
+ * will throw exception and kill tests. The default value is RUN_TEST_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getRunTestTimeout()
+ {
+ return 60000;
+ }
+
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/identity/ServerIdentityWithoutLeasingVersionTestClient.java 2010-12-15 23:10:41 UTC (rev 6166)
@@ -0,0 +1,218 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.versioning.identity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+
+
+/**
+ * Versioning Unit tests for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityWithoutLeasingVersionTestClient extends ServerIdentityVersionTestClientParent
+{
+ private static Logger log = Logger.getLogger(ServerIdentityWithoutLeasingVersionTestClient.class);
+
+ private String host;
+ private boolean clientImplementsServerIdentity;
+ private boolean serverImplementsServerIdentity;
+ protected ByteArrayOutputStream baosOut;
+ protected PrintStream originalOutPrintStream;
+ protected ByteArrayOutputStream baosErr;
+ protected PrintStream originalErrPrintStream;
+
+ public void setUp() throws Exception
+ {
+ clientImplementsServerIdentity = Boolean.getBoolean("clientImplementsServerIdentity");
+ serverImplementsServerIdentity = Boolean.getBoolean("serverImplementsServerIdentity");
+ host = InetAddress.getLocalHost().getHostAddress();
+
+ if (clientImplementsServerIdentity && serverImplementsServerIdentity)
+ {
+ originalOutPrintStream = System.out;
+ baosOut = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baosOut);
+ setOut(ps);
+
+ originalErrPrintStream = System.err;
+ baosErr = new ByteArrayOutputStream();
+ ps = new PrintStream(baosErr);
+ setErr(ps);
+ }
+
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+
+ log.info(this + " clientImplementsServerIdentity: " + clientImplementsServerIdentity);
+ log.info(this + " serverImplementsServerIdentity: " + serverImplementsServerIdentity);
+ log.info(this + " host: " + host);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testServerIdentityWithoutLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ InvokerLocator clientLocator = new InvokerLocator(createLocatorURI());
+ log.info(this + "clientLocator: " + clientLocator);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Run appropriate test.
+ if (clientImplementsServerIdentity && serverImplementsServerIdentity)
+ {
+ assertTrue(doServerIdentitySupportedTest(client));
+ }
+ else
+ {
+ assertTrue(doServerIdentityUnsupportedTest(client));
+ }
+
+ client.disconnect();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+
+
+ protected String createLocatorURI() throws UnknownHostException
+ {
+ String locatorURI = getTransport() + "://" + host + ":" + ServerIdentityVersionTestServer.PORT + "/?" + Remoting.USE_SERVER_CONNECTION_IDENTITY + "=true";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ return locatorURI;
+ }
+
+
+ protected boolean doServerIdentitySupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity supported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "10000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "10000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Verify listener is notified if server bounces (assuming the server identity
+ // facility is available.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+
+ setOut(originalOutPrintStream);
+ String sOut = new String(baosOut.toByteArray());
+ System.out.println(sOut);
+ setErr(originalErrPrintStream);
+ String sErr = new String(baosErr.toByteArray());
+ System.out.println(sErr);
+
+ return listener.connectionFailed && (sOut.indexOf("detected new serverId:") > -1 || sErr.indexOf("detected new serverId:") > -1);
+ }
+
+
+ protected boolean doServerIdentityUnsupportedTest(Client client) throws Exception
+ {
+ log.info("running server identity unsupported test");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "1000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+
+ // Allow ConnectionValidator to run for a while.
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+ return !listener.connectionFailed;
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean connectionFailed;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ connectionFailed = true;
+ this.throwable = throwable;
+ log.info(this + " received connection notification: connectionFailed: " + connectionFailed);
+ }
+
+ }
+}
\ No newline at end of file
13 years, 11 months
JBoss Remoting SVN: r6165 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:09:59 -0500 (Wed, 15 Dec 2010)
New Revision: 6165
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java
Log:
JBREM-1144: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ServerIdentityTestCase.java 2010-12-15 23:09:59 UTC (rev 6165)
@@ -0,0 +1,343 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.connection.identity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.util.SecurityUtility;
+
+
+/**
+ * Unit test for JBREM-1144.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Nov 17, 2010
+ * </p>
+ */
+public class ServerIdentityTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerIdentityTestCase.class);
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected ByteArrayOutputStream baosOut;
+ protected PrintStream originalOutPrintStream;
+ protected ByteArrayOutputStream baosErr;
+ protected PrintStream originalErrPrintStream;
+
+ public void setUp() throws Exception
+ {
+ originalOutPrintStream = System.out;
+ baosOut = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baosOut);
+ setOut(ps);
+
+ originalErrPrintStream = System.err;
+ baosErr = new ByteArrayOutputStream();
+ ps = new PrintStream(baosErr);
+ setErr(ps);
+
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.TRACE);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testServerIdentityWithoutLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false);
+
+ // Create client. Adding "dummy=dummy" assures that InvokerRegistry will not create a
+ // LocalClientInvoker for the ConnectionValidator.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI + "&dummy=dummy");
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "10000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "10000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Verify listener is notified if server bounces.
+ shutdownServer();
+ log.info("SHUT DOWN SERVER");
+ setupServer(false);
+ log.info("SET UP NEW SERVER");
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+ assertTrue(listener.connectionFailed);
+
+ setOut(originalOutPrintStream);
+ String sOut = new String(baosOut.toByteArray());
+ System.out.println(sOut);
+ setErr(originalErrPrintStream);
+ String sErr = new String(baosErr.toByteArray());
+ System.out.println(sErr);
+ assertTrue(sOut.indexOf("detected new serverId:") > -1 || sErr.indexOf("detected new serverId:") > -1);
+
+ client.disconnect();
+ shutdownServer();
+
+ log.info(getName() + " PASSES");
+ }
+
+ public void testServerIdentityWithLeasing() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client. Adding "dummy=dummy" assures that InvokerRegistry will not create a
+ // LocalClientInvoker for the ConnectionValidator.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI + "&dummy=dummy");
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Install connection listener.
+ TestConnectionListener listener = new TestConnectionListener();
+ HashMap metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "10000");
+ metadata.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "10000");
+ client.addConnectionListener(listener, metadata);
+ log.info(this + " added connection listener: " + listener);
+ // Allow time to get serverId of first server.
+ Thread.sleep(15000);
+
+ // Verify listener is notified if server bounces.
+ shutdownServer();
+ log.info("SHUT DOWN SERVER");
+ setupServer(true);
+ log.info("SET UP NEW SERVER");
+ Thread.sleep(10000);
+ log.info(this + " listener.connectionFailed: " + listener.connectionFailed);
+ assertTrue(listener.connectionFailed);
+
+ setOut(originalOutPrintStream);
+ String sOut = new String(baosOut.toByteArray());
+ System.out.println(sOut);
+ setErr(originalErrPrintStream);
+ String sErr = new String(baosErr.toByteArray());
+ System.out.println(sErr);
+ assertTrue(sOut.indexOf("detected new serverId:") > -1 || sErr.indexOf("detected new serverId:") > -1);
+
+ client.disconnect();
+ shutdownServer();
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ private void setOut(final PrintStream ps)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setOut(ps);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ System.setOut(ps);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
+
+
+ private void setErr(final PrintStream ps)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setErr(ps);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ System.setErr(ps);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
+
+
+ protected void setupServer(boolean useLeasing) throws Exception
+ {
+ locatorURI = getTransport() + "://" + host + ":" + port + "?" + Remoting.USE_SERVER_CONNECTION_IDENTITY + "=true";
+ if (useLeasing)
+ {
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE + "=true";
+ locatorURI += "&" + InvokerLocator.CLIENT_LEASE_PERIOD + "=20000";
+ }
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ if (useLeasing)
+ {
+ connector.addConnectionListener(new TestConnectionListener());
+ }
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean connectionFailed;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ connectionFailed = true;
+ this.throwable = throwable;
+ log.info(this + " received connection notification: connectionFailed: " + connectionFailed);
+ }
+
+ }
+}
\ No newline at end of file
13 years, 11 months
JBoss Remoting SVN: r6164 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:08:30 -0500 (Wed, 15 Dec 2010)
New Revision: 6164
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1144: Added useServerConnectionIdentity variable, which determines if a unique serverId is created.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2010-12-15 23:07:30 UTC (rev 6163)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2010-12-15 23:08:30 UTC (rev 6164)
@@ -38,6 +38,7 @@
import org.jboss.remoting.transport.PortUtil;
import org.jboss.remoting.util.SecurityUtility;
import org.jboss.remoting.serialization.ClassLoaderUtility;
+import org.jboss.util.id.GUID;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.BlockingMode;
import org.jboss.util.threadpool.ThreadPool;
@@ -312,6 +313,10 @@
protected boolean registerCallbackListeners = true;
protected boolean useClientConnectionIdentity;
+ protected boolean useServerConnectionIdentity;
+
+ /** Used by ConnectionValidator to detect a change of server. **/
+ protected String serverId = new GUID().toString();
// Constructors ---------------------------------------------------------------------------------
@@ -776,6 +781,16 @@
this.useClientConnectionIdentity = useClientConnectionIdentity;
}
+ public boolean isUseServerConnectionIdentity()
+ {
+ return useServerConnectionIdentity;
+ }
+
+ public void setUseServerConnectionIdentity(boolean useServerConnectionIdentity)
+ {
+ this.useServerConnectionIdentity = useServerConnectionIdentity;
+ }
+
public Object invoke(Object invoke) throws IOException
{
InvocationRequest request = null;
@@ -848,8 +863,29 @@
// Comes from ConnectionValidator configured to tie validation with lease.
boolean response = checkForClientLease(invokerSessionId);
if (trace) log.trace(this + " responding " + response + " to $PING$ for invoker sessionId " + invokerSessionId);
- return new Boolean(response);
+ if (metadata.get(Remoting.USE_SERVER_CONNECTION_IDENTITY) != null)
+ {
+ Map responseMap = new HashMap();
+ responseMap.put(Remoting.SERVER_ID, serverId);
+ if (trace) log.trace(this + " returning serverId: " + serverId);
+ return new InvocationResponse(invocation.getSessionId(), new Boolean(response), false, responseMap);
+ }
+ else
+ {
+ if (trace) log.trace(this + " not returning serverId: " + serverId);
+ return new Boolean(response);
+ }
}
+ else
+ {
+ if (metadata.get(Remoting.USE_SERVER_CONNECTION_IDENTITY) != null)
+ {
+ Map responseMap = new HashMap();
+ responseMap.put(Remoting.SERVER_ID, serverId);
+ if (trace) log.trace(this + " returning serverId: " + serverId);
+ return new InvocationResponse(invocation.getSessionId(), null, false, responseMap);
+ }
+ }
}
if (leaseManagement)
@@ -1174,6 +1210,13 @@
{
useClientConnectionIdentity = Boolean.valueOf(useClientConnectionIdentityString).booleanValue();
}
+
+ // config for useServerConnectionIdentity
+ String useServerConnectionIdentityString = (String)config.get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if(useServerConnectionIdentityString != null)
+ {
+ useServerConnectionIdentity = Boolean.valueOf(useServerConnectionIdentityString).booleanValue();
+ }
// Inject ConnectionListener
String connectionListener = (String)config.get(CONNECTION_LISTENER);
13 years, 11 months
JBoss Remoting SVN: r6163 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:07:30 -0500 (Wed, 15 Dec 2010)
New Revision: 6163
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
Log:
JBREM-1144: Added USE_SERVER_CONNECTION_IDENTITY and SERVER_ID.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2010-12-15 23:06:50 UTC (rev 6162)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2010-12-15 23:07:30 UTC (rev 6163)
@@ -119,7 +119,8 @@
* all connections it participated in are now gone.
*/
public static final String USE_CLIENT_CONNECTION_IDENTITY = "useClientConnectionIdentity";
-// public static final String USE_SERVER_CONNECTION_IDENTITY = "useServerConnectionIdentity";
+ public static final String USE_SERVER_CONNECTION_IDENTITY = "useServerConnectionIdentity";
+ public static final String SERVER_ID = "serverID";
/**
* A flag for indicating that the Client configuration map should be used to configure
13 years, 11 months
JBoss Remoting SVN: r6162 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:06:50 -0500 (Wed, 15 Dec 2010)
New Revision: 6162
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-1144: Declares connection broken when it sees a new serverId, if useServerConnectionIdentity is set to true.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2010-12-15 23:05:31 UTC (rev 6161)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2010-12-15 23:06:50 UTC (rev 6162)
@@ -268,6 +268,8 @@
private MicroRemoteClientInvoker sharedInvoker;
private LeasePinger leasePinger;
private boolean useClientConnectionIdentity;
+ private boolean useServerConnectionIdentity;
+ private String serverId;
// Constructors ---------------------------------------------------------------------------------
@@ -748,6 +750,27 @@
" to a boolean: must be a String");
}
}
+ o = config.get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if (o != null)
+ {
+ if (o instanceof String)
+ {
+ try
+ {
+ useServerConnectionIdentity = Boolean.valueOf(((String) o)).booleanValue();
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " value" +
+ " to a boolean: " + o);
+ }
+ }
+ else
+ {
+ log.warn(this + " could not convert " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " value" +
+ " to a boolean: must be a String");
+ }
+ }
}
}
@@ -813,6 +836,12 @@
{
Map metadata = new HashMap();
metadata.put(ServerInvoker.INVOKER_SESSION_ID, invokerSessionId);
+
+ if (useServerConnectionIdentity)
+ {
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ }
+
InvocationRequest ir =
new InvocationRequest(null, Subsystem.SELF, "$PING$", metadata, null, null);
@@ -824,10 +853,61 @@
// Server indicates lease has stopped.
throw new Exception();
}
+ if (o instanceof InvocationResponse)
+ {
+ Object result = ((InvocationResponse) o).getResult();
+ if (result instanceof Boolean && !((Boolean) result).booleanValue())
+ {
+ // Server indicates lease has stopped.
+ throw new Exception();
+ }
+ if (useServerConnectionIdentity)
+ {
+ Map map = ((InvocationResponse) o).getPayload();
+ if (map != null)
+ {
+ String s = (String) map.get(Remoting.SERVER_ID);
+ if (s != null)
+ {
+ if (serverId == null)
+ {
+ serverId = s;
+ pingWorked = true;
+ if (trace) log.trace(this + " set serverId to " + serverId);
+ }
+ else
+ {
+ pingWorked = s.equals(serverId);
+ if (!pingWorked)
+ {
+ if (trace) log.trace(this + " detected new serverId: " + s + " != " + serverId);
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
- if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
-
- pingWorked = true;
+ if (pingWorked)
+ {
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+ }
+ else
+ {
+ if (trace) { log.trace("ConnectionValidator did not get successful ping response " + clientInvoker);}
+ }
}
catch (Throwable t)
{
@@ -845,17 +925,69 @@
{
// Sending null client id as don't want to trigger lease on server side. This also means
// that client connection validator will NOT impact client lease, so can not depend on it
- // to maintain client lease with the server.
- InvocationRequest ir =
- new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+ // to maintain client lease with the server
+
+ InvocationRequest ir = null;
+ if (useServerConnectionIdentity)
+ {
+ Map metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", metadata, null, null);
+ }
+ else
+ {
+ ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+ }
if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); }
- clientInvoker.invoke(ir);
+ Object o = clientInvoker.invoke(ir);
+ if (useServerConnectionIdentity && o instanceof InvocationResponse)
+ {
+ Map map = ((InvocationResponse) o).getPayload();
+ if (map != null)
+ {
+ String s = (String) map.get(Remoting.SERVER_ID);
+ if (s != null)
+ {
+ if (serverId == null)
+ {
+ serverId = s;
+ pingWorked = true;
+ if (trace) log.trace(this + " set serverId to " + serverId);
+ }
+ else
+ {
+ pingWorked = s.equals(serverId);
+ if (!pingWorked)
+ {
+ if (trace) log.trace(this + " detected new serverId: " + s + " != " + serverId);
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
- if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
-
- pingWorked = true;
+ if (pingWorked)
+ {
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+ }
+ else
+ {
+ if (trace) { log.trace("ConnectionValidator did not get successful ping response " + clientInvoker);}
+ }
}
catch (Throwable t)
{
13 years, 11 months
JBoss Remoting SVN: r6161 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-12-15 18:05:31 -0500 (Wed, 15 Dec 2010)
New Revision: 6161
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1144: Added useServerConnectionIdentity variable.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2010-11-13 16:54:03 UTC (rev 6160)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2010-12-15 23:05:31 UTC (rev 6161)
@@ -300,6 +300,8 @@
private boolean useClientConnectionIdentity;
+ private boolean useServerConnectionIdentity;
+
// Constructors ---------------------------------------------------------------------------------
/**
@@ -2184,6 +2186,27 @@
}
}
}
+ param = configuration.get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if (param instanceof String)
+ {
+ useServerConnectionIdentity = Boolean.valueOf((String) param).booleanValue();
+ }
+ else if (param != null)
+ {
+ log.warn("value of " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " must be a String: " + param);
+ }
+ else
+ {
+ if (locator.getParameters() != null)
+ {
+ param = locator.getParameters().get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if (param != null)
+ {
+ useServerConnectionIdentity = Boolean.valueOf((String) param).booleanValue();
+ this.configuration.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, param);
+ }
+ }
+ }
PortUtil.updateRange(params);
}
13 years, 11 months