incubator-s4-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject [34/50] [abbrv] git commit: resolve test classes directory at runtime
Date Tue, 03 Jan 2012 14:03:28 GMT
resolve test classes directory at runtime

- because IDEs and gradle use different compilation outputs


Project: http://git-wip-us.apache.org/repos/asf/incubator-s4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s4/commit/4c7060a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s4/tree/4c7060a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s4/diff/4c7060a1

Branch: refs/heads/piper
Commit: 4c7060a141ee31e67e1821f75610f1b78cac6550
Parents: c20324f
Author: Matthieu Morel <mmorel@apache.org>
Authored: Thu Oct 27 15:22:56 2011 +0200
Committer: Matthieu Morel <mmorel@apache.org>
Committed: Thu Oct 27 15:33:20 2011 +0200

----------------------------------------------------------------------
 .../test/s4/core/apploading/AppLoadingTest.java    |    7 +-
 .../src/test/java/test/s4/fixtures/TestUtils.java  |   55 +++++++++++----
 2 files changed, 45 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/4c7060a1/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
b/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
index e88aedf..e6be074 100644
--- a/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
+++ b/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
@@ -34,7 +34,7 @@ import com.google.common.io.Files;
  */
 public class AppLoadingTest {
 
-    public static long ZOOKEEPER_PORT = 21810;
+    public static final long ZOOKEEPER_PORT = 21810;
     private static Factory zookeeperServerConnectionFactory = null;
     private Process forkedApp;
 
@@ -59,7 +59,7 @@ public class AppLoadingTest {
 
     @Ignore("fix paths")
     @Test
-    public void testA() throws Exception, InterruptedException {
+    public void testA() throws Exception {
 
         // add all classes from counter app
         File rootAppDir = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath()
@@ -131,7 +131,8 @@ public class AppLoadingTest {
 
         final ZooKeeper zk = TestUtils.createZkClient();
 
-        File rootAppDir = new File(System.getProperty("user.dir") + "/build/classes/test/");
+        File rootAppDir = TestUtils.findDirForCompiledTestClasses();
+
         File appFilesDir = new File(rootAppDir, "test/s4/core/apploading");
         // 1. create app jar and place it in tmp/s4-apps
         generateS4RFromDirectoryContents(rootAppDir, appFilesDir, "appLoadingTest", SimpleApp.class.getName());

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/4c7060a1/subprojects/s4-core/src/test/java/test/s4/fixtures/TestUtils.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/test/java/test/s4/fixtures/TestUtils.java b/subprojects/s4-core/src/test/java/test/s4/fixtures/TestUtils.java
index f01b587..e894fb4 100644
--- a/subprojects/s4-core/src/test/java/test/s4/fixtures/TestUtils.java
+++ b/subprojects/s4-core/src/test/java/test/s4/fixtures/TestUtils.java
@@ -33,10 +33,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Contains static methods that can be used in tests for things such as: - files
- * utilities: strings <-> files conversion, directory recursive delete etc... -
- * starting local instances for zookeeper and bookkeeper - distributed latches
- * through zookeeper - etc...
+ * Contains static methods that can be used in tests for things such as: - files utilities:
strings <-> files
+ * conversion, directory recursive delete etc... - starting local instances for zookeeper
and bookkeeper - distributed
+ * latches through zookeeper - etc...
  * 
  */
 public class TestUtils {
@@ -66,16 +65,16 @@ public class TestUtils {
         cmdList.add("java");
         cmdList.add("-cp");
         cmdList.add(System.getProperty("java.class.path"));
-//      cmdList.add("-Xdebug");
-//      cmdList.add("-Xnoagent");
-//     
-//      cmdList.add("-Xrunjdwp:transport=dt_socket,address=8788,server=y,suspend=n");
+        // cmdList.add("-Xdebug");
+        // cmdList.add("-Xnoagent");
+        //
+        // cmdList.add("-Xrunjdwp:transport=dt_socket,address=8788,server=y,suspend=n");
 
         cmdList.add(mainClass);
         for (String arg : args) {
             cmdList.add(arg);
         }
-        
+
         System.out.println(Arrays.toString(cmdList.toArray(new String[] {})).replace(",",
""));
         ProcessBuilder pb = new ProcessBuilder(cmdList);
 
@@ -236,8 +235,8 @@ public class TestUtils {
             long length = file.length();
 
             /*
-             * Arrays can only be created using int types, so ensure that the
-             * file size is not too big before we downcast to create the array.
+             * Arrays can only be created using int types, so ensure that the file size is
not too big before we
+             * downcast to create the array.
              */
             if (length > Integer.MAX_VALUE) {
                 throw new IOException("Error file is too large: " + file.getName() + " "
+ length + " bytes");
@@ -282,9 +281,8 @@ public class TestUtils {
         watchAndSignalCreation(path, latch, zk, false);
     }
 
-    
-    public static void watchAndSignalCreation(String path, final CountDownLatch latch, final
ZooKeeper zk, boolean deleteIfExists)
-            throws KeeperException, InterruptedException {
+    public static void watchAndSignalCreation(String path, final CountDownLatch latch, final
ZooKeeper zk,
+            boolean deleteIfExists) throws KeeperException, InterruptedException {
 
         if (zk.exists(path, false) != null) {
             if (deleteIfExists) {
@@ -404,6 +402,35 @@ public class TestUtils {
         }
     }
 
+    /**
+     * gradle and eclipse have different directories for output files This is justified here
+     * http://gradle.1045684.n5.nabble.com/Changing-default-IDE-output-directories-td3335478.html#a3337433
+     * 
+     * A consequence is that for tests to reference compiled files, we need to resolve the
corresponding directory at
+     * runtime.
+     * 
+     * This is what this method does
+     * 
+     * @return directory containing the compiled test classes for this project and execution
environment.
+     */
+    public static File findDirForCompiledTestClasses() {
+        String userDir = System.getProperty("user.dir");
+        String classpath = System.getProperty("java.class.path");
+        System.out.println(userDir);
+        System.out.println(classpath);
+        if (classpath.contains(userDir + "/bin")) {
+            // eclipse classpath
+            return new File(userDir + "/bin");
+        } else if (classpath.contains(userDir + "/build/classes/test")) {
+            // gradle classpath
+            return new File(userDir + "/build/classes/test");
+        } else {
+            // TODO other IDEs
+            throw new RuntimeException("Cannot find path for compiled test classes");
+        }
+
+    }
+
     public static void injectIntoStringSocketAdapter(String string) throws IOException {
         Socket socket = null;
         PrintWriter writer = null;


Mime
View raw message