tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1296890 - in /openejb/trunk/openejb: container/openejb-loader/src/main/java/org/apache/openejb/loader/ itests/failover/ itests/failover/src/main/java/org/apache/openejb/itest/failover/ itests/failover/src/test/java/org/apache/openejb/itest...
Date Sun, 04 Mar 2012 22:20:25 GMT
Author: rmannibucau
Date: Sun Mar  4 22:20:25 2012
New Revision: 1296890

URL: http://svn.apache.org/viewvc?rev=1296890&view=rev
Log:
using resolver to get artifacts in failover tests

Modified:
    openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
    openejb/trunk/openejb/itests/failover/pom.xml
    openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
    openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DedicatedRootServerTest.java
    openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DiscoveryHostTest.java
    openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/ReconnectDelayTest.java
    openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/SpeedTest.java
    openejb/trunk/openejb/utils/openejb-provisionning/src/main/java/org/apache/openejb/resolver/Resolver.java

Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
(original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
Sun Mar  4 22:20:25 2012
@@ -92,6 +92,7 @@ public class Files {
     }
 
     public static File file(File file) {
+        exists(file);
         if (!file.isFile()) throw new RuntimeException("Not a file: " + file.getAbsolutePath());
         return file;
     }
@@ -106,6 +107,10 @@ public class Files {
         return file;
     }
 
+    public static File readableFile(File file) {
+        return readable(file(file));
+    }
+
     public static File mkdir(File file) {
         if (file.exists()) return file;
         if (!file.mkdirs()) throw new RuntimeException("Cannot mkdir: " + file.getAbsolutePath());

Modified: openejb/trunk/openejb/itests/failover/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/failover/pom.xml?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/itests/failover/pom.xml (original)
+++ openejb/trunk/openejb/itests/failover/pom.xml Sun Mar  4 22:20:25 2012
@@ -68,6 +68,12 @@
       <version>1.0.0-beta-3-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-provisionning</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>compile</scope>

Modified: openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
(original)
+++ openejb/trunk/openejb/itests/failover/src/main/java/org/apache/openejb/itest/failover/Repository.java
Sun Mar  4 22:20:25 2012
@@ -16,98 +16,47 @@
  */
 package org.apache.openejb.itest.failover;
 
-import org.apache.openejb.loader.Files;
+import org.apache.openejb.loader.ProvisioningUtil;
+import org.apache.openejb.resolver.Resolver;
 import org.apache.openejb.util.Join;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
 
 /**
  * @version $Rev$ $Date$
  */
-public class Repository {
-    private final File repository;
+public final class Repository {
+    private static final Resolver RESOLVER = new Resolver();
 
-    public Repository() {
-        this(defaultRepository());
-    }
-
-    public Repository(File repository) {
-        Files.exists(repository);
-        Files.dir(repository);
-
-        this.repository = repository;
-    }
-
-    /**
-     * Checks the system property 'repo'
-     * If not found, defaults to '${user.home}/.m2/repository'
-     * @return
-     */
-    private static File defaultRepository() {
-        final File home = new File(System.getProperty("user.home"));
-        final String property = System.getProperty("repo", Files.path(home, ".m2", "repository").getAbsolutePath());
-        return new File(property);
-    }
-
-    public Artifact getArtifact(String groupId, String artifactId, String type) {
-        return new Artifact(groupId, artifactId, type);
-    }
-
-    public class Artifact {
-        private final String groupId;
-        private final String artifactId;
-        private final String type;
-
-        public Artifact(String groupId, String artifactId, String type) {
-            this.groupId = groupId;
-            this.artifactId = artifactId;
-            this.type = type;
-        }
-
-        public File get(String version) {
-            List<String> path = new ArrayList<String>();
-
-            // GroupID path
-            Collections.addAll(path, groupId.split("\\."));
-            path.add(artifactId);
-            path.add(version);
-            path.add(artifactId + "-" + version + "." + type);
-
-            File file = new File(repository, Join.join(File.separator, path));
-            Files.exists(file);
-            Files.file(file);
-            Files.readable(file);
-
-            return file;
+    public static File getArtifact(final String groupId, final String artifactId, final String
type) {
+        final String oldCache = System.getProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
+        System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, System.getProperty("openejb.itest.failover.cache",
"target/cache"));
+        final String path;
+        try {
+            path = RESOLVER.resolve("mvn:" + groupId + ":" + artifactId + ":" + guessVersion(groupId,
artifactId) + ":" + type);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (oldCache == null) {
+                System.clearProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
+            } else {
+                System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, oldCache);
+            }
         }
 
-        public File get() {
-            return get(guessVersion());
-        }
+        return new File(path);
+    }
 
-        private String guessVersion() {
-            String[] keys = {artifactId + ".version", groupId + ".version", "version"};
-            for (String key : keys) {
-                final String value = System.getProperty(key);
-                if (value != null) {
-                    return value;
-                }
+    private static String guessVersion(final String groupId, final String artifactId) {
+        String[] keys = { artifactId + ".version", groupId + ".version", "version" };
+        for (String key : keys) {
+            final String value = System.getProperty(key);
+            if (value != null) {
+                return value;
             }
-
-            String message = String.format("Cannot find version for %s. Checked the following
system properties: %s", this, Join.join(", ", keys));
-            throw new IllegalStateException(message);
         }
 
-        @Override
-        public String toString() {
-            return "Artifact{" +
-                    "groupId='" + groupId + '\'' +
-                    ", artifactId='" + artifactId + '\'' +
-                    ", type='" + type + '\'' +
-                    '}';
-        }
+        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: openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DedicatedRootServerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DedicatedRootServerTest.java?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DedicatedRootServerTest.java
(original)
+++ openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DedicatedRootServerTest.java
Sun Mar  4 22:20:25 2012
@@ -59,9 +59,8 @@ public class DedicatedRootServerTest {
         // To run in an IDE, uncomment and update this line
         //System.setProperty("version", "4.0.0-beta-3-SNAPSHOT");
 
-        final Repository repository = new Repository();
-        final File zip = repository.getArtifact("org.apache.openejb", "openejb-standalone",
"zip").get();
-        final File app = repository.getArtifact("org.apache.openejb.itests", "failover-ejb",
"jar").get();
+        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();
 

Modified: openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DiscoveryHostTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DiscoveryHostTest.java?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DiscoveryHostTest.java
(original)
+++ openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/DiscoveryHostTest.java
Sun Mar  4 22:20:25 2012
@@ -24,26 +24,15 @@ import org.apache.openejb.loader.Zips;
 import org.apache.openejb.server.control.StandaloneServer;
 import org.apache.openejb.util.Join;
 import org.apache.openejb.util.NetworkUtil;
-import org.apache.xbean.finder.ResourceFinder;
 import org.junit.Assert;
 import org.junit.Test;
-import org.junit.Ignore;
 
 import javax.ejb.EJBException;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.NetworkInterface;
-import java.net.ServerSocket;
-import java.net.SocketAddress;
-import java.net.URL;
-import java.nio.channels.ServerSocketChannel;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
@@ -56,9 +45,8 @@ public class DiscoveryHostTest {
         // To run in an IDE, uncomment and update this line
         //System.setProperty("version", "4.0.0-beta-3-SNAPSHOT");
 
-        final Repository repository = new Repository();
-        final File zip = repository.getArtifact("org.apache.openejb", "openejb-standalone",
"zip").get();
-        final File app = repository.getArtifact("org.apache.openejb.itests", "failover-ejb",
"jar").get();
+        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();
 

Modified: openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/ReconnectDelayTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/ReconnectDelayTest.java?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/ReconnectDelayTest.java
(original)
+++ openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/ReconnectDelayTest.java
Sun Mar  4 22:20:25 2012
@@ -56,9 +56,8 @@ public class ReconnectDelayTest {
 
         Duration reconnectDelay = new Duration("1 second");
 
-        final Repository repository = new Repository();
-        final File zip = repository.getArtifact("org.apache.openejb", "openejb-standalone",
"zip").get();
-        final File app = repository.getArtifact("org.apache.openejb.itests", "failover-ejb",
"jar").get();
+        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();
 

Modified: openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/SpeedTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/SpeedTest.java?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/SpeedTest.java
(original)
+++ openejb/trunk/openejb/itests/failover/src/test/java/org/apache/openejb/itest/failover/SpeedTest.java
Sun Mar  4 22:20:25 2012
@@ -22,8 +22,6 @@ 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.apache.openejb.util.Join;
-import org.apache.openejb.util.NetworkUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -31,7 +29,6 @@ import javax.ejb.EJBException;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -46,9 +43,8 @@ public class SpeedTest extends FailoverT
         // To run in an IDE, uncomment and update this line
         //System.setProperty("version", "4.0.0-beta-3-SNAPSHOT");
 
-        final Repository repository = new Repository();
-        final File zip = repository.getArtifact("org.apache.openejb", "openejb-standalone",
"zip").get();
-        final File app = repository.getArtifact("org.apache.openejb.itests", "failover-ejb",
"jar").get();
+        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();
 

Modified: openejb/trunk/openejb/utils/openejb-provisionning/src/main/java/org/apache/openejb/resolver/Resolver.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/utils/openejb-provisionning/src/main/java/org/apache/openejb/resolver/Resolver.java?rev=1296890&r1=1296889&r2=1296890&view=diff
==============================================================================
--- openejb/trunk/openejb/utils/openejb-provisionning/src/main/java/org/apache/openejb/resolver/Resolver.java
(original)
+++ openejb/trunk/openejb/utils/openejb-provisionning/src/main/java/org/apache/openejb/resolver/Resolver.java
Sun Mar  4 22:20:25 2012
@@ -36,7 +36,7 @@ public class Resolver implements Locatio
             final String info = rawLocation.substring(MVN_PREFIX.length());
             final Parser parser = new Parser(info);
             final File file = cacheFile(parser.getArtifactPath());
-            if (!file.exists()) {
+            if (!file.exists() || !file.canRead()) {
                 try {
                     final URL url = new URL(MVN_PREFIX.substring(MVN_PREFIX.length() - 1),
"localhost", -1, info, new Handler());
                     final File parentFile = file.getParentFile();



Mime
View raw message