From jboss-remoting-commits at lists.jboss.org Wed Mar 12 23:32:36 2008 Content-Type: multipart/mixed; boundary="===============0258138302030209661==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r3609 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi. Date: Wed, 12 Mar 2008 23:32:36 -0400 Message-ID: --===============0258138302030209661== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2008-03-12 23:32:36 -0400 (Wed, 12 Mar 2008) New Revision: 3609 Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/R= MIInvokerOnewayMarshallingClientTest.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/R= MIInvokerOnewayMarshallingServerTest.java remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/R= MIInvokerOnewayMarshallingTestCase.java Log: JBREM-167: New unit tests. Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/r= mi/RMIInvokerOnewayMarshallingClientTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/= RMIInvokerOnewayMarshallingClientTest.java (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/= RMIInvokerOnewayMarshallingClientTest.java 2008-03-13 03:32:36 UTC (rev 360= 9) @@ -0,0 +1,433 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, 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.transport.rmi; + +import junit.framework.TestCase; +import org.jboss.logging.Logger; +import org.jboss.remoting.Client; +import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.invocation.NameBasedInvocation; +import org.jboss.remoting.marshal.serializable.SerializableMarshaller; +import org.jboss.remoting.transport.Connector; +import org.jboss.remoting.transport.rmi.RMIServerInvoker; +import org.jboss.test.remoting.ComplexReturn; +import org.jboss.test.remoting.TestUtil; +import org.jboss.test.remoting.performance.synchronous.PerformanceServerTe= st; +import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase; +import org.jboss.test.remoting.transport.mock.MockInvokerCallbackHandler; +import org.jboss.test.remoting.transport.mock.MockTest; +import org.w3c.dom.Document; + +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.ByteArrayInputStream; +import java.rmi.MarshalledObject; +import java.rmi.server.UID; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * Unit test for JBREM-167. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Mar 12, 2008 + *

+ */ +public class RMIInvokerOnewayMarshallingClientTest extends TestCase +{ + + private String sessionId =3D new UID().toString(); + private Client client; + private Connector connector; + private InvokerLocator locator; + private int port =3D RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1; + protected String transport =3D "rmi"; + + private static final Logger log =3D Logger.getLogger(RMIInvokerOnewayMa= rshallingClientTest.class); + + public void init(Map metadata) + { + try + { + InvokerLocator locator =3D new InvokerLocator(buildLocatorURI(met= adata, this.port)); + //InvokerLocator locator =3D new InvokerLocator(getTransport() + = "://localhost:" + port); + System.out.println("client locator: " + locator); + client =3D new Client(locator, "mock"); + client.connect(); + } + catch(Exception e) + { + log.error(e.getMessage(), e); + } + } + + private String buildLocatorURI(Map metadata, int port) + { + if(metadata =3D=3D null || metadata.size() =3D=3D 0) + { + return transport + "://localhost:" + port; + } + else + { + StringBuffer uriBuffer =3D new StringBuffer(transport + "://local= host:" + port); + + Set keys =3D metadata.keySet(); + if(keys.size() > 0) + { + uriBuffer.append("/?"); + } + + Iterator itr =3D keys.iterator(); + while(itr.hasNext()) + { + String key =3D (String) itr.next(); + String value =3D (String) metadata.get(key); + uriBuffer.append(key + "=3D" + value + "&"); + } + return uriBuffer.substring(0, uriBuffer.length() - 1); + } + } + + private InvokerLocator initServer(Map metadata, int serverPort) throws = Exception + { + if(serverPort < 0) + { + serverPort =3D TestUtil.getRandomPort(); + } + log.debug("port =3D " + serverPort); + +// InvokerRegistry.registerInvoker("mock", MockClientInvoker.class, M= ockServerInvoker.class); + connector =3D new Connector(); + + InvokerLocator locator =3D new InvokerLocator(buildLocatorURI(metada= ta, serverPort)); + System.out.println("Server locator: " + locator); + + //InvokerLocator locator =3D new InvokerLocator(transport + "://loca= lhost:" + port); + StringBuffer buf =3D new StringBuffer(); + buf.append("\n"); + buf.append("\n"); + buf.append(" org.jboss.test.remoting.= transport.mock.MockServerInvocationHandler\n"); + buf.append("\n"); + Document xml =3D DocumentBuilderFactory.newInstance().newDocumentBui= lder().parse(new ByteArrayInputStream(buf.toString().getBytes())); + connector.setInvokerLocator(locator.getLocatorURI()); + connector.setConfiguration(xml.getDocumentElement()); + //connector.create(); + connector.start(); + return locator; + } + + + public void setUp() throws Exception + { + Map metadata =3D new HashMap(); + String newMetadata =3D System.getProperty(PerformanceTestCase.REMOTI= NG_METADATA); + if(newMetadata !=3D null && newMetadata.length() > 0) + { + metadata.putAll(PerformanceServerTest.parseMetadataString(newMeta= data)); + } + + metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port= + 1)); + locator =3D initServer(metadata, -1); + metadata.put(InvokerLocator.DATATYPE, SerializableMarshaller.DATATYP= E); + metadata.put(RMIServerInvoker.RMI_ONEWAY_MARSHALLING, "true"); + metadata.put("serializationtype", "jboss"); + init(metadata); + log.info("Using metadata: " + metadata); + } + + public void tearDown() throws Exception + { + if(connector !=3D null) + { + connector.stop(); + connector.destroy(); + connector =3D null; + } + locator =3D null; + if(client !=3D null) + { + client.disconnect(); + client =3D null; + } + } + + /** + * Test simple invocation and adding of listener with push callback (me= aning server + * will send callback message when it gets it) to a local callback serv= er + * + * @throws Throwable + */ + public void testLocalPushCallbackWithDatatype() throws Throwable + { + setUp(); + runLocalPushCallback(); + } + + public void runLocalPushCallback() throws Throwable + { + log.debug("running testLocalPushCallback()"); + + sessionId =3D new UID().toString(); + + sessionId =3D client.getSessionId(); + MockInvokerCallbackHandler handler =3D new MockInvokerCallbackHandle= r(sessionId); + + log.debug("client.getInvoker().getLocator()" + client.getInvoker().g= etLocator()); + + // simple invoke, should return bar + Object ret =3D makeInvocation("foo", "bar"); + assertTrue("Result of testLocalPushCallback() invocation of foo.", "= bar".equals(ret)); + client.addListener(handler, locator); + // invoke which should cause callback + ret =3D makeInvocation("test", "test"); + // allow time for callback + Thread.sleep(3000); + log.debug("done sleeping."); + int callbacksPerformed =3D handler.isCallbackReceived(); + log.debug("callbacksPerformed after adding listener is " + callbacks= Performed); + assertTrue("Result of testLocalPushCallback() failed since did not g= et callback.", + (callbacksPerformed =3D=3D 1)); + // Can now call direct on client + client.removeListener(handler); + // shouldn't get callback now since removed listener + ret =3D makeInvocation("test", "test"); + // allow time for callback + Thread.sleep(2000); + log.debug("done sleeping."); + callbacksPerformed =3D handler.isCallbackReceived(); + log.debug("callbackPerformed after removing listener is " + callback= sPerformed); + assertTrue("Result of testLocalPushCallback() failed since did get c= allback " + + "but have been removed as listener.", + (callbacksPerformed =3D=3D 1)); + } + + /** + * Test simple invocation and adding of listener with push callback (me= aning server + * will send callback message when it gets it) to a remote callback ser= ver + * + * @throws Throwable + */ + public void testRemotePushCallbackWithDataType() throws Throwable + { + setUp(); + runRemotePushCallback(); + } + + public void runRemotePushCallback() throws Throwable + { + log.debug("running testRemotePushCallback()"); + + sessionId =3D new UID().toString(); + //InvokerLocator locator =3D client.getInvoker().getLocator(); + sessionId =3D client.getSessionId(); + MockInvokerCallbackHandler handler =3D new MockInvokerCallbackHandle= r(sessionId); + + log.debug("client.getInvoker().getLocator()" + client.getInvoker().g= etLocator()); + + // simple invoke, should return bar + Object ret =3D makeInvocation("foo", "bar"); + assertTrue("Result of testRemotePushCallback() invocation of foo.", = "bar".equals(ret)); + client.addListener(handler, locator); + // invoke which should cause callback + ret =3D makeInvocation("test", "test"); + // allow time for callback + Thread.sleep(3000); + log.debug("done sleeping."); + // TODO: No way to currently check the remote callback handler + // to see if it got callback -TME + /* + int callbacksPerformed =3D handler.isCallbackReceived(); + log.debug("callbacksPerformed after adding listener is " + callbacks= Performed); + assertTrue("Result of testRemotePushCallback() failed since did not = get callback.", + (callbacksPerformed =3D=3D 1)); + */ + // Can now call direct on client + client.removeListener(handler); + // shouldn't get callback now since removed listener + ret =3D makeInvocation("test", "test"); + // allow time for callback + Thread.sleep(2000); + log.debug("done sleeping."); + /* + callbacksPerformed =3D handler.isCallbackReceived(); + log.debug("callbackPerformed after removing listener is " + callback= sPerformed); + assertTrue("Result of testRemotePushCallback() failed since did get = callback " + + "but have been removed as listener.", + (callbacksPerformed =3D=3D 1)); + */ + } + + /** + * Tests simple invocation and pull callbacks. Meaning will add a list= ener and + * will then have to get the callbacks from the server. + * + * @throws Throwable + */ + public void testPullCallbackWithDataType() throws Throwable + { + setUp(); + runPullCallback(); + } + + public void runPullCallback() throws Throwable + { + log.debug("running testPullCallback()"); + + // should be null by default, since don't have connector started, bu= t setting anyway + //client.setClientLocator(null); + + MockInvokerCallbackHandler handler =3D new MockInvokerCallbackHandle= r(sessionId); + + // simple invoke, should return bar + Object ret =3D makeInvocation("bar", "foo"); + assertTrue("Result of runPullCallbackTest() invocation of bar.", "fo= o".equals(ret)); + client.addListener(handler); + // invoke which should cause callback on server side + ret =3D makeInvocation("test", "test"); + // allow time for callback + Thread.sleep(2000); + ret =3D client.getCallbacks(handler); + log.debug("getCallbacks returned " + ret); + log.debug("should have something."); + assertTrue("Result of runPullCallbackTest() getCallbacks() after add= listener.", + ret !=3D null); + // can now call directly on client + //ret =3D makeInvocation("removeListener", null); + client.removeListener(handler); + ret =3D makeInvocation("getCallbacks", null); + log.debug("getCallbacks returned " + ret); + log.debug("should have been empty."); + assertTrue("Result of runPullCallbackTest() getCallbacks() after rem= ove listener.", + ret =3D=3D null); + } + + /** + * Tests complex invocation to get object containing array of complex o= bjects. + * + * @throws Throwable + */ + public void testArrayReturnWithDataType() throws Throwable + { + setUp(); + runArrayReturn(); + } + + public void runArrayReturn() throws Throwable + { + // simple invoke, should return bar + Object ret =3D makeInvocation("testComplexReturn", null); + ComplexReturn complexRet =3D (ComplexReturn) ret; + MockTest[] mockTests =3D complexRet.getMockTests(); + assertTrue("ComplexReturn's array should contain 2 items", + 2 =3D=3D mockTests.length); + for(int x =3D 0; x < mockTests.length; x++) + { + System.err.println(mockTests[x]); + MockTest test =3D mockTests[x]; + assertNotNull("MockTest should not be null", test); + } + +// assertTrue("Result of runPullCallbackTest() invocation of ba= r.", +// "foo".equals(ret)); + } + + /** + * Tests complex invocation to get marshalled object. + * + * @throws Throwable + */ + public void testMarshalledObjectReturnWithDataType() throws Throwable + { + setUp(); + runMarshalledObjectReturn(); + } + + public void runMarshalledObjectReturn() throws Throwable + { + // simple invoke, should return bar + Object ret =3D makeInvocation("testMarshalledObject", null); + ret =3D ((MarshalledObject) ret).get(); + ComplexReturn complexRet =3D (ComplexReturn) ret; + MockTest[] mockTests =3D complexRet.getMockTests(); + assertTrue("ComplexReturn's array should contain 2 items", + 2 =3D=3D mockTests.length); + for(int x =3D 0; x < mockTests.length; x++) + { + System.err.println(mockTests[x]); + MockTest test =3D mockTests[x]; + assertNotNull("MockTest should not be null", test); + } + +// assertTrue("Result of runPullCallbackTest() invocation of ba= r.", +// "foo".equals(ret)); + } + + private Object makeInvocation(String method, String param) throws Throw= able + { + Object ret =3D client.invoke(new NameBasedInvocation(method, + new Object[]{para= m}, + new String[]{Stri= ng.class.getName()}), + null); + + return ret; + } + +// public static void main(String[] args) +// { +// RMIInvokerClientTest client =3D new RMIInvokerClientTest(); +// try +// { +// client.setUp(); +// client.testArrayReturn(); +// client.testArrayReturnWithDataType(); +// client.testLocalPushCallback(); +// client.testLocalPushCallbackWithDatatype(); +// client.testMarshalledObjectReturn(); +// client.testMarshalledObjectReturnWithDataType(); +// client.testPullCallback(); +// client.testPullCallbackWithDataType(); +// client.testRemotePushCallback(); +// client.testRemotePushCallbackWithDataType(); +// } +// catch (Throwable throwable) +// { +// throwable.printStackTrace(); +// } +// finally +// { +// try +// { +// client.tearDown(); +// } +// catch (Exception e) +// { +// e.printStackTrace(); +// } +// } +// +// } + +} Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/r= mi/RMIInvokerOnewayMarshallingServerTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/= RMIInvokerOnewayMarshallingServerTest.java (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/= RMIInvokerOnewayMarshallingServerTest.java 2008-03-13 03:32:36 UTC (rev 360= 9) @@ -0,0 +1,151 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, 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.transport.rmi; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import org.jboss.jrunit.extensions.ServerTestCase; +import org.jboss.logging.Logger; +import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.ServerInvocationHandler; +import org.jboss.remoting.marshal.serializable.SerializableMarshaller; +import org.jboss.remoting.transport.Connector; +import org.jboss.remoting.transport.rmi.RMIServerInvoker; +import org.jboss.test.remoting.TestUtil; +import org.jboss.test.remoting.performance.synchronous.PerformanceServerTe= st; +import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase; +import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler; + + +/** + * Unit test for JBREM-167. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Mar 12, 2008 + *

+ */ +public class RMIInvokerOnewayMarshallingServerTest extends ServerTestCase +{ + private int port =3D RMIServerInvoker.DEFAULT_REGISTRY_PORT - 1; + protected String transport =3D "rmi"; + private Connector connector; + + private static final Logger log =3D Logger.getLogger(RMIInvokerOnewayMa= rshallingServerTest.class); + + public void init(Map metatdata) throws Exception + { + if(port < 0) + { + port =3D TestUtil.getRandomPort(); + } + log.debug("port =3D " + port); + + connector =3D new Connector(); + InvokerLocator locator =3D new InvokerLocator(buildLocatorURI(metatd= ata)); + System.out.println("server locator: " + locator); + connector.setInvokerLocator(locator.getLocatorURI()); + connector.start(); + connector.addInvocationHandler(getSubsystem(), getServerInvocationHa= ndler()); + } + + private String buildLocatorURI(Map metadata) + { + if(metadata =3D=3D null || metadata.size() =3D=3D 0) + { + return transport + "://localhost:" + port; + } + else + { + StringBuffer uriBuffer =3D new StringBuffer(transport + "://local= host:" + port); + + Set keys =3D metadata.keySet(); + if(keys.size() > 0) + { + uriBuffer.append("/?"); + } + + Iterator itr =3D keys.iterator(); + while(itr.hasNext()) + { + String key =3D (String) itr.next(); + String value =3D (String) metadata.get(key); + uriBuffer.append(key + "=3D" + value + "&"); + } + return uriBuffer.substring(0, uriBuffer.length() - 1); + } + } + + protected String getSubsystem() + { + return "mock"; + } + + protected ServerInvocationHandler getServerInvocationHandler() + { + return new MockServerInvocationHandler(); + } + + public void setUp() throws Exception + { + Map metadata =3D new HashMap(); + String newMetadata =3D System.getProperty(PerformanceTestCase.REMOTI= NG_METADATA); + if(newMetadata !=3D null && newMetadata.length() > 0) + { + metadata.putAll(PerformanceServerTest.parseMetadataString(newMeta= data)); + } + metadata.put(RMIServerInvoker.REGISTRY_PORT_KEY, String.valueOf(port= + 1)); + metadata.put(InvokerLocator.DATATYPE, SerializableMarshaller.DATATYP= E); + metadata.put(RMIServerInvoker.RMI_ONEWAY_MARSHALLING, "true"); + metadata.put("serializationtype", "jboss"); + init(metadata); + } + + public void tearDown() throws Exception + { + if(connector !=3D null) + { + connector.stop(); + connector.destroy(); + } + } + + public static void main(String[] args) + { + RMIInvokerOnewayMarshallingServerTest server =3D new RMIInvokerOnewa= yMarshallingServerTest(); + try + { + server.setUp(); + Thread.currentThread().sleep(6000000); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + +} Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/r= mi/RMIInvokerOnewayMarshallingTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/= RMIInvokerOnewayMarshallingTestCase.java (rev 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/= RMIInvokerOnewayMarshallingTestCase.java 2008-03-13 03:32:36 UTC (rev 3609) @@ -0,0 +1,44 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, 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.transport.rmi; + +import org.jboss.test.remoting.transport.InvokerTestDriver; + +/** + * Unit test for JBREM-167. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright Mar 12, 2008 + *

+ */ +public class RMIInvokerOnewayMarshallingTestCase extends InvokerTestDriver +{ + public void declareTestClasses() + { + addTestClasses(RMIInvokerOnewayMarshallingClientTest.class.getName(), + 1, + RMIInvokerOnewayMarshallingServerTest.class.getName()= ); + } +} \ No newline at end of file --===============0258138302030209661==--