db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcai...@apache.org
Subject svn commit: r1041682 - in /db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck: RunTCK.java Utilities.java
Date Fri, 03 Dec 2010 04:03:44 GMT
Author: mcaisse
Date: Fri Dec  3 04:03:44 2010
New Revision: 1041682

URL: http://svn.apache.org/viewvc?rev=1041682&view=rev
Log:
JDO-647 - Progress.... interim check-in

Modified:
    db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
    db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/Utilities.java

Modified: db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java?rev=1041682&r1=1041681&r2=1041682&view=diff
==============================================================================
--- db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java (original)
+++ db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/RunTCK.java Fri Dec  3 04:03:44
2010
@@ -14,10 +14,12 @@ import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.commons.io.FileUtils;
+import org.apache.jdo.exectck.Utilities.InvocationResult;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -367,7 +369,8 @@ public class RunTCK extends AbstractMojo
         Properties props = null;
         boolean alreadyran = false;
         String runonce = "false";
-        StringBuffer propsString = new StringBuffer(" ");
+//        StringBuffer propsString = new StringBuffer(" ");
+        List<String> propsString = new ArrayList<String>();
 
         if (cfgs != null) {
             System.out.println("Configurations specified in cfgs are " + cfgs.toString());
@@ -390,16 +393,15 @@ public class RunTCK extends AbstractMojo
                 + "\n  identity types: " + identitytypes.toString());
 
         // Properties required for test execution
-        propsString.append(" -DResultPrinterClass=" + resultPrinterClass);
-        propsString.append(" -Dverbose=" + verbose);
-        propsString.append(" -Djdo.tck.cleanupaftertest=" + cleanupaftertest);
-        propsString.append(" -DPMFProperties=" + pmfProperties);
-        propsString.append(" -DPMFProperties=" + confDirectory + File.separator
-                + pmfProperties + " ");
-        propsString.append(" -DPMF2Properties=" + buildDirectory + File.separator
+        propsString.add("-DResultPrinterClass=" + resultPrinterClass);
+        propsString.add("-Dverbose=" + verbose);
+        propsString.add("-Djdo.tck.cleanupaftertest=" + cleanupaftertest);
+        propsString.add("-DPMFProperties=" + buildDirectory + File.separator
+                + "classes" + File.separator + pmfProperties);
+        propsString.add("-DPMF2Properties=" + buildDirectory + File.separator
                 + "classes" + File.separator + pmfProperties);
         String excludeFile = confDirectory + File.separator + exclude;
-        propsString.append(" -Djdo.tck.exclude=" +
+        propsString.add("-Djdo.tck.exclude=" +
                 PropertyUtils.getProperties(excludeFile).getProperty("jdo.tck.exclude"));
 
         // Create configuration log directory
@@ -412,7 +414,7 @@ public class RunTCK extends AbstractMojo
             throw new MojoExecutionException("Failed to create directory "
                     + cfgDirName);
         }
-        propsString.append(" -Djdo.tck.log.directory=" + thisLogDir);
+        propsString.add("-Djdo.tck.log.directory=" + thisLogDir);
 
         // Get ClassLoader URLs to build classpath below
         URL[] cpURLs = ((URLClassLoader) Thread.currentThread().getContextClassLoader()).getURLs();
@@ -423,7 +425,7 @@ public class RunTCK extends AbstractMojo
             alreadyran = false;
 
             for (String idtype : idtypes) {
-                propsString.append(" -Djdo.tck.identitytype=" + idtype);
+                propsString.add("-Djdo.tck.identitytype=" + idtype);
                 String enhancedDirName = buildDirectory + File.separator + "enhanced"
                         + File.separator + impl + File.separator + idtype + File.separator;
                 File enhancedDir = new File(enhancedDirName);
@@ -454,15 +456,15 @@ public class RunTCK extends AbstractMojo
                     // Parse conf file and set properties String
                     props = PropertyUtils.getProperties(confDirectory
                             + File.separator + cfg);
-                    propsString.append(" -Djdo.tck.testdata=" +
+                    propsString.add("-Djdo.tck.testdata=" +
                             props.getProperty("jdo.tck.testdata"));
-                    propsString.append(" -Djdo.tck.standarddata=" +
+                    propsString.add("-Djdo.tck.standarddata=" +
                             props.getProperty("jdo.tck.standarddata"));
-//                    propsString.append(" -Djdo.tck.description=\"" +
+//                    propsString.append("-Djdo.tck.description=\"" +
 //                            props.getProperty("jdo.tck.description") + "\"");
-                    propsString.append(" -Djdo.tck.requiredOptions=" +
+                    propsString.add("-Djdo.tck.requiredOptions=" +
                             props.getProperty("jdo.tck.requiredOptions"));
-                    propsString.append(" -Djdo.tck.signaturefile=" +
+                    propsString.add("-Djdo.tck.signaturefile=" +
                             signaturefile);
                     String mapping = props.getProperty("jdo.tck.mapping");
                     if (mapping == null) {
@@ -474,9 +476,11 @@ public class RunTCK extends AbstractMojo
                         throw new MojoExecutionException(
                                 "Could not find classes value in conf file: " + cfg);
                     }
+                    List<String> classesList = Arrays.asList(classes.split(" "));
+
 
-                    propsString.append(" -Djdo.tck.schemaname=" + idtype + mapping);
-                    propsString.append(" -Djdo.tck.cfg=" + cfg);
+                    propsString.add("-Djdo.tck.schemaname=" + idtype + mapping);
+                    propsString.add("-Djdo.tck.cfg=" + cfg);
 
                     runonce = props.getProperty("runonce");
                     runonce = (runonce == null) ? "false" : runonce;
@@ -499,17 +503,31 @@ public class RunTCK extends AbstractMojo
                     }
 
                     // build command line string
-                    StringBuffer cmdBuf = new StringBuffer();
-                    cmdBuf.append("java " + " ");
-                    cmdBuf.append("-cp " + cpString + " ");
-                    cmdBuf.append(propsString + " ");
-                    cmdBuf.append(dbproperties + " ");
-                    cmdBuf.append(jvmproperties + " ");
+//                    StringBuffer cmdBuf = new StringBuffer();
+                    List<String> command = new ArrayList<String>();
+                    command.add("java");
+                    command.add("-cp");
+                    command.add(cpString);
+                    command.addAll(propsString);
+                    command.add(dbproperties);
+                    // TODO!!! split jvmproperties into a List!!
+                    command.add(jvmproperties);
                     if (debugTCK) {
-                        cmdBuf.append(debugDirectives + " ");
+                        command.add(debugDirectives);
                     }
-                    cmdBuf.append(testRunnerClass + " ");
-                    cmdBuf.append(classes);
+                    command.add(testRunnerClass);
+                    command.addAll(classesList);
+
+//                    cmdBuf.append("java ");
+//                    cmdBuf.append("-cp " + cpString + " ");
+//                    cmdBuf.append(propsString + " ");
+//                    cmdBuf.append(dbproperties + " ");
+//                    cmdBuf.append(jvmproperties + " ");
+//                    if (debugTCK) {
+//                        cmdBuf.append(debugDirectives + " ");
+//                    }
+//                    cmdBuf.append(testRunnerClass + " ");
+//                    cmdBuf.append(classes);
 
                     // invoke class runner
                     System.out.println("Starting configuration=" + cfg +
@@ -522,21 +540,15 @@ public class RunTCK extends AbstractMojo
                     if (runonce.equals("true") && alreadyran) {
                         continue;
                     }
-                    System.out.println("Command line is: \n" + cmdBuf.toString());
-                    try {
-                        Process proc = Runtime.getRuntime().exec(cmdBuf.toString());
-//                        System.out.println("Err: "
-//                                + Utilities.convertStreamToString(proc.getErrorStream()));
-//                        System.out.println("Out: "
-//                                + Utilities.convertStreamToString(proc.getInputStream()));
-                        try {
-                            proc.waitFor();
-                        } catch (InterruptedException ex) {
-                            Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null,
ex);
-                        }
-                    } catch (IOException ex) {
-                        Logger.getLogger(RunTCK.class.getName()).log(Level.SEVERE, null,
ex);
+                    System.out.println("Command line is: \n" + command.toString());
+                    InvocationResult result = (new Utilities()).invokeTest(command);
+
+                    if (runtckVerbose) {
+                        System.out.println("Test exit value is" + result.getExitValue());
+                        System.out.println("Test result output:\n" + result.getOutputString());
+                        System.out.println("Test result error:\n" + result.getErrorString());
                     }
+
                     if (runonce.equals("true")) {
                         alreadyran = true;
                     }

Modified: db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/Utilities.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/Utilities.java?rev=1041682&r1=1041681&r2=1041682&view=diff
==============================================================================
--- db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/Utilities.java (original)
+++ db/jdo/trunk/exectck/src/main/java/org/apache/jdo/exectck/Utilities.java Fri Dec  3 04:03:44
2010
@@ -10,9 +10,13 @@ import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.CharBuffer;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+import javax.jdo.JDOException;
 
 public class Utilities {
 
@@ -92,31 +96,118 @@ public class Utilities {
 
     }
 
-    public static String convertStreamToString(InputStream is)
-            throws IOException {
-        /*
-         * To convert the InputStream to String we use the
-         * Reader.read(char[] buffer) method. We iterate until the
-         * Reader return -1 which means there's no more data to
-         * read. We use the StringWriter class to produce the string.
-         */
-        if (is != null) {
-            Writer writer = new StringWriter();
-
-            char[] buffer = new char[1024];
-            try {
-                Reader reader = new BufferedReader(
-                        new InputStreamReader(is, "UTF-8"));
-                int n;
-                while ((n = reader.read(buffer)) != -1) {
-                    writer.write(buffer, 0, n);
-                }
-            } finally {
-                is.close();
+//    public static String convertStreamToString(InputStream is)
+//            throws IOException {
+//        /*
+//         * To convert the InputStream to String we use the
+//         * Reader.read(char[] buffer) method. We iterate until the
+//         * Reader return -1 which means there's no more data to
+//         * read. We use the StringWriter class to produce the string.
+//         */
+//        if (is != null) {
+//            Writer writer = new StringWriter();
+//
+//            char[] buffer = new char[1024];
+//            try {
+//                Reader reader = new BufferedReader(
+//                        new InputStreamReader(is, "UTF-8"));
+//                int n;
+//                while ((n = reader.read(buffer)) != -1) {
+//                    writer.write(buffer, 0, n);
+//                }
+//            } finally {
+//                is.close();
+//            }
+//            return writer.toString();
+//        } else {
+//            return "";
+//        }
+//    }
+    InvocationResult invokeTest(List command) {
+        InvocationResult result = new InvocationResult();
+        try {
+            ProcessBuilder builder = new ProcessBuilder(command);
+            Map<String, String> env = builder.environment();
+            Process proc = builder.start();
+            InputStream stdout = proc.getInputStream();
+            InputStream stderr = proc.getErrorStream();
+            CharBuffer outBuffer = CharBuffer.allocate(1000000);
+            CharBuffer errBuffer = CharBuffer.allocate(1000000);
+            Thread outputThread = createReaderThread(stdout, outBuffer);
+            Thread errorThread = createReaderThread(stderr, errBuffer);
+            int exitValue = proc.waitFor();
+            result.setExitValue(exitValue);
+            errorThread.join(10000); // wait ten seconds to get stderr after process terminates
+            outputThread.join(10000); // wait ten seconds to get stdout after process terminates
+            result.setErrorString(errBuffer.toString());
+            result.setOutputString(outBuffer.toString());
+            // wait until the Enhancer command finishes
+        } catch (InterruptedException ex) {
+            throw new RuntimeException("InterruptedException", ex);
+        } catch (IOException ex) {
+            throw new RuntimeException("IOException", ex);
+        } catch (JDOException jdoex) {
+            jdoex.printStackTrace();
+            Throwable[] throwables = jdoex.getNestedExceptions();
+            System.out.println("Exception throwables of size: " + throwables.length);
+            for (Throwable throwable: throwables) {
+                throwable.printStackTrace();
             }
-            return writer.toString();
-        } else {
-            return "";
         }
+        return result;
+    }
+
+    private Thread createReaderThread(final InputStream input, final CharBuffer output) {
+        final Reader reader = new InputStreamReader(input);
+        Thread thread = new Thread(
+                new Runnable() {
+                    public void run() {
+                        int count = 0;
+                        int outputBytesRead = 0;
+                        try {
+                            while (-1 != (outputBytesRead = reader.read(output))) {
+                                count += outputBytesRead;
+                            }
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        } finally {
+                            output.flip();
+                        }
+                    }
+                });
+        thread.start();
+        return thread;
+    }
+
+
+    class InvocationResult {
+        private int exitValue;
+        private String errorString;
+        private String outputString;
+
+        int getExitValue() {
+            return exitValue;
+        }
+
+        private void setExitValue(int exitValue) {
+            this.exitValue = exitValue;
+        }
+
+        private void setErrorString(String errorString) {
+            this.errorString = errorString;
+        }
+
+        String getErrorString() {
+            return errorString;
+        }
+
+        private void setOutputString(String outputString) {
+            this.outputString = outputString;
+        }
+
+        String getOutputString() {
+            return outputString;
+        }
+
     }
 }



Mime
View raw message