Title: [2536] trunk/openejb3/openejb-itests/src/main/java/org/openejb/test: Test server implementations for:
Revision
2536
Author
dblevins
Date
2006-03-10 03:51:28 -0500 (Fri, 10 Mar 2006)

Log Message

Test server implementations for:
 - ejb over http
 - ejb over http over a servlet in tomcat

Fixed up Test Runner to post required jndi information
Fixed up remote test server to do a better job of starting the server

Modified Paths

Added Paths

Diff

Added: trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/RemoteHttpTestServer.java (2535 => 2536)

--- trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/RemoteHttpTestServer.java	2006-03-10 08:45:43 UTC (rev 2535)
+++ trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/RemoteHttpTestServer.java	2006-03-10 08:51:28 UTC (rev 2536)
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  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.openejb.test;
+
+import java.util.Properties;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class RemoteHttpTestServer extends RemoteTestServer {
+    public void init(Properties props) {
+        super.init(props);
+        props.put("java.naming.factory.initial", "org.openejb.client.RemoteInitialContextFactory");
+        props.put("java.naming.provider.url", "http://127.0.0.1:4204");
+    }
+
+}

Modified: trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/RemoteTestServer.java (2535 => 2536)

--- trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/RemoteTestServer.java	2006-03-10 08:45:43 UTC (rev 2535)
+++ trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/RemoteTestServer.java	2006-03-10 08:51:28 UTC (rev 2536)
@@ -29,13 +29,15 @@
     public void init(Properties props) {
         properties = props;
 
-        props.put("test.server.class", "org.openejb.test.RemoteTestServer");
+//        props.put("test.server.class","org.openejb.test.RemoteTestServer");
         props.put("java.naming.factory.initial", "org.openejb.client.RemoteInitialContextFactory");
         props.put("java.naming.provider.url", "127.0.0.1:4201");
         props.put("java.naming.security.principal", "testuser");
         props.put("java.naming.security.credentials", "testpassword");
+    }
 
-
+    public Properties getProperties() {
+        return properties;
     }
 
     public void destroy() {
@@ -45,16 +47,37 @@
         if (!connect()) {
             try {
                 System.out.println("[] START SERVER");
+
+                String openejbHome = System.getProperty("openejb.home");
+
+                File home = new File(openejbHome);
+                System.out.println("OPENEJB_HOME = "+home.getAbsolutePath());
+                String systemInfo = "Java " + System.getProperty("java.version") + "; " + System.getProperty("os.name") + "/" + System.getProperty("os.version");
+                System.out.println("SYSTEM_INFO  = "+systemInfo);
+
                 serverHasAlreadyBeenStarted = false;
                 String version = null;
 
-                URL resource = this.getClass().getResource("openejb-version.properties");
+                File openejbJar = null;
+                File lib = new File(home, "lib");
+                File[] files = lib.listFiles();
+                for (int i = 0; i < files.length && openejbJar == null; i++) {
+                    File file = files[i];
+                    if (file.getName().startsWith("openejb-core") && file.getName().endsWith("jar")){
+                        openejbJar = file;
+                    }
+                }
 
-                Properties versionInfo = new Properties();
-                versionInfo.load(resource.openConnection().getInputStream());
-                version = (String) versionInfo.get("version");
+                if (openejbJar == null){
+                    throw new IllegalStateException("Cannot find the openejb-core jar in "+lib.getAbsolutePath());
+                }
+                
+                //File openejbJar = new File(lib, "openejb-core-" + version + ".jar");
 
-                Process server = Runtime.getRuntime().exec("java -jar lib" + File.separator + "openejb-core-" + version + ".jar start -nowait");
+                //DMB: If you don't use an array, you get problems with jar paths containing spaces
+                // the command won't parse correctly
+                String[] args = {"java", "-jar", openejbJar.getAbsolutePath(), "start"};
+                Process server = Runtime.getRuntime().exec(args);
 
                 // Pipe the processes STDOUT to ours
                 InputStream out = server.getInputStream();
@@ -187,45 +210,28 @@
     }
 
     private static final class Pipe implements Runnable {
-
-
         private final InputStream is;
-
         private final OutputStream out;
 
         private Pipe(InputStream is, OutputStream out) {
-
             super();
-
             this.is = is;
-
             this.out = out;
-
         }
 
         public void run() {
-
             try {
-
                 int i = is.read();
-
                 out.write(i);
 
                 while (i != -1) {
-
                     i = is.read();
-
                     out.write(i);
-
                 }
 
             } catch (Exception e) {
-
                 e.printStackTrace();
-
             }
-
         }
-
     }
 }

Modified: trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/TestRunner.java (2535 => 2536)

--- trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/TestRunner.java	2006-03-10 08:45:43 UTC (rev 2535)
+++ trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/TestRunner.java	2006-03-10 08:51:28 UTC (rev 2536)
@@ -7,6 +7,8 @@
 import java.io.PrintStream;
 import java.net.URL;
 import java.util.Properties;
+import java.util.Iterator;
+import java.util.Map;
 
 /**
  * @author <a href="" PROTECTED]">David Blevins</a>
@@ -51,6 +53,10 @@
                 runLocalTests();
             } else if (args[0].equals("remote")) {
                 runRemoteTests();
+            } else if (args[0].equals("http")) {
+                runRemoteHttpTests();
+            } else if (args[0].equals("tomcat")) {
+                runTomcatRemoteHttpTests();
             } else {
                 printHelp();
 
@@ -61,6 +67,19 @@
                 TestRunner aTestRunner = new TestRunner();
                 TestResult r = aTestRunner
                         .start(new String[]{"org.openejb.test.ClientTestSuite"});
+
+                System.out.println("");
+                System.out.println("_________________________________________________");
+                System.out.println("CLIENT JNDI PROPERTIES");
+                Properties env = TestManager.getServer().getContextEnvironment();
+                for (Iterator iterator = env.entrySet().iterator(); iterator.hasNext();) {
+                    Map.Entry entry = (Map.Entry) iterator.next();
+                    String key = (String) entry.getKey();
+                    Object value = entry.getValue();
+                    System.out.println(key+" = "+value);
+                }
+                System.out.println("_________________________________________________");
+
                 if (!r.wasSuccessful())
                     System.exit(FAILURE_EXIT);
                 System.exit(SUCCESS_EXIT);
@@ -97,6 +116,30 @@
         System.out.println("_________________________________________________");
     }
 
+    private static void runRemoteHttpTests() {
+        System.setProperty("openejb.test.server",
+                "org.openejb.test.RemoteHttpTestServer");
+        System.setProperty("openejb.test.database",
+                "org.openejb.test.InstantDbTestDatabase");
+
+        System.out.println("_________________________________________________");
+        System.out
+                .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n");
+        System.out.println("Running EJB compliance tests on HTTP/Remote Server");
+        System.out.println("_________________________________________________");
+    }
+
+    private static void runTomcatRemoteHttpTests() {
+        System.setProperty("openejb.test.server", TomcatRemoteTestServer.class.getName());
+        System.setProperty("openejb.test.database", "org.openejb.test.InstantDbTestDatabase");
+
+        System.out.println("_________________________________________________");
+        System.out
+                .println("|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|\n");
+        System.out.println("Running EJB compliance tests on HTTP/Tomcat Server");
+        System.out.println("_________________________________________________");
+    }
+
     private static void printHelp() {
         String header = "OpenEJB Compliance Tests ";
         try {
@@ -133,7 +176,7 @@
         } catch (Exception e) {
             System.out.println("Cannot initialize the test environment: "
                     + e.getClass().getName() + " " + e.getMessage());
-            // e.printStackTrace();
+             e.printStackTrace();
             // System.exit(-1);
             throw e;
         }

Added: trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/TomcatRemoteTestServer.java (2535 => 2536)

--- trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/TomcatRemoteTestServer.java	2006-03-10 08:45:43 UTC (rev 2535)
+++ trunk/openejb3/openejb-itests/src/main/java/org/openejb/test/TomcatRemoteTestServer.java	2006-03-10 08:51:28 UTC (rev 2536)
@@ -0,0 +1,293 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  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.openejb.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class TomcatRemoteTestServer implements TestServer {
+    private Properties properties;
+    private String servletUrl;
+    private File tomcatHome;
+
+    private boolean serverHasAlreadyBeenStarted = true;
+
+    public void init(Properties props) {
+        properties = props;
+        servletUrl = System.getProperty("remote.serlvet.url", "http://127.0.0.1:8080/openejb/remote");
+//        props.put("test.server.class", TomcatRemoteTestServer.class.getName());
+        props.put("java.naming.factory.initial", "org.openejb.client.RemoteInitialContextFactory");
+        props.put("java.naming.provider.url", servletUrl);
+
+        String homeProperty = System.getProperty("tomcat.home");
+        if (homeProperty == null) {
+            throw new IllegalStateException("The system property tomcat.home must be defined.");
+        }
+
+        tomcatHome = new File(homeProperty);
+
+        if (!tomcatHome.exists()) {
+            throw new IllegalStateException("The tomcat.home directory does not exist: " + tomcatHome.getAbsolutePath());
+        }
+    }
+
+    public void start() {
+        if (connect()) {
+            return;
+        }
+
+        try {
+            System.out.println("[] START TOMCAT SERVER");
+            System.out.println("CATALINA_HOME = " + tomcatHome.getAbsolutePath());
+
+            String systemInfo = "Java " + System.getProperty("java.version") + "; " + System.getProperty("os.name") + "/" + System.getProperty("os.version");
+            System.out.println("SYSTEM_INFO   = " + systemInfo);
+
+            serverHasAlreadyBeenStarted = false;
+
+
+            execBootstrap("start");
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Cannot start the server: " + e.getClass().getName() + ": " + e.getMessage(), e);
+        }
+        connect(10);
+        // Wait a wee bit longer for good measure
+        try {
+            Thread.sleep(5000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void stop() {
+        if (!serverHasAlreadyBeenStarted) {
+            try {
+                System.out.println("[] STOP TOMCAT SERVER");
+                execBootstrap("stop");
+
+                disconnect(10);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    private void execBootstrap(String command) throws IOException {
+        String[] bootstrapCommand = getBootstrapCommand(tomcatHome, command);
+        Process server = Runtime.getRuntime().exec(bootstrapCommand);
+
+        FilePathBuilder tomcat = new FilePathBuilder(tomcatHome);
+        OutputStream catalinaOut = new FileOutputStream(tomcat.l("logs").f("catalina.out"));
+
+        // Pipe the processes STDOUT to ours
+        InputStream out = server.getInputStream();
+        Thread serverOut = new Thread(new Pipe(out, catalinaOut));
+
+        serverOut.setDaemon(true);
+        serverOut.start();
+
+        // Pipe the processes STDERR to ours
+        InputStream err = server.getErrorStream();
+        Thread serverErr = new Thread(new Pipe(err, catalinaOut));
+
+        serverErr.setDaemon(true);
+        serverErr.start();
+    }
+
+    public Properties getContextEnvironment() {
+        return (Properties) properties.clone();
+    }
+
+    private boolean disconnect(int tries) {
+        if (connect()) {
+            tries--;
+            if (tries < 1) {
+                return false;
+            } else {
+                try {
+                    Thread.sleep(5000);
+                } catch (InterruptedException e) {
+                }
+                disconnect(tries);
+            }
+        }
+
+        return true;
+    }
+
+    private boolean connect() {
+        return connect(1);
+    }
+
+    private boolean connect(int tries) {
+        //System.out.println("CONNECT "+ tries);
+        try {
+            URL url = "" URL(servletUrl);
+            url.openStream();
+        } catch (Exception e) {
+            tries--;
+            //System.out.println(e.getMessage());
+            if (tries < 1) {
+                return false;
+            } else {
+                try {
+                    Thread.sleep(5000);
+                } catch (Exception e2) {
+                    e.printStackTrace();
+                }
+                return connect(tries);
+            }
+        }
+
+        return true;
+    }
+
+    private String[] getBootstrapCommand(File tomcatHome, String command) {
+        FilePathBuilder tomcat = new FilePathBuilder(tomcatHome);
+        FilePathBuilder tomcatBin = tomcat.l("bin");
+
+        FilePathBuilder javaHome = new FilePathBuilder(System.getProperty("java.home"));
+        String path = tomcatHome.getAbsolutePath();
+
+        String s = File.pathSeparator;
+
+        if (path.indexOf("tomcat-5.5") != -1) {
+            return new String[]{javaHome.l("bin").s("java"),
+                    "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager",
+                    "-Djava.util.logging.config.file=" + tomcat.l("conf").l("logging.properties"),
+                    "-Djava.endorsed.dirs=" + tomcat.l("common").l("endorsed"),
+                    "-classpath", tomcatBin.l("bootstrap.jar") + s + tomcatBin.l("commons-logging-api.jar"),
+                    "-Dcatalina.base=" + tomcat,
+                    "-Dcatalina.home=" + tomcat,
+                    "-Djava.io.tmpdir=" + tomcat.l("temp"),
+                    "org.apache.catalina.startup.Bootstrap", command};
+        } else if (path.indexOf("tomcat-5.0") != -1) {
+            return new String[]{javaHome.l("bin").s("java"),
+                    "-Djava.endorsed.dirs=" + tomcat.l("common").l("endorsed"),
+                    "-classpath", tomcatBin.l("bootstrap.jar") + s + tomcatBin.l("commons-logging-api.jar") + s + javaHome.l("lib").s("tools.jar"),
+                    "-Dcatalina.base=" + tomcat,
+                    "-Dcatalina.home=" + tomcat,
+                    "-Djava.io.tmpdir=" + tomcat.l("temp"),
+                    "org.apache.catalina.startup.Bootstrap", command};
+        } else if (path.indexOf("tomcat-4.1") != -1) {
+            return new String[]{javaHome.l("bin").s("java"),
+                    "-Djava.endorsed.dirs=" + tomcat.l("common").l("endorsed"),
+                    "-classpath", tomcatBin.s("bootstrap.jar") + s + javaHome.l("lib").s("tools.jar"),
+                    "-Dcatalina.base=" + tomcat,
+                    "-Dcatalina.home=" + tomcat,
+                    "-Djava.io.tmpdir=" + tomcat.l("temp"),
+                    "org.apache.catalina.startup.Bootstrap", command};
+        } else {
+            throw new IllegalArgumentException("Unsupported Tomcat version: " + tomcatHome.getName());
+        }
+    }
+
+    public static class FilePathBuilder {
+        private final File file;
+
+        public FilePathBuilder(File file) {
+            this.file = file;
+        }
+
+        public FilePathBuilder(String filePath) {
+            this.file = new File(filePath);
+        }
+
+        public FilePathBuilder l(String name) {
+            return new FilePathBuilder(f(name));
+        }
+
+        public File f(String name) {
+            return new File(file, name);
+        }
+
+        public String s(String name) {
+            return new File(file, name).getAbsolutePath();
+        }
+
+        public String toString() {
+            return file.getAbsolutePath();
+        }
+    }
+
+    private static final class Pipe implements Runnable {
+        private final InputStream is;
+        private final OutputStream out;
+
+        private Pipe(InputStream is, OutputStream out) {
+            super();
+            this.is = is;
+            this.out = out;
+        }
+
+        public void run() {
+            try {
+                int i = is.read();
+                out.write(i);
+
+                while (i != -1) {
+                    i = is.read();
+                    out.write(i);
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+/**
+
+ 5.5.x startup
+
+
+
+ 5.0.x
+
+ -Djava.endorsed.dirs=/Users/dblevins/work/openejb1/target/jakarta-tomcat-5.0.30/common/endorsed
+ -classpath
+ /System/Library/Frameworks/JavaVM.framework/Versions/1.4/Home/lib/tools.jar:/Users/dblevins/work/openejb1/target/jakarta-tomcat-5.0.30/bin/bootstrap.jar:/Users/dblevins/work/openejb1/target/jakarta-tomcat-5.0.30/bin/commons-logging-api.jar
+ -Dcatalina.base=/Users/dblevins/work/openejb1/target/jakarta-tomcat-5.0.30
+ -Dcatalina.home=/Users/dblevins/work/openejb1/target/jakarta-tomcat-5.0.30
+ -Djava.io.tmpdir=/Users/dblevins/work/openejb1/target/jakarta-tomcat-5.0.30/temp
+ org.apache.catalina.startup.Bootstrap
+ start
+
+ 4.1.x
+
+ -Djava.endorsed.dirs=/Users/dblevins/work/openejb1/target/jakarta-tomcat-4.1.31/common/endorsed
+ -classpath
+ /System/Library/Frameworks/JavaVM.framework/Versions/1.4/Home/lib/tools.jar:/Users/dblevins/work/openejb1/target/jakarta-tomcat-4.1.31/bin/bootstrap.jar
+ -Dcatalina.base=/Users/dblevins/work/openejb1/target/jakarta-tomcat-4.1.31
+ -Dcatalina.home=/Users/dblevins/work/openejb1/target/jakarta-tomcat-4.1.31
+ -Djava.io.tmpdir=/Users/dblevins/work/openejb1/target/jakarta-tomcat-4.1.31/temp
+ org.apache.catalina.startup.Bootstrap
+ start
+
+ */
+
+
+}

Reply via email to