tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andygumbre...@apache.org
Subject svn commit: r1511656 - in /tomee/tomee/trunk/itests: ./ failover-ejb/ failover/ failover/src/main/java/org/apache/openejb/itest/failover/ failover/src/main/java/org/apache/openejb/server/control/ failover/src/test/java/org/apache/openejb/itest/failover...
Date Thu, 08 Aug 2013 09:48:21 GMT
Author: andygumbrecht
Date: Thu Aug  8 09:48:21 2013
New Revision: 1511656

URL: http://svn.apache.org/r1511656
Log:
Added legacy-client test.

Added:
    tomee/tomee/trunk/itests/legacy-client/   (with props)
    tomee/tomee/trunk/itests/legacy-client/pom.xml
    tomee/tomee/trunk/itests/legacy-client/src/
    tomee/tomee/trunk/itests/legacy-client/src/main/
    tomee/tomee/trunk/itests/legacy-client/src/test/
    tomee/tomee/trunk/itests/legacy-client/src/test/java/
    tomee/tomee/trunk/itests/legacy-client/src/test/java/org/
    tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/
    tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/
    tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/
    tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/
    tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/ClientThread.java
    tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/LegacyClientTest.java
Modified:
    tomee/tomee/trunk/itests/   (props changed)
    tomee/tomee/trunk/itests/failover/   (props changed)
    tomee/tomee/trunk/itests/failover-ejb/   (props changed)
    tomee/tomee/trunk/itests/failover/pom.xml
    tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
    tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
    tomee/tomee/trunk/itests/failover/src/test/java/org/apache/openejb/itest/failover/ClientThread.java
    tomee/tomee/trunk/itests/pom.xml

Propchange: tomee/tomee/trunk/itests/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Aug  8 09:48:21 2013
@@ -5,3 +5,5 @@
 .classpath
 .project
 target
+
+.idea

Propchange: tomee/tomee/trunk/itests/failover/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Aug  8 09:48:21 2013
@@ -1 +1,5 @@
 target
+
+.idea
+
+failover.iml

Propchange: tomee/tomee/trunk/itests/failover-ejb/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Aug  8 09:48:21 2013
@@ -1 +1,5 @@
 target
+
+*.iml
+
+.idea

Modified: tomee/tomee/trunk/itests/failover/pom.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/failover/pom.xml?rev=1511656&r1=1511655&r2=1511656&view=diff
==============================================================================
--- tomee/tomee/trunk/itests/failover/pom.xml (original)
+++ tomee/tomee/trunk/itests/failover/pom.xml Thu Aug  8 09:48:21 2013
@@ -71,6 +71,41 @@
       <groupId>org.apache.openejb</groupId>
       <artifactId>openejb-provisionning</artifactId>
       <version>${project.version}</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>wagon-provider-api</artifactId>
+          <groupId>org.apache.maven.wagon</groupId>
+        </exclusion>
+        <exclusion>
+          <artifactId>plexus-utils</artifactId>
+          <groupId>org.codehaus.plexus</groupId>
+        </exclusion>
+        <exclusion>
+          <artifactId>plexus-classworlds</artifactId>
+          <groupId>org.codehaus.plexus</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-provider-api</artifactId>
+      <version>2.4</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>plexus-utils</artifactId>
+          <groupId>org.codehaus.plexus</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>3.0.10</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-classworlds</artifactId>
+      <version>2.4.2</version>
     </dependency>
 
     <dependency>

Modified: tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java?rev=1511656&r1=1511655&r2=1511656&view=diff
==============================================================================
--- tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
(original)
+++ tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
Thu Aug  8 09:48:21 2013
@@ -47,16 +47,16 @@ public final class Repository {
         return new File(path);
     }
 
-    private static String guessVersion(final String groupId, final String artifactId) {
-        String[] keys = { artifactId + ".version", groupId + ".version", "version" };
-        for (String key : keys) {
+    public static String guessVersion(final String groupId, final String artifactId) {
+        final String[] keys = { artifactId + ".version", groupId + ".version", "version"
};
+        for (final String key : keys) {
             final String value = System.getProperty(key);
             if (value != null) {
                 return value;
             }
         }
 
-        String message = String.format("Cannot find version for %s:%s. Checked the following
system properties: %s", groupId, artifactId, Join.join(", ", keys));
+        final String message = String.format("Cannot find version for %s:%s. Checked the
following system properties: %s", groupId, artifactId, Join.join(", ", keys));
         throw new IllegalStateException(message);
     }
 }

Modified: tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java?rev=1511656&r1=1511655&r2=1511656&view=diff
==============================================================================
--- tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
(original)
+++ tomee/tomee/trunk/itests/failover/src/main/java/org/apache/openejb/server/control/StandaloneServer.java
Thu Aug  8 09:48:21 2013
@@ -33,12 +33,16 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
-import static org.apache.openejb.loader.Files.*;
+import static org.apache.openejb.loader.Files.dir;
+import static org.apache.openejb.loader.Files.exists;
+import static org.apache.openejb.loader.Files.file;
+import static org.apache.openejb.loader.Files.readable;
+import static org.apache.openejb.loader.Files.select;
 
 /**
  * @version $Rev$ $Date$
  */
-@SuppressWarnings({"UnusedDeclaration"})
+@SuppressWarnings({"UnusedDeclaration", "UseOfSystemOutOrSystemErr"})
 public class StandaloneServer {
 
     private final File home;
@@ -55,11 +59,11 @@ public class StandaloneServer {
     private Options options = new Options(properties);
     private Context context = new Context();
 
-    public StandaloneServer(File home) {
+    public StandaloneServer(final File home) {
         this(home, home);
     }
 
-    public StandaloneServer(File home, File base) {
+    public StandaloneServer(final File home, final File base) {
         this.home = home;
         this.base = base;
 
@@ -90,7 +94,7 @@ public class StandaloneServer {
         return context;
     }
 
-    public ServerService getServerService(String string) {
+    public ServerService getServerService(final String string) {
         return new ServerService(string);
     }
 
@@ -98,7 +102,7 @@ public class StandaloneServer {
 
         private final String name;
 
-        public ServerService(String name) {
+        public ServerService(final String name) {
             this.name = name;
         }
 
@@ -106,7 +110,7 @@ public class StandaloneServer {
             return options.get(name + ".port", -1);
         }
 
-        public void setPort(int i) {
+        public void setPort(final int i) {
             properties.put(name + ".port", i + "");
         }
 
@@ -118,11 +122,11 @@ public class StandaloneServer {
             return !isDisabled();
         }
 
-        public void setDisabled(boolean b) {
+        public void setDisabled(final boolean b) {
             properties.put(name + ".disabled", b + "");
         }
 
-        public void setEnabled(boolean b) {
+        public void setEnabled(final boolean b) {
             setDisabled(!b);
         }
 
@@ -130,7 +134,7 @@ public class StandaloneServer {
             return options.get(name + ".bind", "");
         }
 
-        public void setBind(String bind) {
+        public void setBind(final String bind) {
             properties.put(name + ".bind", bind);
         }
 
@@ -138,25 +142,25 @@ public class StandaloneServer {
             return options.get(name + ".threads", -1);
         }
 
-        public void setThreads(int threads) {
+        public void setThreads(final int threads) {
             properties.put(name + ".threads", threads + "");
         }
 
-        public ServerService set(String name, String value) {
+        public ServerService set(final String name, final String value) {
             properties.put(this.name + "." + name, value);
             return this;
         }
 
-        public Object get(String name) {
+        public Object get(final String name) {
             return properties.get(this.name + "." + name);
         }
 
-        public ServerService threads(int threads) {
+        public ServerService threads(final int threads) {
             setThreads(threads);
             return this;
         }
 
-        public ServerService port(int port) {
+        public ServerService port(final int port) {
             setPort(port);
             return this;
         }
@@ -171,12 +175,11 @@ public class StandaloneServer {
             return this;
         }
 
-        public ServerService bind(String host) {
+        public ServerService bind(final String host) {
             setBind(host);
             return this;
         }
 
-
     }
 
     public File getHome() {
@@ -191,7 +194,7 @@ public class StandaloneServer {
         return debug;
     }
 
-    public void setDebug(boolean debug) {
+    public void setDebug(final boolean debug) {
         this.debug = debug;
     }
 
@@ -199,7 +202,7 @@ public class StandaloneServer {
         return profile;
     }
 
-    public void setProfile(boolean profile) {
+    public void setProfile(final boolean profile) {
         this.profile = profile;
     }
 
@@ -207,7 +210,7 @@ public class StandaloneServer {
         return process;
     }
 
-    public void setProcess(Process process) {
+    public void setProcess(final Process process) {
         this.process = process;
     }
 
@@ -215,7 +218,7 @@ public class StandaloneServer {
         return verbose;
     }
 
-    public void setVerbose(boolean verbose) {
+    public void setVerbose(final boolean verbose) {
         this.verbose = verbose;
     }
 
@@ -223,7 +226,7 @@ public class StandaloneServer {
         return out;
     }
 
-    public void setOut(OutputStream out) {
+    public void setOut(final OutputStream out) {
         this.out = out;
     }
 
@@ -239,7 +242,7 @@ public class StandaloneServer {
         return properties;
     }
 
-    public Object setProperty(String key, String value) {
+    public Object setProperty(final String key, final String value) {
         return getProperties().setProperty(key, value);
     }
 
@@ -247,11 +250,13 @@ public class StandaloneServer {
         start(0, TimeUnit.MILLISECONDS);
     }
 
-    public void start(int timeout, TimeUnit minutes) {
-        if (process != null) throw new ServerRunningException(home, "Server already running");
+    public void start(final int timeout, final TimeUnit minutes) {
+        if (process != null) {
+            throw new ServerRunningException(home, "Server already running");
+        }
 
         try {
-            List<String> args = new ArrayList<String>();
+            final List<String> args = new ArrayList<String>();
             args.add(java.getAbsolutePath());
             args.addAll(jvmOpts);
             final Set<Map.Entry<Object, Object>> collection = properties.entrySet();
@@ -287,18 +292,22 @@ public class StandaloneServer {
     }
 
     private void edit() {
-        if (process != null) throw new ServerRunningException(home, "Cannot change settings
while server is running");
+        if (process != null) {
+            throw new ServerRunningException(home, "Cannot change settings while server is
running");
+        }
     }
 
     public static class DevNull extends OutputStream {
 
         @Override
-        public void write(int b) throws IOException {
+        public void write(final int b) throws IOException {
         }
     }
 
     public void kill() {
-        if (process == null) return;
+        if (process == null) {
+            return;
+        }
 
         process.destroy();
 
@@ -314,12 +323,14 @@ public class StandaloneServer {
         process = null;
     }
 
-    private int command(String... strings) {
+    private int command(final String... strings) {
         return command(Arrays.asList(strings));
     }
 
-    private int command(List<String> strings) {
-        if (process == null) throw new ServerNotRunningException(home);
+    private int command(final List<String> strings) {
+        if (process == null) {
+            throw new ServerNotRunningException(home);
+        }
 
         try {
             final List<String> args = new ArrayList<String>();
@@ -340,14 +351,14 @@ public class StandaloneServer {
         return -1;
     }
 
-    public void deploy(String path) {
+    public void deploy(final String path) {
         final int code = command("deploy", getServerUrl(), path);
         if (code != 0) {
             throw new DeployException(home, code, path);
         }
     }
 
-    public void undeploy(String path) {
+    public void undeploy(final String path) {
         final int code = command("undeploy", getServerUrl(), path);
         if (code != 0) {
             throw new UndeployException(home, code, path);
@@ -362,9 +373,10 @@ public class StandaloneServer {
         waitForExit();
     }
 
-
     public void killOnExit() {
-        if (kill.contains(this)) return;
+        if (kill.contains(this)) {
+            return;
+        }
         kill.add(this);
     }
 
@@ -375,7 +387,7 @@ public class StandaloneServer {
         Runtime.getRuntime().addShutdownHook(new Thread() {
             @Override
             public void run() {
-                for (StandaloneServer server : kill) {
+                for (final StandaloneServer server : kill) {
                     try {
                         if (server.process != null) {
                             server.process.destroy();
@@ -389,18 +401,19 @@ public class StandaloneServer {
     }
 
     public static class ServerException extends RuntimeException {
+
         private final File home;
 
-        public ServerException(File home) {
+        public ServerException(final File home) {
             this.home = home;
         }
 
-        public ServerException(File home, String message) {
+        public ServerException(final File home, final String message) {
             super(message);
             this.home = home;
         }
 
-        public ServerException(File home, String message, Throwable cause) {
+        public ServerException(final File home, final String message, final Throwable cause)
{
             super(message, cause);
             this.home = home;
         }
@@ -412,26 +425,29 @@ public class StandaloneServer {
     }
 
     public static class ServerNotRunningException extends ServerException {
-        public ServerNotRunningException(File home) {
+
+        public ServerNotRunningException(final File home) {
             super(home);
         }
     }
 
     public static class ServerRunningException extends ServerException {
-        public ServerRunningException(File home) {
+
+        public ServerRunningException(final File home) {
             super(home);
         }
 
-        public ServerRunningException(File home, String message) {
+        public ServerRunningException(final File home, final String message) {
             super(home, message);
         }
     }
 
     public static class ServerCommandException extends ServerException {
+
         private final int returnCode;
         private final String[] args;
 
-        public ServerCommandException(File home, int returnCode, String... args) {
+        public ServerCommandException(final File home, final int returnCode, final String...
args) {
             super(home);
             this.returnCode = returnCode;
             this.args = args;
@@ -439,26 +455,30 @@ public class StandaloneServer {
     }
 
     public static class DeployException extends ServerCommandException {
-        public DeployException(File home, int returnCode, String... args) {
+
+        public DeployException(final File home, final int returnCode, final String... args)
{
             super(home, returnCode, args);
         }
     }
 
     public static class UndeployException extends ServerCommandException {
-        public UndeployException(File home, int returnCode, String... args) {
+
+        public UndeployException(final File home, final int returnCode, final String... args)
{
             super(home, returnCode, args);
         }
     }
 
     public static class StopException extends ServerCommandException {
-        public StopException(File home, int returnCode, String... args) {
+
+        public StopException(final File home, final int returnCode, final String... args)
{
             super(home, returnCode, args);
         }
     }
 
     private static class SystemPropertiesCallback implements Join.NameCallback<Map.Entry<Object,
Object>> {
+
         @Override
-        public String getName(Map.Entry<Object, Object> e) {
+        public String getName(final Map.Entry<Object, Object> e) {
             return String.format("-D%s=%s", e.getKey().toString(), e.getValue().toString());
         }
     }
@@ -467,10 +487,14 @@ public class StandaloneServer {
         final ServerService ejbd = getServerService("ejbd");
 
         int port = ejbd.getPort();
-        if (port == 0) port = Integer.parseInt(System.getProperty("ejbd.port", "4201"));
+        if (port == 0) {
+            port = Integer.parseInt(System.getProperty("ejbd.port", "4201"));
+        }
 
         String host = ejbd.getBind();
-        if (host == null || host.length() == 0) host = "localhost";
+        if (host == null || host.length() == 0) {
+            host = "localhost";
+        }
 
         return String.format("--server-url=ejbd://%s:%s", host, port);
     }

Modified: tomee/tomee/trunk/itests/failover/src/test/java/org/apache/openejb/itest/failover/ClientThread.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/failover/src/test/java/org/apache/openejb/itest/failover/ClientThread.java?rev=1511656&r1=1511655&r2=1511656&view=diff
==============================================================================
--- tomee/tomee/trunk/itests/failover/src/test/java/org/apache/openejb/itest/failover/ClientThread.java
(original)
+++ tomee/tomee/trunk/itests/failover/src/test/java/org/apache/openejb/itest/failover/ClientThread.java
Thu Aug  8 09:48:21 2013
@@ -29,7 +29,7 @@ public class ClientThread implements Run
     private final AtomicLong delay = new AtomicLong(0);
     private final Callable callable;
 
-    public ClientThread(Callable callable) {
+    public ClientThread(final Callable callable) {
         this.callable = callable;
     }
 
@@ -46,12 +46,12 @@ public class ClientThread implements Run
         }
     }
 
-    public ClientThread delay(long delay){
+    public ClientThread delay(final long delay){
         setDelay(delay);
         return this;
     }
 
-    public void setDelay(long delay) {
+    public void setDelay(final long delay) {
         this.delay.set(delay);
     }
 

Propchange: tomee/tomee/trunk/itests/legacy-client/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug  8 09:48:21 2013
@@ -0,0 +1,2 @@
+*.iml
+target

Added: tomee/tomee/trunk/itests/legacy-client/pom.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/legacy-client/pom.xml?rev=1511656&view=auto
==============================================================================
--- tomee/tomee/trunk/itests/legacy-client/pom.xml (added)
+++ tomee/tomee/trunk/itests/legacy-client/pom.xml Thu Aug  8 09:48:21 2013
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <parent>
+    <artifactId>itests</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>4.6.0-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.openejb.itests</groupId>
+  <artifactId>legacy-client</artifactId>
+  <packaging>jar</packaging>
+  <name>OpenEJB :: iTests :: Legacy</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemPropertyVariables>
+            <version>${project.version}</version>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb.itests</groupId>
+      <artifactId>failover</artifactId>
+      <version>${project.version}</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>openejb-client</artifactId>
+          <groupId>org.apache.openejb</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-client</artifactId>
+      <version>4.5.2</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+
+</project>
+

Added: tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/ClientThread.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/ClientThread.java?rev=1511656&view=auto
==============================================================================
--- tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/ClientThread.java
(added)
+++ tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/ClientThread.java
Thu Aug  8 09:48:21 2013
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.itest.legacy;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class ClientThread implements Runnable {
+
+    private final AtomicBoolean run = new AtomicBoolean(false);
+    private final AtomicLong delay = new AtomicLong(0);
+    private final Callable callable;
+
+    public ClientThread(final Callable callable) {
+        this.callable = callable;
+    }
+
+    @Override
+    public void run() {
+        while (run.get()) {
+            pause();
+
+            try {
+                callable.call();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public ClientThread delay(final long delay){
+        setDelay(delay);
+        return this;
+    }
+
+    public void setDelay(final long delay) {
+        this.delay.set(delay);
+    }
+
+    private void pause() {
+        final long l = delay.get();
+        try {
+            if (l > 0) Thread.sleep(l);
+        } catch (InterruptedException e) {
+            Thread.interrupted();
+        }
+    }
+
+    public ClientThread start() {
+        run.set(true);
+        final Thread thread = new Thread(this);
+        thread.setDaemon(true);
+        thread.start();
+        return this;
+    }
+
+    public ClientThread stop() {
+        run.set(false);
+        return this;
+    }
+}

Added: tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/LegacyClientTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/LegacyClientTest.java?rev=1511656&view=auto
==============================================================================
--- tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/LegacyClientTest.java
(added)
+++ tomee/tomee/trunk/itests/legacy-client/src/test/java/org/apache/openejb/itest/legacy/LegacyClientTest.java
Thu Aug  8 09:48:21 2013
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.itest.legacy;
+
+import org.apache.openejb.client.Client;
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.client.event.ClusterMetaDataUpdated;
+import org.apache.openejb.client.event.Observes;
+import org.apache.openejb.itest.failover.Repository;
+import org.apache.openejb.itest.failover.ejb.Calculator;
+import org.apache.openejb.loader.Files;
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.loader.Zips;
+import org.apache.openejb.server.control.StandaloneServer;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.ejb.EJBException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.apache.openejb.util.NetworkUtil.getNextAvailablePort;
+
+public class LegacyClientTest {
+
+    static final Logger logger = Logger.getLogger("org.apache.openejb.client");
+
+    static {
+        final ConsoleHandler consoleHandler = new ConsoleHandler();
+        consoleHandler.setLevel(Level.FINER);
+        logger.addHandler(consoleHandler);
+        logger.setLevel(Level.FINER);
+        logger.setUseParentHandlers(false);
+    }
+
+    @Test
+    public void test() throws Exception {
+
+//        To run in an IDE, uncomment and update this line
+//        System.setProperty("version", OpenEjbVersion.get().getVersion());
+        System.setProperty("openejb.client.connection.strategy", "roundrobin");
+
+        logger.info("Retrieving standalone server: " + Repository.guessVersion("org.apache.openejb",
"openejb-standalone"));
+        final File zip = Repository.getArtifact("org.apache.openejb", "openejb-standalone",
"zip");
+        final File app = Repository.getArtifact("org.apache.openejb.itests", "failover-ejb",
"jar");
+
+        final File dir = Files.tmpdir();
+
+        final StandaloneServer root;
+        {
+            final String name = "root";
+            final File home = new File(dir, name);
+
+            Files.mkdir(home);
+            Zips.unzip(zip, home, true);
+
+            root = new StandaloneServer(home, home);
+            root.killOnExit();
+            root.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
+            root.ignoreOut();
+            root.setProperty("name", name);
+            root.setProperty("openejb.extract.configuration", "false");
+
+            final StandaloneServer.ServerService multipoint = root.getServerService("multipoint");
+            multipoint.setBind("localhost");
+            multipoint.setPort(getNextAvailablePort());
+            multipoint.setDisabled(false);
+            multipoint.set("discoveryName", name);
+
+            logger.info("Starting Root server");
+            root.start();
+        }
+
+        final Services services = new Services();
+        Client.addEventObserver(services);
+
+        final Map<String, StandaloneServer> servers = new HashMap<String, StandaloneServer>();
+        for (final String name : new String[]{"red", "green", "blue"}) {
+
+            final File home = new File(dir, name);
+            Files.mkdir(home);
+            Zips.unzip(zip, home, true);
+
+            final StandaloneServer server = new StandaloneServer(home, home);
+            server.killOnExit();
+            server.ignoreOut();
+            server.setProperty("name", name);
+            server.setProperty("openejb.extract.configuration", "false");
+            server.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
+
+            IO.copy(app, Files.path(home, "apps", "itest.jar"));
+            IO.copy(IO.read("<openejb><Deployments dir=\"apps/\"/></openejb>"),
Files.path(home, "conf", "openejb.xml"));
+
+            final StandaloneServer.ServerService ejbd = server.getServerService("ejbd");
+            ejbd.setBind("localhost");
+            ejbd.setDisabled(false);
+            ejbd.setPort(getNextAvailablePort());
+            ejbd.setThreads(5);
+
+            final URI uri = URI.create(String.format("ejbd://%s:%s/%s", ejbd.getBind(), ejbd.getPort(),
name));
+            ejbd.set("discovery", "ejb:" + uri);
+            services.add(uri);
+            server.getContext().set(URI.class, uri);
+
+            final StandaloneServer.ServerService multipoint = server.getServerService("multipoint");
+            multipoint.setPort(getNextAvailablePort());
+            multipoint.setDisabled(false);
+            multipoint.set("discoveryName", name);
+            multipoint.set("initialServers", "localhost:" + root.getServerService("multipoint").getPort());
+
+            servers.put(name, server);
+
+            logger.info(String.format("Starting %s server", name));
+
+            server.start(1, TimeUnit.MINUTES);
+        }
+
+
+        System.setProperty("openejb.client.requestretry", "true");
+        System.setProperty("openejb.client.connection.strategy", "random");
+
+        logger.info("Beginning Test");
+
+        final Properties environment = new Properties();
+        environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+        environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + servers.values().iterator().next().getServerService("ejbd").getPort()
+ "/provider");
+
+        final InitialContext context = new InitialContext(environment);
+        final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
+
+        for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet())
{
+            final String name = entry.getKey();
+            final StandaloneServer server = entry.getValue();
+            final URI serverURI = server.getContext().get(URI.class);
+
+            logger.info("Waiting for updated list");
+            services.assertServices(30, TimeUnit.SECONDS, new CalculatorCallable(bean), 500);
+
+            logger.info("Asserting balance");
+            assertBalance(bean, services.get().size());
+
+            logger.info("Shutting down " + name);
+            server.kill();
+            services.remove(serverURI);
+        }
+
+        logger.info("All Servers Shutdown");
+
+        try {
+            logger.info("Making one last request, expecting complete failover");
+
+            final String name = bean.name();
+            Assert.fail("Server should be destroyed: " + name);
+        } catch (EJBException e) {
+            logger.info(String.format("Pass.  Request resulted in %s: %s", e.getCause().getClass().getSimpleName(),
e.getMessage()));
+            // good
+        }
+
+
+        for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet())
{
+            final String name = entry.getKey();
+            final StandaloneServer server = entry.getValue();
+            final URI serverURI = server.getContext().get(URI.class);
+
+            logger.info(String.format("Starting %s server", name));
+
+            server.start(1, TimeUnit.MINUTES);
+            services.add(serverURI);
+
+            logger.info("Waiting for updated list");
+            services.assertServices(30, TimeUnit.SECONDS, new CalculatorCallable(bean), 500);
+
+            logger.info("Asserting balance");
+            assertBalance(bean, services.get().size());
+        }
+    }
+
+    private void assertBalance(final Calculator bean, final int size) {
+        final int expectedInvocations = 1000;
+        final double percent = 0.10;
+        final int totalInvocations = size * expectedInvocations;
+
+
+        // Verify the work reached all servers
+        final Set<Map.Entry<String, AtomicInteger>> entries = invoke(bean, totalInvocations).entrySet();
+
+        Assert.assertEquals(size, entries.size());
+
+        // And each server got a minimum of %10 percent of the traffic
+        for (final Map.Entry<String, AtomicInteger> entry : entries) {
+
+            final int actualInvocations = entry.getValue().get();
+
+            Assert.assertTrue(String.format("%s out of %s is too low", actualInvocations,
expectedInvocations), actualInvocations > expectedInvocations * percent);
+        }
+    }
+
+
+    private Map<String, AtomicInteger> invoke(final Calculator bean, final int max)
{
+        final Map<String, AtomicInteger> invocations = new HashMap<String, AtomicInteger>();
+        for (int i = 0; i < max; i++) {
+            final String name = bean.name();
+
+            if (!invocations.containsKey(name)) {
+                invocations.put(name, new AtomicInteger());
+            }
+
+            invocations.get(name).incrementAndGet();
+        }
+
+        for (final Map.Entry<String, AtomicInteger> entry : invocations.entrySet())
{
+            logger.info(String.format("Server %s invoked %s times", entry.getKey(), entry.getValue()));
+        }
+
+        return invocations;
+    }
+
+    public static class Services {
+        static final Logger logger = Logger.getLogger(Services.class.getName());
+
+        private final ReentrantLock lock = new ReentrantLock();
+        private final Condition condition = lock.newCondition();
+
+        private final Set<URI> expected = new HashSet<URI>();
+
+        public Services() {
+        }
+
+        public Set<URI> get() {
+            return expected;
+        }
+
+        public boolean add(final URI uri) {
+            return expected.add(uri);
+        }
+
+        public boolean remove(final URI o) {
+            return expected.remove(o);
+        }
+
+        public void observe(@Observes final ClusterMetaDataUpdated updated) {
+            final URI[] locations = updated.getClusterMetaData().getLocations();
+            final Set<URI> found = new HashSet<URI>(Arrays.asList(locations));
+
+            if (expected.equals(found)) {
+                lock.lock();
+                try {
+                    condition.signal();
+                } finally {
+                    lock.unlock();
+                }
+            }
+        }
+
+        public Set<URI> diff(final Set<URI> a, final Set<URI> b) {
+            final Set<URI> diffs = new HashSet<URI>();
+            for (final URI uri : b) {
+                if (!a.contains(uri)) diffs.add(uri);
+            }
+
+            return diffs;
+        }
+
+        public void assertServices(final long timeout, final TimeUnit unit, final Callable
callable) {
+            assertServices(timeout, unit, callable, 10);
+        }
+
+        public void assertServices(final long timeout, final TimeUnit unit, final Callable
callable, final int delay) {
+            final ClientThread client = new ClientThread(callable);
+            client.delay(delay);
+            client.start();
+            try {
+                Assert.assertTrue(String.format("services failed to come online: waited %s
%s", timeout, unit), await(timeout, unit));
+            } catch (InterruptedException e) {
+                Thread.interrupted();
+                Assert.fail("Interrupted");
+            } finally {
+                client.stop();
+            }
+        }
+
+        public boolean await(final long timeout, final TimeUnit unit) throws InterruptedException
{
+            lock.lock();
+            try {
+                return condition.await(timeout, unit);
+            } finally {
+                lock.unlock();
+            }
+        }
+    }
+
+    private static class CalculatorCallable implements Callable {
+        private final Calculator bean;
+
+        public CalculatorCallable(final Calculator bean) {
+            this.bean = bean;
+        }
+
+        @Override
+        public Object call() throws Exception {
+            return bean.name();
+        }
+    }
+}

Modified: tomee/tomee/trunk/itests/pom.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/itests/pom.xml?rev=1511656&r1=1511655&r2=1511656&view=diff
==============================================================================
--- tomee/tomee/trunk/itests/pom.xml (original)
+++ tomee/tomee/trunk/itests/pom.xml Thu Aug  8 09:48:21 2013
@@ -20,24 +20,29 @@
 <!-- $Rev$ $Date$ -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
   <parent>
     <artifactId>openejb</artifactId>
     <groupId>org.apache.openejb</groupId>
     <version>4.6.0-SNAPSHOT</version>
   </parent>
+
   <modelVersion>4.0.0</modelVersion>
   <artifactId>itests</artifactId>
   <packaging>pom</packaging>
   <name>OpenEJB :: iTests</name>
+
   <modules>
-    <module>openejb-itests-client</module>
+    <module>failover</module>
+    <module>failover-ejb</module>
+    <module>legacy-client</module>
+    <module>openejb-itests-app</module>
     <module>openejb-itests-beans</module>
-    <module>openejb-itests-servlets</module>
+    <module>openejb-itests-client</module>
     <module>openejb-itests-interceptor-beans</module>
-    <module>openejb-itests-app</module>
+    <module>openejb-itests-servlets</module>
     <module>openejb-itests-web</module>
-    <module>failover</module>
-    <module>failover-ejb</module>
   </modules>
+
 </project>
 



Mime
View raw message