db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r239997 - in /incubator/jdo/trunk/tck20: ./ test/conf/ test/java/org/apache/jdo/tck/util/
Date Thu, 25 Aug 2005 05:27:48 GMT
Author: mbo
Date: Wed Aug 24 22:27:42 2005
New Revision: 239997

URL: http://svn.apache.org/viewcvs?rev=239997&view=rev
Log:
Added a summary file listing the runtck results for all configurations.
Changes provided by Michael Watzek.

Added:
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ConsoleFileOutput.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ResultSummary.java
Modified:
    incubator/jdo/trunk/tck20/maven.xml
    incubator/jdo/trunk/tck20/test/conf/derby.properties
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchResultPrinter.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchTestRunner.java

Modified: incubator/jdo/trunk/tck20/maven.xml
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/maven.xml?rev=239997&r1=239996&r2=239997&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/maven.xml (original)
+++ incubator/jdo/trunk/tck20/maven.xml Wed Aug 24 22:27:42 2005
@@ -200,6 +200,7 @@
     <goal name="runtck.iut" prereqs="setProps">
         <mkdir dir="${jdo.tck.log.directory.database}"/>
         <attainGoal name="privateRuntck.iut"/>
+        <attainGoal name="result"/>
     </goal>
 
     <goal name="privateRuntck.iut"
@@ -236,6 +237,7 @@
     <goal name="runtck.jdori" prereqs="setProps">
         <mkdir dir="${jdo.tck.log.directory.database}"/>
         <attainGoal name="privateRuntck.jdori"/>
+        <attainGoal name="result"/>
     </goal>
 
     <goal name="privateRuntck.jdori"
@@ -361,6 +363,14 @@
             <arg line="${jdo.tck.classes}"/>
         </java>
         <echo>Finished run with database="${jdo.tck.database}" identitytype="${jdo.tck.identitytype}"
mapping="${jdo.tck.mapping}".</echo>
+    </goal>
+
+    <goal name="result">
+        <java fork="yes" dir="${jdo.tck.testdir}"
+               classname="org.apache.jdo.tck.util.ResultSummary">
+            <classpath refid="jdori.class.path"/>
+            <arg line="${jdo.tck.log.directory}/${timestamp}"/>
+        </java>
     </goal>
 
     <!-- ================== -->

Modified: incubator/jdo/trunk/tck20/test/conf/derby.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/conf/derby.properties?rev=239997&r1=239996&r2=239997&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/conf/derby.properties (original)
+++ incubator/jdo/trunk/tck20/test/conf/derby.properties Wed Aug 24 22:27:42 2005
@@ -18,7 +18,7 @@
 #If this property is set, the derby.stream.error.method and 
 #derby.stream.error.field properties are ignored.
 #Default: derby.log
-derby.stream.error.file=../../logs/database/derby.log
+derby.stream.error.file=../../logs/database/derby.txt
 
 #Specifies which errors are logged to the Derby error log 
 #(typically the derby.log file). In test environments, use the setting 

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchResultPrinter.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchResultPrinter.java?rev=239997&r1=239996&r2=239997&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchResultPrinter.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchResultPrinter.java Wed
Aug 24 22:27:42 2005
@@ -38,10 +38,21 @@
 public class BatchResultPrinter
     extends ResultPrinter
 {
-    /** */
+    private static final DecimalFormat THREE_DIGITS_FORMATTER = new DecimalFormat("000");
+
+    /** The stream to delegate the output. */
+    private ConsoleFileOutput consoleFileOutput;
+    
+    /** The time elapsed to run a test suite. */
     private long runtime;
     
     /** */
+    public BatchResultPrinter(ConsoleFileOutput consoleFileOutput) {
+        this(new PrintStream(consoleFileOutput));
+        this.consoleFileOutput = consoleFileOutput;
+    }
+        
+    /** */
     public BatchResultPrinter(PrintStream writer) {
         super(writer);
     }
@@ -74,6 +85,13 @@
         getWriter().flush();
     }
         
+    /**
+     * @see ResultPrinter#elapsedTimeAsString(long)
+     */
+    protected String elapsedTimeAsString(long runTime) {
+        return THREE_DIGITS_FORMATTER.format((double)runTime/1000);
+    }
+
     /** */
     protected void printHeader(long runTime) {
         this.runtime = runTime;
@@ -83,22 +101,57 @@
         
     /** */
     protected void printFooter(TestResult result) {
-        if (result.wasSuccessful()) {
-            getWriter().print("OK");
-            getWriter().println (" (" + result.runCount() + " test" + (result.runCount()
== 1 ? "": "s") + ")");
-                
+        String message = null;
+        if (this.consoleFileOutput != null) { 
+            message = getResultMessage(result, this.consoleFileOutput);
+            String directory = this.consoleFileOutput.getDirectory();
+            ResultSummary.appendTCKResultMessage(directory, message);
+            ResultSummary.save(directory, result);
         } else {
+            message = getResultMessage(result);
+        }
+        
+        if (!result.wasSuccessful()) {
             getWriter().println("FAILURES!!!");
             printErrorSummary(result);
-            getWriter().println("Tests run: "+result.runCount()+ 
-                                ",  Failures: "+result.failureCount()+
-                                ",  Errors: "+result.errorCount()+
-                                ", Time: "+elapsedTimeAsString(this.runtime)+" seconds.");
         }
+        
+        getWriter().println(message);
         getWriter().println("Excluded tests: " + System.getProperty("jdo.tck.exclude"));
     }
         
     // helper method
+    
+    /**
+     * Returns the result message for the given result instance and
+     * the given console file output instance.
+     * @param result the result instance
+     * @param consoleFileOutput the console file output instance
+     * @return the result message
+     */
+    private String getResultMessage(TestResult result, ConsoleFileOutput consoleFileOutput)
{
+        String message = this.consoleFileOutput.getFileName() + ':';
+        message += System.getProperty("line.separator") + "    ";
+        message += getResultMessage(result);
+        return message;
+    }
+        
+    /**
+     * Returns the result message for the given result instance.
+     * @param result the result instance
+     * @return the result message
+     */
+    private String getResultMessage(TestResult result) {
+        boolean success = result.wasSuccessful();
+        String message = success ? "OK " : "** ";
+        message += "Tests run: " + THREE_DIGITS_FORMATTER.format(result.runCount()) + 
+                   ", Time: "+elapsedTimeAsString(this.runtime)+" seconds.";
+        if (!success) {
+            message += " Failures: "+result.failureCount() + 
+                       ", Errors: "+result.errorCount();
+        }
+        return message;
+    }
         
     /** 
      * @return Name of the class of the given object without package prefix
@@ -150,7 +203,6 @@
     }
     
     private static class ErrorSummaryEntry implements Comparable {
-        private static DecimalFormat decimalFormat = new DecimalFormat("000");
         private int count = 0;
         private Throwable t;
         
@@ -179,7 +231,7 @@
         
         public String toString() {
             StringBuffer buffer = 
-                new StringBuffer(decimalFormat.format(count));
+                new StringBuffer(THREE_DIGITS_FORMATTER.format(count));
             buffer.append(" error" );
             if (this.count!=1) {
                 buffer.append("s: ");

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchTestRunner.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchTestRunner.java?rev=239997&r1=239996&r2=239997&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchTestRunner.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/BatchTestRunner.java Wed Aug
24 22:27:42 2005
@@ -17,7 +17,6 @@
 package org.apache.jdo.tck.util;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
@@ -130,13 +129,29 @@
                 try {
                     // get class instance
                     Class clazz = Class.forName(className);
-                    // constructor taking PrintStream arg
-                    Constructor ctor = clazz.getConstructor(
-                        new Class[] { PrintStream.class } );
-                    // create instance
-                    PrintStream stream = !Boolean.getBoolean("no.log.file") ?
-                        new PrintStream(new ConsoleFileOutput()) :
-                        System.out;
+                    
+                    Constructor ctor = null;
+                    OutputStream stream = null;
+
+                    // choose constructor taking ConsoleFileOutput arg
+                    if (!Boolean.getBoolean("no.log.file")) {
+                        try {
+                            ctor = clazz.getConstructor(
+                            new Class[] { ConsoleFileOutput.class } );
+                            stream = new ConsoleFileOutput();
+                        }
+                        catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                    }
+                    
+                    // choose constructor taking PrintStream arg
+                    if (ctor == null) {
+                        ctor = clazz.getConstructor(
+                                new Class[] { PrintStream.class } );
+                        stream = System.out;
+                    }
+                        
                     return (ResultPrinter)ctor.newInstance(
                         new Object[] { stream });
                 }
@@ -178,53 +193,6 @@
      */
     protected ResultPrinter getDefaultResultPrinter() {
         return new BatchResultPrinter(System.out);
-    }
-    
-    /**
-     * Creates an output stream that delegates to
-     * {@link System#out} and to a file output stream.
-     * The file name of the file output stream is determined
-     * by method {@link BatchTestRunner#getFileName()}.
-     */
-    private static class ConsoleFileOutput extends OutputStream {
-
-        private String fileName;
-        private PrintStream systemOut = System.out;
-        private FileOutputStream fileOut;
-        
-        private ConsoleFileOutput() {
-            try {
-                this.fileName = getFileName();
-                this.fileOut = new FileOutputStream(this.fileName);
-            } catch (IOException e) {
-                if (this.fileName!=null)
-                    System.err.println("Cannot create log file "+this.fileName+". "+e);
-            }
-        }
-        
-        /* 
-         * @see java.io.OutputStream#write(int)
-         */
-        public void write(int b) throws IOException {
-            this.systemOut.write(b);
-            this.fileOut.write(b);
-        }
-        
-        /**
-         * @see java.io.OutputStream#close()
-         */
-        public void close()  throws IOException {
-            this.fileOut.close();
-            this.systemOut.close();
-        }
-    
-        /**
-         * @see java.io.OutputStream#flush()
-         */
-        public void flush()  throws IOException {
-            this.systemOut.flush();
-            this.fileOut.flush();
-        }        
     }
     
     /**

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ConsoleFileOutput.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ConsoleFileOutput.java?rev=239997&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ConsoleFileOutput.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ConsoleFileOutput.java Wed
Aug 24 22:27:42 2005
@@ -0,0 +1,80 @@
+/*
+ * 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.apache.jdo.tck.util;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+/**
+ * Creates an output stream that delegates to
+ * {@link System#out} and to a file output stream.
+ * The file name of the file output stream is determined
+ * by method {@link BatchTestRunner#getFileName()}.
+ */
+class ConsoleFileOutput extends OutputStream {
+
+    private String fileName;
+    private final PrintStream systemOut = System.out;
+    private FileOutputStream fileOut;
+    
+    ConsoleFileOutput() {
+        this.fileName = BatchTestRunner.getFileName();
+        try {
+            this.fileOut = new FileOutputStream(this.fileName);
+        } catch (IOException e) {
+            System.err.println("Cannot create log file "+this.fileName+". "+e);
+        }
+    }
+    
+    /* 
+     * @see java.io.OutputStream#write(int)
+     */
+    public void write(int b) throws IOException {
+        this.systemOut.write(b);
+        this.fileOut.write(b);
+    }
+    
+    /**
+     * @see java.io.OutputStream#close()
+     */
+    public void close()  throws IOException {
+        this.fileOut.close();
+        this.systemOut.close();
+    }
+
+    /**
+     * @see java.io.OutputStream#flush()
+     */
+    public void flush()  throws IOException {
+        this.systemOut.flush();
+        this.fileOut.flush();
+    }  
+    
+    String getFileName() {
+        return new File(this.fileName).getName();
+    }
+    
+    String getDirectory() {
+        String result = new File(this.fileName).getParent();
+        if (!result.endsWith(File.separator))
+            result += File.separator;
+        return result;
+    }
+}

Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ResultSummary.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ResultSummary.java?rev=239997&view=auto
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ResultSummary.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/util/ResultSummary.java Wed Aug
24 22:27:42 2005
@@ -0,0 +1,194 @@
+/*
+ * 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.apache.jdo.tck.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintStream;
+import java.io.Serializable;
+
+import javax.jdo.JDOFatalException;
+
+import junit.framework.TestResult;
+
+/**
+ * A serializable class used to store test results in a file.
+ */
+public class ResultSummary implements Serializable {
+    private static final long serialVersionUID = 1L;
+    
+    /** The name of the file to store a serialized instance of this class. */
+    private static final String FILE_NAME_OF_RESULT_SUMMARY = "ResultSummary.ser";
+    
+    /** The name of the TCK result file. */
+    private static final String RESULT_FILE_NAME = "TCK-results.txt";
+    
+    /* The number of all configurations. */
+    private int nrOfTotalConfigurations = 0;
+    
+    /* The number of failed configurations. */
+    private int nrOfFailedConfigurations = 0;
+    
+    /**
+     * Deserializes an instance and prints that instance to
+     * {@link System#out} and the TCK result file.
+     * Finally deletes the file of the serialized instance. 
+     * @param args the first element contains the directory 
+     * where the test result is stored.
+     */
+    public static void main(String[] args) {
+        // print result summary
+        
+        String directory = args[0] + File.separator;
+        ResultSummary resultSummary = ResultSummary.load(directory);
+        String newLine = System.getProperty("line.separator");
+        String resultMessage = "Result: " + resultSummary; 
+        String message = "-------" + newLine + resultMessage;
+        appendTCKResultMessage(directory, message);
+        System.out.println(resultMessage);
+        System.out.println("See file '"+ directory + RESULT_FILE_NAME + 
+                "' for details.");
+        
+        // delete file
+        String fileName = args[0] + File.separator + FILE_NAME_OF_RESULT_SUMMARY;
+        File file = new File(fileName);
+        file.delete();
+    }
+    
+    /**
+     * Appends the given message to the TCK result file in the given directory. 
+     * @param directory the directory
+     * @param message the message
+     */
+    static void appendTCKResultMessage(String directory, String message) {
+        String fileName = directory + RESULT_FILE_NAME;
+        PrintStream resultStream = null;
+        try {
+            resultStream = new PrintStream(
+                    new FileOutputStream(fileName, true));
+            resultStream.println(message);
+        } catch (FileNotFoundException e) {
+            throw new JDOFatalException("Cannot create file "+fileName, e);
+        } finally {
+            if (resultStream != null)
+                resultStream.close();
+        }
+    }
+
+    /**
+     * Creates an instance for the given result object and
+     * serializes that instance to a file in the geven directory.
+     * @param directory the directory
+     * @param result the result object
+     */
+    static void save(String directory, TestResult result) {
+        ResultSummary resultSummary = load(directory);
+        if (resultSummary == null) {
+            resultSummary = new ResultSummary();
+        }
+        resultSummary.increment(result);
+        resultSummary.save(directory);
+    }
+    
+    /**
+     * Returns a deserialized instance stored in the given direcotry.
+     * @param directory the directory
+     * @return the deserialized instance
+     */
+    private static ResultSummary load(String directory) {
+        ResultSummary result;
+        String fileName = directory + FILE_NAME_OF_RESULT_SUMMARY;
+        ObjectInputStream ois = null;
+        try {
+            try {
+                ois = new ObjectInputStream(new FileInputStream(fileName));
+                result = (ResultSummary) ois.readObject();
+            } finally {
+                if (ois != null) {
+                    ois.close();
+                }
+            }
+        } catch (FileNotFoundException e) {
+            result = null;
+        } catch (IOException e) {
+            throw new JDOFatalException(
+                    "Cannot deserialize result summary in file "
+                    +fileName, e);
+        } catch (ClassNotFoundException e) {
+            throw new JDOFatalException(
+                    "Cannot deserialize result summary in file "
+                    +fileName, e);
+        }
+        return result;
+    }
+    
+    /**
+     * Increments fields of this instance based on the given result object.
+     * @param result the result object
+     */
+    private void increment(TestResult result) {
+        this.nrOfTotalConfigurations++;
+        if (!result.wasSuccessful()) {
+            this.nrOfFailedConfigurations++;
+        }
+    }
+    
+    /**
+     * Serializes this instance to a file in the given directory.
+     * @param directory the directory
+     */
+    private void save(String directory) {
+        String fileName = directory + FILE_NAME_OF_RESULT_SUMMARY;
+        ObjectOutputStream oos = null;
+        try {
+            try {
+                oos = new ObjectOutputStream(new FileOutputStream(fileName));
+                oos.writeObject(this);
+            } finally {
+                if (oos != null) {
+                    oos.close();
+                }
+            }
+        } catch (FileNotFoundException e) {
+            throw new JDOFatalException(
+                    "Cannot create file " + fileName, e);
+        } catch (IOException e) {
+            throw new JDOFatalException(
+                    "Cannot serialize result summary to file "
+                    + fileName, e);
+        }
+    }
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString() {
+        String result;
+        if (this.nrOfFailedConfigurations==0) {
+            result = "All (" + this.nrOfTotalConfigurations + ") configurations passed.";
+        } else {
+            result = String.valueOf(this.nrOfFailedConfigurations) + " of " +
+                     this.nrOfTotalConfigurations + " configurations failed.";
+        }
+        return result;
+    }
+}



Mime
View raw message