Hi,
please find the attached patch implementing the logging proposal.
After applying the patch and before running the TCK, make sure to
reinstall the schema or to copy "derby.properties" to
"target/database/derby". That file contains a property specifying
where to write the Derby logging file. I changed the logging level in
order to see SQL statements in that file.
This is the output of "svn status" in my workspace:
tck20>svn status
A test/java/org/apache/jdo/tck/util/TCKFileAppender.java
M test/java/org/apache/jdo/tck/util/BatchTestRunner.java
M test/conf/logging.properties
M test/conf/derby.properties
A test/conf/log4j.properties
M project.properties
M maven.xml
Regards,
Michael
------------------------------------------------------------------------
Index: test/java/org/apache/jdo/tck/util/TCKFileAppender.java
===================================================================
--- test/java/org/apache/jdo/tck/util/TCKFileAppender.java
(revision 0)
+++ test/java/org/apache/jdo/tck/util/TCKFileAppender.java
(revision 0)
@@ -0,0 +1,54 @@
+/*
+ * 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.IOException;
+
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Layout;
+
+/**
+ * FileAppender appends log events to a file.
+ */
+public class TCKFileAppender extends FileAppender {
+
+ /**
+ * Delegates to super constructor.
+ */
+ public TCKFileAppender() {}
+ + public TCKFileAppender(Layout layout, String filename,
boolean append, + boolean bufferedIO, int bufferSize)
throws IOException {
+ super(layout, filename, append, bufferedIO, bufferSize);
+ }
+ + public TCKFileAppender(Layout layout, String filename,
boolean append) + throws IOException {
+ super(layout, filename, append);
+ }
+ + public TCKFileAppender(Layout layout, String filename)
throws IOException {
+ this(layout, filename, true);
+ }
+
+ public synchronized void setFile(String fileName, boolean append,
boolean bufferedIO, int bufferSize) + throws IOException {
+ String changedFileName =
BatchTestRunner.changeFileNameCreateDirectory(fileName);
+ super.setFile(changedFileName, append, bufferedIO, bufferSize);
+ }
+}
+
Property changes on:
test/java/org/apache/jdo/tck/util/TCKFileAppender.java
___________________________________________________________________
Name: svn:executable
+ *
Index: test/java/org/apache/jdo/tck/util/BatchTestRunner.java
===================================================================
--- test/java/org/apache/jdo/tck/util/BatchTestRunner.java
(revision 233318)
+++ test/java/org/apache/jdo/tck/util/BatchTestRunner.java (working
copy)
@@ -17,16 +17,13 @@
package org.apache.jdo.tck.util;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.text.SimpleDateFormat;
import java.util.Arrays;
-import java.util.Date;
import junit.framework.Test;
import junit.framework.TestResult;
@@ -57,7 +54,7 @@
/** Redirect System.out and System.err to an ConsoleFileOutput
instance. */
static {
- if (!Boolean.getBoolean("noLogFile")) {
+ if (!Boolean.getBoolean("no.log.file")) {
PrintStream printStream = new PrintStream(new
ConsoleFileOutput());
System.setErr(printStream);
System.setOut(printStream);
@@ -191,34 +188,17 @@
private static class ConsoleFileOutput extends OutputStream {
- private static String outDir = "logs";
- private static String fileNameSuffix = ".txt";
- private static SimpleDateFormat simpleDateFormat = new
SimpleDateFormat("yyyyMMdd-HHmmss");
private PrintStream systemOut = System.out;
private FileOutputStream fileOut;
private ConsoleFileOutput() {
- String identityType =
System.getProperty("jdo.tck.identitytype");
- String db = System.getProperty("jdo.tck.database");
- String testConfig = System.getProperty("jdo.tck.cfg");
- if (identityType.equals("applicationidentity"))
- identityType = "app";
- else identityType = "dsid";
- testConfig = testConfig.substring(0,
testConfig.indexOf('.'));
- String fileName = simpleDateFormat.format(new Date()) + "-"
- + db + "-"
- + identityType + "-"
- + testConfig
- + fileNameSuffix;
- File dir = new File(outDir);
- if (!dir.exists()) {
- dir.mkdir();
- }
- + String fileName = null;
try {
- fileOut = new FileOutputStream(new File(dir, fileName));
- } catch (FileNotFoundException e) {
- System.err.println("Cannot create log file
"+fileName+". "+e);
+ fileName = getFileNameCreateDirectory();
+ this.fileOut = new FileOutputStream(fileName);
+ } catch (IOException e) {
+ if (fileName!=null)
+ System.err.println("Cannot create log file
"+fileName+". "+e);
}
}
@@ -246,4 +226,85 @@
this.fileOut.flush();
} }
+ + public static String getFileNameCreateDirectory() throws
IOException {
+ return changeFileNameCreateDirectory(".txt");
+ }
+ + public static String changeFileNameCreateDirectory(String
fileName) throws IOException {
+ String directory =
getSysPropertyAsPartialFileName("jdo.tck.log.directory",
File.separatorChar);
+ if (directory!=null) {
+ File dir = new File(directory);
+ if (!dir.exists() &&
+ !dir.mkdirs()) {
+ throw new IOException("Cannot create directory "+dir);
+ }
+ }
+
+ String db =
getSysPropertyAsPartialFileName("jdo.tck.database");
+ + String identityType =
getSysPropertyAsPartialFileName("jdo.tck.identitytype");
+ if (identityType!=null) {
+ if (identityType.equals("applicationidentity")) {
+ identityType = "app";
+ } else { + identityType = "dsid";
+ }
+ }
+ + String configuration =
getSysPropertyAsPartialFileName("jdo.tck.cfg");
+ if (configuration!=null) {
+ int index = configuration.indexOf('.');
+ if (index!=-1) {
+ configuration = configuration.substring(0, index);
+ }
+ }
+ + directory = fixPartialFileName(directory);
+ db = fixPartialFileName(db, '-',
+ new String[]{identityType, configuration, fileName});
+ identityType = fixPartialFileName(identityType, '-',
+ new String[]{configuration, fileName});
+ configuration = fixPartialFileName(configuration, '-',
+ new String[]{fileName});
+
+ return directory + db + identityType + configuration + fileName;
+ }
+ + private static String getSysPropertyAsPartialFileName(String
property) {
+ return getSysPropertyAsPartialFileName(property, (char)0);
+ }
+ + private static String getSysPropertyAsPartialFileName(String
property, char trailingChar) {
+ String result = System.getProperty(property);
+ if (result!=null &&
+ trailingChar!=0) {
+ result += trailingChar;
+ }
+ return result;
+ }
+
+ private static String fixPartialFileName(String str) {
+ if (str==null) {
+ str = "";
+ }
+ return str;
+ }
+ + private static String fixPartialFileName(String str, char c,
+ String[] values) {
+ str = fixPartialFileName(str);
+ if (!str.equals("")) {
+ for (int i = 0; i < values.length; i++) {
+ String value = values[i];
+ if (value!=null &&
+ !value.equals("") &&
+ !value.startsWith(".")) {
+ str += c;
+ break;
+ }
+ }
+ }
+ return str;
+ }
}
Index: test/conf/logging.properties
===================================================================
--- test/conf/logging.properties (revision 233318)
+++ test/conf/logging.properties (working copy)
@@ -41,26 +41,3 @@
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINEST
-
-
-######################
-# JPOX logging properties
-######################
-
-# Define the destination and format of our logging
-log4j.appender.A1=org.apache.log4j.FileAppender
-log4j.appender.A1.File=jpox.log
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p
[%c] - %m%n
-
-# JPOX Categories
-log4j.category.JPOX.JDO=INFO, A1
-log4j.category.JPOX.Cache=INFO, A1
-log4j.category.JPOX.MetaData=INFO, A1
-log4j.category.JPOX.General=DEBUG, A1
-log4j.category.JPOX.Utility=INFO, A1
-log4j.category.JPOX.Transaction=INFO, A1
-log4j.category.JPOX.RDBMS=DEBUG, A1
-
-log4j.category.JPOX.Enhancer=INFO, A1
-log4j.category.JPOX.SchemaTool=INFO, A1
Index: test/conf/derby.properties
===================================================================
--- test/conf/derby.properties (revision 233318)
+++ test/conf/derby.properties (working copy)
@@ -1,2 +1,46 @@
-# This flag must be set on Mac OSX
-#derby.storage.fileSyncTransactionLog=true
+# This flag must be set on Mac OSX
+#derby.storage.fileSyncTransactionLog=true
+
+#When this property is set to true, Derby writes the query plan
information +#into the derby.log file for all executed queries.
+#Default: false
+#derby.language.logQueryPlan=true
+
+#When this property is set to true, Derby writes the text and
parameter values +#of all executed statements to the information log
at the beginning of +#execution. It also writes information about
commits and rollbacks. +#Information includes the time and thread number.
+#Default: false
+derby.language.logStatementText=true
+
+#Specifies name of the file to which the error log is written. +#If
the file name is relative, it is taken as relative to the system
directory.
+#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
+
+#Specifies which errors are logged to the Derby error log
+#(typically the derby.log file). In test environments, use the
setting +#derby.stream.error.logSeverityLevel=0 so that all problems
are reported.
+#Any error raised in a Derby system is given a level of severity.
+#This property indicates the minimum severity necessary for an error
to appear +#in the error log. The severities are defined in the class
+#org.apache.derby.types.ExceptionSeverity. +#The higher the number,
the more severe the error.
+#20000: Errors that cause the statement to be rolled back, +#for
example syntax errors and constraint violations.
+#30000: Errors that cause the transaction to be rolled back, +#for
example deadlocks.
+#40000: Errors that cause the connection to be closed.
+#50000: Errors that shut down the Derby system.
+#Default: 40000
+#derby.stream.error.logSeverityLevel=0
+
+#Specifies whether to append to or destroy and re-create the
derby.log file, +#which is used to record error and other information
+#when Derby starts up in a JVM.
+#You can set this property even if the file does not yet exist;
+#Derby creates the file.
+#Default: false
+derby.infolog.append=true
Index: test/conf/log4j.properties
===================================================================
--- test/conf/log4j.properties (revision 0)
+++ test/conf/log4j.properties (revision 0)
@@ -0,0 +1,40 @@
+#
+# 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.
+
+###########################
+# JPOX logging properties #
+###########################
+
+# JPOX appenders
+log4j.appender.JPOX=org.apache.jdo.tck.util.TCKFileAppender
+log4j.appender.JPOX.File=jpox.txt
+log4j.appender.JPOX.layout=org.apache.log4j.PatternLayout
+log4j.appender.JPOX.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t)
%-5p [%c] - %m%n
+
+# JPOX loggers
+log4j.logger.JPOX=INFO, JPOX
+#log4j.logger.JPOX.JDO=INFO, JPOX
+#log4j.logger.JPOX.Cache=INFO, JPOX
+#log4j.logger.JPOX.MetaData=INFO, JPOX
+#log4j.logger.JPOX.General=DEBUG, JPOX
+#log4j.logger.JPOX.Utility=INFO, JPOX
+#log4j.logger.JPOX.Transaction=INFO, JPOX
+#log4j.logger.JPOX.RDBMS=INFO, JPOX
+
+log4j.logger.JPOX.Enhancer=INFO, JPOX
+log4j.logger.JPOX.SchemaTool=INFO, JPOX
+
+# C3P0 loggers
+log4j.logger.com.mchange.v2=INFO, JPOX
Property changes on: test/conf/log4j.properties
___________________________________________________________________
Name: svn:executable
+ *
Index: project.properties
===================================================================
--- project.properties (revision 233318)
+++ project.properties (working copy)
@@ -21,7 +21,7 @@
# iut properties file
iut.runtck.properties = iut.properties
-iut.runtck.sysproperties =
-Dderby.system.home=${jdo.tck.testdir}/database/${jdo.tck.database}
-Dlog4j.configuration=file:${basedir}/test/conf/logging.properties
+iut.runtck.sysproperties =
-Dderby.system.home=${jdo.tck.testdir}/database/${jdo.tck.database}
# Flags indicating whether IUT supports application/datastore identity
iut.applicationidentity.supported = yes
@@ -32,7 +32,7 @@
iut.enhancer.main = ${jdo.enhancer.main}
iut.enhancer.options = -v -d "${iut.enhanced.dir}"
iut.enhancer.args = ${jdo.tck.jdometadata.files}
-iut.enhancer.sysproperties =
-Dlog4j.configuration=file:${basedir}/test/conf/logging.properties
+iut.enhancer.sysproperties =
iut.enhancer.sourcepath =
${jdo.tck.testclasses.dir}${path.separator}${jdo.jdoapi.jarfile}${path.separator}${junit.jarfile}${path.separator}${log4j.jarfile}
iut.enhancer.classpath =
${jpox.enhancer.jarfile}${path.separator}${jpox.jdori.jarfile}${path.separator}${jdo.jdoapi.jarfile}${path.separator}${log4j.jarfile}${path.separator}${bcel.jarfile}${path.separator}${jdo.tck.testclasses.dir}
@@ -49,7 +49,10 @@
jdo.tck.testclasses.dir = ${maven.build.dir}/classes
jdo.tck.testdir = ${maven.build.dir}
jdo.tck.resultprinterclass = org.apache.jdo.tck.util.BatchResultPrinter
-database.runtck.sysproperties =
-Dderby.system.home=${jdo.tck.testdir}/database/${jdo.tck.database}
-Dlog4j.configuration=file:${basedir}/test/conf/logging.properties
+jdo.tck.log.directory = logs
+jdo.tck.log.directory.database =
${maven.build.dir}/${jdo.tck.log.directory}/database
+jdo.tck.log.directory.enhancer =
${maven.build.dir}/${jdo.tck.log.directory}/enhancer
+database.runtck.sysproperties =
-Dderby.system.home=${jdo.tck.testdir}/database/${jdo.tck.database}
jdo.runtck.sysproperties = -Xmx512m
# dependencies
@@ -307,6 +310,9 @@
org/apache/jdo/tck/api/instancecallbacks/NoAccessToFieldsAfterPredelete.class
\
org/apache/jdo/tck/api/instancecallbacks/TestParts.class
+jdo.tck.util.enhancer.sources = \
+ org/apache/jdo/tck/util/TCKFileAppender.java
+ jdo.tck.jdometadata.files = \
org/apache/jdo/tck/pc/company/package.jdo \
org/apache/jdo/tck/pc/fieldtypes/AllTypes.jdo \
Index: maven.xml
===================================================================
--- maven.xml (revision 233318)
+++ maven.xml (working copy)
@@ -142,6 +142,7 @@
</goal>
<goal name="privateInstallSchema">
+ <mkdir dir="${jdo.tck.log.directory.database}"/>
<!-- load mappings into a HashSet to unique them -->
<j:new var="uniqueMappings" className="java.util.HashSet"/>
<j:forEach var="cfg" items="${jdo.tck.cfglist}">
@@ -197,12 +198,16 @@
<!-- ================== -->
<goal name="runtck.iut" prereqs="setProps">
+ <mkdir dir="${jdo.tck.log.directory.database}"/>
<attainGoal name="privateRuntck.iut"/>
</goal>
<goal name="privateRuntck.iut"
prereqs="java:compile, testrunner.set, copyprops,
doEnhance.iut, package.iut">
<!-- Run tests for all databases, identity types, and
configurations -->
+ <tstamp>
+ <format property="timestamp" pattern="yyyyMMdd-HHmmss"/>
+ </tstamp>
<echo>Run all configurations on iut</echo>
<j:forEach var="jdo.tck.database" items="${jdo.tck.dblist}">
<j:forEach var="jdo.tck.identitytype"
items="${jdo.tck.identitytypes}">
@@ -228,12 +233,16 @@
</goal>
<goal name="runtck.jdori" prereqs="setProps">
+ <mkdir dir="${jdo.tck.log.directory.database}"/>
<attainGoal name="privateRuntck.jdori"/>
</goal>
<goal name="privateRuntck.jdori"
prereqs="java:compile, testrunner.set, copyprops,
doEnhance.jdori, package.jdori">
<!-- Run tests for all databases, identity types, and
configurations -->
+ <tstamp>
+ <format property="timestamp" pattern="yyyyMMdd-HHmmss"/>
+ </tstamp>
<echo>Run all configurations on jdori</echo>
<j:forEach var="jdo.tck.database" items="${jdo.tck.dblist}">
<j:forEach var="jdo.tck.identitytype"
items="${jdo.tck.identitytypes}">
@@ -296,6 +305,8 @@
value="${jdo.tck.cfg}"/>
<sysproperty key="jdo.tck.exclude"
value="${jdo.tck.exclude}"/>
+ <sysproperty key="jdo.tck.log.directory"
+ value="${jdo.tck.log.directory}/${timestamp}"/>
<jvmarg line="${database.runtck.sysproperties}"/>
<jvmarg line="${iut.runtck.sysproperties}"/>
<arg line="${jdo.tck.classes}"/>
@@ -341,6 +352,8 @@
value="${jdo.tck.cfg}"/>
<sysproperty key="jdo.tck.exclude"
value="${jdo.tck.exclude}"/>
+ <sysproperty key="jdo.tck.log.directory"
+ value="${jdo.tck.log.directory}/${timestamp}"/>
<jvmarg line="${database.runtck.sysproperties}"/>
<jvmarg line="${jdo.runtck.sysproperties}"/>
<arg line="${jdo.tck.classes}"/>
@@ -381,10 +394,17 @@
<copy todir="${jdo.tck.enhanced.dir}/${jdo.tck.identitytype}">
<fileset dir="${basedir}/test/jdo/${jdo.tck.identitytype}"
includes="**/*.jdo, **/jdoTest.properties"/>
+ <fileset dir="${basedir}/test/conf">
+ <include name="commons-logging.properties"/>
+ <include name="simplelog.properties"/>
+ <include name="logging.properties"/>
+ <include name="log4j.properties"/>
+ </fileset>
</copy>
<!-- compile pc and pa classes -->
<javac srcdir="${basedir}/test/java"
- includes="${jdo.tck.pcclasses.sources}
${jdo.tck.paclasses.sources}"
+ includes="${jdo.tck.pcclasses.sources}
${jdo.tck.paclasses.sources}
+ ${jdo.tck.util.enhancer.sources}"
destdir="${jdo.tck.enhanced.dir}/${jdo.tck.identitytype}"
debug="on"
classpathref="project.class.path">
@@ -410,6 +430,12 @@
dir="${jdo.tck.enhanced.dir}/${jdo.tck.identitytype}"
classname="${iut.enhancer.main}"
classpathref="this.enhance.class.path">
+ <sysproperty key="jdo.tck.identitytype"
+ value="${jdo.tck.identitytype}"/>
+ <sysproperty key="jdo.tck.log.directory"
+
value="${jdo.tck.log.directory.enhancer}"/>
+ <sysproperty key="no.log.file"
+ value="true"/>
<jvmarg line="${iut.enhancer.sysproperties}"/>
<arg line="${iut.enhancer.options}"/>
<arg line="${iut.enhancer.args}"/>
@@ -432,6 +458,12 @@
dir="${jdo.tck.enhanced.dir}/${jdo.tck.identitytype}"
classname="${jdo.enhancer.main}"
classpathref="this.enhance.class.path">
+ <sysproperty key="jdo.tck.identitytype"
+ value="${jdo.tck.identitytype}"/>
+ <sysproperty key="jdo.tck.log.directory"
+
value="${jdo.tck.log.directory.enhancer}"/>
+ <sysproperty key="no.log.file"
+ value="true"/>
<jvmarg line="${jdo.enhancer.sysproperties}"/>
<arg line="${jdo.enhancer.options}"/>
<arg line="${jdo.enhancer.args}"/>
@@ -577,6 +609,7 @@
<include name="commons-logging.properties"/>
<include name="simplelog.properties"/>
<include name="logging.properties"/>
+ <include name="log4j.properties"/>
<include name="jndi.properties"/>
</fileset>
<fileset dir="${basedir}/test/java">