geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r351623 [4/4] - in /geronimo/trunk/sandbox/freeorb/geronimo-orb: ./ src/main/java/org/apache/geronimo/corba/ src/main/java/org/apache/geronimo/corba/channel/ src/main/java/org/apache/geronimo/corba/channel/nio/ src/main/java/org/apache/gero...
Date Fri, 02 Dec 2005 07:59:10 GMT
Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/test/HelloWorldTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/test/HelloWorldTest.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/test/HelloWorldTest.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/test/HelloWorldTest.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,143 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.geronimo.corba.testframework.RemoteTest;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Object;
+import org.omg.CORBA.Policy;
+import org.omg.PortableServer.IdAssignmentPolicyValue;
+import org.omg.PortableServer.ImplicitActivationPolicyValue;
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.Servant;
+import org.omg.PortableServer.ServantRetentionPolicyValue;
+
+public abstract class HelloWorldTest extends RemoteTest {
+
+    static protected final String ORBClassKey = "org.omg.CORBA.ORBClass";
+    static protected final String ORBSingletonClassKey = "org.omg.CORBA.ORBSingletonClass";
+
+	public void setUp() throws Exception {
+		startTestAgent("server", true);
+		startTestAgent("client", true);
+	}
+	
+	ORB orb;
+
+	HelloObjectOperations hello;
+
+	public void serverBefore1() throws Exception {
+
+		hello = new HelloObjectServant();
+
+		orb = ORB.init(new String[0], getAgentProperties());
+
+		//com.sun.corba.se.spi.orb.ORB o = (com.sun.corba.se.spi.orb.ORB) orb;
+		//o.giopDebugFlag = true;
+		//o.giopVersionDebugFlag = true;
+		//o.transportDebugFlag = true;
+		
+        new Thread() {
+            public void run() {
+                orb.run();
+            }
+        }.start();
+
+		POA root = (POA) orb.resolve_initial_references("RootPOA");
+
+		List plist = new ArrayList();
+
+		plist
+				.add(root
+						.create_id_assignment_policy(IdAssignmentPolicyValue.SYSTEM_ID));
+
+		plist
+				.add(root
+						.create_implicit_activation_policy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION));
+
+		plist
+				.add(root
+						.create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN));
+
+		Policy[] policies = (Policy[]) plist.toArray(new Policy[0]);
+
+		POA poa = root.create_POA("poa1", null, policies);
+
+		org.omg.CORBA.Object ref = poa.servant_to_reference((Servant) hello);
+
+		String ior = orb.object_to_string(ref);
+		
+		poa.the_POAManager().activate();
+
+		putProperty("serverIOR", ior);
+	}
+
+	public void clientBefore1() throws Exception {
+		orb = ORB.init(new String[0], getAgentProperties());
+		
+
+		String ior = getProperty("serverIOR");
+		assertNotNull(ior);
+
+		System.out.println("ior is: " + ior);
+
+		System.out.println("ORB is "+orb);
+		
+		Object obj = orb.string_to_object(ior);
+		assertNotNull(obj);
+		
+		hello = HelloObjectHelper.narrow(obj);
+		
+		assertNotNull(hello);
+
+	}
+	
+	public void serverAfter1() throws Exception {
+		orb.shutdown(false);
+	}
+
+	
+	public void serverTest2() {
+		System.out.println("hej far");
+	}
+	
+	public void clientTest1() throws Exception {
+
+		try {
+		
+		//System.out.println("ce1.1");
+		//hello.hello11();
+
+		System.out.println("ce1.2");
+		System.out.flush();
+		hello.hello1((short) 0xba);
+		
+		System.out.println("ce1.3");
+		hello.hello2(0x01020304);
+
+		} catch (Throwable e) {
+			e.printStackTrace();
+			throw new RuntimeException(e);
+		}
+		
+	}
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTest.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTest.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTest.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,175 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.omg.CORBA.Object;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+
+public class RemoteTest extends Assert implements Test {
+	public RemoteTest() {
+	}
+
+	public void setUp() throws Exception {
+	}
+
+	protected void startTestAgent(String agentName, boolean fork)
+			throws Exception {
+		testAgentManager.addAgent(agentName, getAgentProperties(agentName),
+				fork);
+	}
+
+	protected void startTestAgent(String agentName) throws Exception {
+		startTestAgent(agentName, true);
+	}
+
+	protected Properties getAgentProperties() throws Exception {
+		if (driver == null) {
+			return System.getProperties();
+		} else {
+			return driver.getAgentProperties(agentName);
+		}
+	}
+
+	protected Properties getAgentProperties(String agentName) {
+		Properties props = new Properties();
+		addIfNonNull(props, "java.ext.dirs", System.getProperties());
+		return props;
+	}
+
+	private void addIfNonNull(Properties props, String string,
+			Properties properties) {
+		String val = properties.getProperty(string);
+		if (val != null) {
+			props.setProperty(string, val);
+		}
+	}
+
+	public void putProperty(String id, String value) {
+		try {
+			driver.putProperty(id, value);
+		} catch (RemoteException e) {
+			throw new Error(e);
+		}
+	}
+
+	public String getProperty(String id) {
+		try {
+			return (String) driver.getProperty(id);
+		} catch (RemoteException e) {
+			throw new Error(e);
+		}
+	}
+
+	protected static final String testKeyword = "Test";
+
+	private void ensureTstMethods() {
+		if (testMethods == null) {
+			Method[] methods = this.getClass().getMethods();
+			testMethods = new HashSet();
+			for (int i = 0; i < methods.length; i++) {
+				if (methods[i].getName().equals("countTestCases"))
+					continue;
+
+				int testIndex = methods[i].getName().indexOf(testKeyword);
+				if (testIndex > 0) {
+					String testName = methods[i].getName().substring(
+							testIndex + testKeyword.length());
+					testMethods.add(testName);
+				}
+			}
+		}
+	}
+
+	public int countTestCases() {
+		ensureTstMethods();
+		return testMethods.size();
+	}
+
+	// public void testIt() {}
+
+	private Set testMethods;
+
+	private TestAgentManager testAgentManager;
+
+	public void run(TestResult result) {
+		ensureTstMethods();
+		try {
+			testAgentManager = new TestAgentManager(this, this.getClass()
+					.getName(), generateDriverName());
+			setTstDriver(testAgentManager.getTestDriver());
+			System.out.println("BEGIN setUp : "+getClass().getName());
+			setUp();
+			System.out.println("END setUp : "+getClass().getName());
+			Iterator i = testMethods.iterator();
+			while (i.hasNext()) {
+				String testName = (String) i.next();
+				RemoteTestCase testCase = new RemoteTestCase(this,
+						testAgentManager, testName);
+				testCase.run(result);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new Error(e);
+		}
+		testAgentManager.shutdownAllAgents();
+	}
+
+	private String generateDriverName() {
+		return "testDriver." + this.getClass().getName() + "."
+				+ Math.rint(Integer.MAX_VALUE);
+
+	}
+
+	private TestDriver driver;
+
+	private String agentName;
+
+	protected void setTstDriver(TestDriver driver) {
+		this.driver = driver;
+	}
+
+	public void setAgentName(String agentName) {
+		this.agentName = agentName;
+	}
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestCase.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestCase.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestCase.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestCase.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,78 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+class RemoteTestCase extends TestCase {
+
+    public RemoteTestCase(Object testObject, TestAgentManager testAgentManager, String testName)
{
+        super(testObject.getClass().getName() + " :: " + testName);
+        this.testAgentManager = testAgentManager;
+        methodCalls = new ArrayList();
+        Method[] methods = testObject.getClass().getMethods();
+        String[] testPhases = new String[] {"Before", RemoteTest.testKeyword, "After" };
+        for(int phaseIndex = 0; phaseIndex < testPhases.length; phaseIndex++) {
+            Iterator agentNameIter = testAgentManager.getAgentNames().iterator();
+            while(agentNameIter.hasNext()) {
+                String agentName = (String) agentNameIter.next();
+                for(int agentIndex = 0; agentIndex < methods.length; agentIndex++) {
+                    String methodName = methods[agentIndex].getName();
+                    if(methodName.equals(agentName + testPhases[phaseIndex] + testName))
{
+                        AgentMethodPair pair = new AgentMethodPair(agentName, methods[agentIndex].getName());
+                        methodCalls.add(pair);
+                    }
+                }            
+            }
+        }
+        
+    }
+    
+    private class AgentMethodPair {
+        public AgentMethodPair(String agentName, String methodName) {
+            this.agentName = agentName;
+            this.methodName = methodName;
+        }
+        public String agentName;
+        public String methodName;
+    }
+    
+    private List methodCalls;
+
+    private TestAgentManager testAgentManager;
+
+    protected void runTest() throws Throwable {
+        Iterator it = methodCalls.iterator();
+        while(it.hasNext()) {
+            AgentMethodPair pair = (AgentMethodPair) it.next();
+            try {
+                testAgentManager.invokeOnAgent(pair.agentName, pair.methodName);
+            }
+            catch(InvocationTargetException e) {
+            		e.printStackTrace();
+                throw e.getTargetException();
+            }
+        }
+    }
+}
+

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestUtil.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestUtil.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/RemoteTestUtil.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,134 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+
+class RemoteTestUtil {
+	public static void invokeAndRethrow(Object obj, Method method)
+			throws Throwable {
+		try {
+			method.invoke(obj, null);
+		} catch (InvocationTargetException e) {
+			throw e.getTargetException();
+		}
+
+	}
+
+	// Forks a new java process.
+	public static Process execJava(String className, Properties props,
+			String[] javaArgs) throws IOException {
+		// Get path to java binary
+		File javaHome = new File(System.getProperty("java.home"));
+		File javaBin = new File(new File(javaHome, "bin"), "java");
+
+		// Get current class path
+		URLClassLoader cl = (URLClassLoader) RemoteTest.class.getClassLoader();
+		URL[] classPathUrls = cl.getURLs();
+
+		// Construct list of arguments
+		List binArgs = new ArrayList();
+
+		// First argument is the java binary to run
+		binArgs.add(javaBin.getPath());
+
+		// Add the classpath to argument list
+		binArgs.add("-classpath");
+		String classPath = ""
+				+ new File(classPathUrls[0].getPath().replaceAll("%20", " "));
+		for (int i = 1; i < classPathUrls.length; i++) {
+			classPath += File.pathSeparator
+					+ new File(classPathUrls[i].getPath()
+							.replaceAll("%20", " "));
+		}
+		classPath += "";
+		binArgs.add(classPath);
+
+		// Add properties to argument list
+		Enumeration en = props.keys();
+		while (en.hasMoreElements()) {
+			String key = (String) en.nextElement();
+			binArgs.add("-D" + key + "=" + props.getProperty(key));
+		}
+
+		// Add class containing main method to arg list
+		binArgs.add(className);
+
+		// Add java arguments
+		for (int i = 0; i < javaArgs.length; i++) {
+			binArgs.add(javaArgs[i]);
+		}
+
+		// Convert arg list to array
+		String[] argArray = new String[binArgs.size()];
+		for (int i = 0; i < argArray.length; i++) {
+			argArray[i] = (String) binArgs.get(i);
+		}
+
+		for (int i = 0; i < argArray.length; i++) {
+			System.out.print(argArray[i] + " ");
+		}
+		System.out.println();
+
+		// Fork process
+		return Runtime.getRuntime().exec(argArray);
+	}
+
+	public static void redirectStream(final InputStream in,
+			final OutputStream out, final String streamName) {
+		Thread stdoutTransferThread = new Thread() {
+			public void run() {
+				PrintWriter pw = new PrintWriter(new OutputStreamWriter(out),
+						true);
+				try {
+					BufferedReader reader = new BufferedReader(
+							new InputStreamReader(in));
+					String line;
+					while ((line = reader.readLine()) != null) {
+						pw.print("[");
+						pw.print(streamName);
+						pw.print("] ");
+						pw.println(line);
+					}
+					pw.print("[");
+					pw.print(streamName);
+					pw.print("] ");
+					pw.println("EOF");
+				} catch (Throwable e) {
+					e.printStackTrace();
+					// throw new Error(e);
+				}
+			}
+		};
+		stdoutTransferThread.start();
+	}
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgent.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgent.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgent.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgent.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,173 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.io.IOException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.util.Properties;
+
+class TestAgent {
+
+    private final String agentName;
+    private int exitCode = -1;
+    private VMController controller;
+    private boolean running = false;
+    
+    private final Object shutdownOrReadyMonitor = new Object();
+	private final boolean fork;
+
+    public TestAgent(String agentName, boolean fork) {
+        this.agentName = agentName;
+		this.fork = fork;
+    }
+    
+    public void start(String driverName, String testClassName, Properties props) throws IOException
{
+        // fork vm
+
+        final String[] javaArgs = {testClassName, agentName, "localhost", 
+                Integer.toString(Registry.REGISTRY_PORT), driverName, fork ? "true" : "false"
};
+        
+        running = true;
+        
+        if (fork) {
+        
+        final Process proc = RemoteTestUtil.execJava(this.getClass().getName(), props, javaArgs);
+        
+        RemoteTestUtil.redirectStream(proc.getInputStream(), System.out, agentName+":out");
+        RemoteTestUtil.redirectStream(proc.getErrorStream(), System.err, agentName+":err");
+
+        try {
+            synchronized(shutdownOrReadyMonitor) {
+                // Create a thread to notify us if the agent JVM terminates
+                new Thread() {
+                    public void run() {
+                        try {
+                            proc.waitFor();
+                        }
+                        catch(InterruptedException e) {}
+                        exitCode = proc.exitValue();
+                        running = false;
+                        synchronized(shutdownOrReadyMonitor) {
+                            shutdownOrReadyMonitor.notify();
+                        }
+                    }
+                }.start();
+                
+                while(controller == null) {
+                  	shutdownOrReadyMonitor.wait();
+                }
+            }
+        }
+        catch(InterruptedException e) { throw new Error(e); }
+        
+        } else {
+        
+        		new Thread() {
+        			
+        			public void run() {
+        				
+        				try {
+							TestAgent.main(javaArgs);
+						} catch (Exception e) {
+							// TODO Auto-generated catch block
+							e.printStackTrace();
+						}
+        				
+                        running = false;
+                        synchronized(shutdownOrReadyMonitor) {
+                            shutdownOrReadyMonitor.notify();
+                        }
+
+        			}
+        			
+        		}.start();
+        	
+        }
+        
+
+        if(!running) {
+            throw new Error("Unable to start agent:" + 
+                    " Process terminated unexpectedly with exit code " + 
+                    getExitCode());
+        }        
+    }
+    
+    public int getExitCode() { return exitCode; }
+    
+    public void agentReady(VMController controller) {
+        this.controller = controller;
+        synchronized(shutdownOrReadyMonitor) {
+            shutdownOrReadyMonitor.notify();
+        }
+    }
+    
+    public VMController getController() {
+    	synchronized(shutdownOrReadyMonitor) {
+    		while(controller == null) {
+    			try {
+    				shutdownOrReadyMonitor.wait();
+				} catch (InterruptedException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+    		}
+    	}
+    	return controller;
+    }
+    
+    
+    /** this is the main routine run in test agents */
+    public static void main(String[] args) throws Exception {
+        String testClassName = args[0];
+        String agentName = args[1];
+        String registryHost = args[2];
+        int registryPort = Integer.parseInt(args[3]);
+        String driverName = args[4];
+        String fork = args[5];
+
+        Registry reg = LocateRegistry.getRegistry(registryHost, registryPort);
+
+        Class c = Class.forName(testClassName);
+        if (!RemoteTest.class.isAssignableFrom(c)) {
+            throw new Exception("Unable to cast to RemoteTst class");
+        }
+
+        TestDriver driver = (TestDriver) reg.lookup(driverName);
+
+        RemoteTest test = (RemoteTest) c.newInstance();
+        test.setTstDriver(driver);
+        VMControllerImpl controller = new VMControllerImpl(test);
+
+        test.setAgentName(agentName);
+        
+        driver.agentReady(agentName, controller);
+        
+        synchronized(controller.terminateMonitor) {
+            controller.terminateMonitor.wait();
+        }
+        
+        if ("true".equals(fork)) {
+            System.out.println("Client exiting (1)");
+            System.exit(0);        	
+        } else {
+            System.out.println("Client exiting (2)");
+        }
+    }
+
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgentManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgentManager.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgentManager.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestAgentManager.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,121 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.io.IOException;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class TestAgentManager {
+	
+	final RemoteTest tst;
+
+	public TestAgentManager(RemoteTest tst, String testClassName, String driverName)
+			throws RemoteException {
+		this.tst = tst;
+		this.testClassName = testClassName;
+		setTestDriver(new TestDriverImpl(this, driverName));
+		setupRegistry();
+		bindDriverInRegistry();
+	}
+
+	public void addAgent(String agentName, Properties props, boolean fork) throws IOException
{
+		TestAgent agent = new TestAgent(agentName, fork);
+		getAgentsByName().put(agentName, agent);
+		agentNames.add(agentName);
+		agent.start(getTestDriver().getDriverName(), testClassName, props);
+	}
+
+	public String getClassName() {
+		return testClassName;
+	}
+
+	public List getAgentNames() {
+		return agentNames;
+	}
+
+	public void invokeOnAgent(String agentName, String methodName)
+			throws Exception {
+		
+		TestAgent agent = ((TestAgent) getAgentsByName().get(agentName));
+		VMController controller = agent.getController();
+		controller.invoke(
+				methodName);
+	}
+
+	public void shutdownAllAgents() {
+		Iterator it = agentNames.iterator();
+		while (it.hasNext()) {
+			TestAgent agent = (TestAgent) agentsByName.get(it.next());
+			try {
+				agent.getController().exit(0);
+			} catch (Exception e) {
+			}
+		}
+	}
+
+	private List agentNames = new ArrayList();
+
+	private Map agentsByName = new HashMap();
+
+	private TestDriverImpl testDriver;
+
+	private Registry rmiRegistry;
+
+	private String testClassName;
+
+	private void setupRegistry() throws RemoteException {
+		if (rmiRegistry == null) {
+			try {
+				rmiRegistry = LocateRegistry
+						.createRegistry(Registry.REGISTRY_PORT);
+			} catch (Exception e) {
+				e.printStackTrace();
+				rmiRegistry = LocateRegistry
+						.getRegistry(Registry.REGISTRY_PORT);
+			}
+		}
+	}
+
+	private void bindDriverInRegistry() throws RemoteException {
+		rmiRegistry.rebind(getTestDriver().getDriverName(), getTestDriver());
+	}
+
+	TestDriverImpl getTestDriver() {
+		return testDriver;
+	}
+
+	private void setTestDriver(TestDriverImpl testDriver) {
+		this.testDriver = testDriver;
+	}
+
+	public void setAgentsByName(Map agentsByName) {
+		this.agentsByName = agentsByName;
+	}
+
+	public Map getAgentsByName() {
+		return agentsByName;
+	}
+
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriver.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriver.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriver.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriver.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,32 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.Properties;
+
+
+public interface TestDriver extends Remote {
+
+	// agent reports that it is ready to roll...
+	void agentReady(String agentName, VMController controller) throws RemoteException;
+	void putProperty(String id, String value) throws RemoteException;
+    String getProperty(String id) throws RemoteException;
+	Properties getAgentProperties(String agentName) throws RemoteException;
+    
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriverImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriverImpl.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriverImpl.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/TestDriverImpl.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,67 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+class TestDriverImpl extends UnicastRemoteObject implements
+TestDriver {
+    /**
+     * 
+     */
+    private final TestAgentManager testAgentManager;
+    private Map properties = new HashMap();
+
+    public TestDriverImpl(TestAgentManager manager, String driverName) throws RemoteException
{
+        testAgentManager = manager;
+        this.driverName = driverName;
+    }
+    
+    public void agentReady(String agentName, VMController controller)
+    throws RemoteException {
+        System.out.println("AgentReady: " + agentName);
+        TestAgent testAgent = (TestAgent) testAgentManager.getAgentsByName().get(agentName);
+        testAgent.agentReady(controller);
+    }
+
+    public String getDriverName() { return driverName; }
+
+    String driverName;
+    
+    protected TestDriverImpl(TestAgentManager manager) throws RemoteException {
+        super();
+        testAgentManager = manager;
+        System.out.println("Constructing TestDriverImpl");
+    }
+
+    public synchronized void putProperty(String id, String value) throws RemoteException
{
+        properties.put(id, value);
+        
+    }
+
+    public synchronized String getProperty(String id) throws RemoteException {
+        return (String) properties.get(id);
+    }
+
+	public Properties getAgentProperties(String agentName) throws RemoteException {
+		return testAgentManager.tst.getAgentProperties(agentName);
+	}
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMController.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMController.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMController.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMController.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.rmi.Remote;
+
+public interface VMController extends Remote {
+	public void invoke(String methodName) throws Exception;
+	public void exit(int code) throws Exception;
+}

Added: geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMControllerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMControllerImpl.java?rev=351623&view=auto
==============================================================================
--- geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMControllerImpl.java
(added)
+++ geronimo/trunk/sandbox/freeorb/geronimo-orb/src/test/java/org/apache/geronimo/corba/testframework/VMControllerImpl.java
Thu Dec  1 23:58:55 2005
@@ -0,0 +1,54 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.corba.testframework;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+
+class VMControllerImpl extends UnicastRemoteObject implements VMController {
+    /**
+     * 
+     */
+    private final RemoteTest remoteTest;
+
+    public VMControllerImpl(RemoteTest remoteTest) throws RemoteException {
+        super();
+
+        this.remoteTest = remoteTest;
+    }
+
+    public void invoke(String methodName) throws Exception {
+        try {
+            Method method = this.remoteTest.getClass().getMethod(methodName,null);
+            RemoteTestUtil.invokeAndRethrow(this.remoteTest, method);
+        }
+        catch(Throwable t) {
+            throw new InvocationTargetException(t);
+        }
+    }
+
+    public void exit(int code) throws Exception {
+        System.out.println("Exiting VM peacefully");
+        synchronized(terminateMonitor) {
+            terminateMonitor.notify();
+        }
+    }
+    
+    public Object terminateMonitor = new Object();
+}



Mime
View raw message