|
The planned extensions to tck20's JDO_Test (based on Craig's suggestion):
$ svn diff src/java/org/apache/jdo/tck/JDO_Test.java Index: src/java/org/apache/jdo/tck/JDO_Test.java =================================================================== --- src/java/org/apache/jdo/tck/JDO_Test.java (revision 375502) +++ src/java/org/apache/jdo/tck/JDO_Test.java (working copy) @@ -128,6 +128,10 @@ /** identitytype value for datastoreidentity. */ public static final String DATASTORE_IDENTITY = "datastoreidentity"; + /** New line. + */ + public static final String NL = System.getProperty("line.separator"); + /** * String indicating the type of identity used for the current test case. * The value is either "applicationidentity" or "datastoreidentity". @@ -147,6 +151,10 @@ /** The Properties object for the PersistenceManagerFactory. */ protected static Properties PMFPropertiesObject; + /** A buffer of of error messages. + */ + protected static StringBuffer messages; + /** The PersistenceManagerFactory. */ protected PersistenceManagerFactory pmf; @@ -537,13 +545,36 @@ return props; } + /** Appends to error messages. + */ + protected static synchronized void appendMessage(String message) { + if (messages == null) { + messages = new StringBuffer(); + } + messages.append(message); + messages.append(NL); + } + + /** + * Returns collected error messages, or <code>null</code> if there + * are none, and clears the buffer. + */ + protected static synchronized String popMessages() { + if (messages == null) { + return null; + } + final String msg = messages.toString(); + messages = null; + return msg; + } + /** * Prints the specified msg (if debug is true), before it aborts the * test case. */ public void fail(String assertionFailure, String msg) { if (debug) logger.debug(msg); - fail(assertionFailure + "\n" + msg); + fail(assertionFailure + NL + msg); } // Helper methods to check for supported options Looks good. Just a comment.
1. Please change name of popMessages to something else. Pop has a specific meaning (remove the top element of a Stack) and I don't think it's appropriate for a Message pad. How about: String retrieveMessages() that has the same semantics as your popMessages. > How about:
> String retrieveMessages() that has the same semantics as your popMessages. OK. For thread-safety testing, a simple barrier synchronization utility is needed.
Hi Martin,
the ThreadExceptionHandler changes look good. I looked at the RougueBarriere class. It's small, but still takes some time to understand (at least for me :-)). Maybe you can add some comments motivating why we need a holder for the boolean tripped. I think this allows other threads to see that the barrier is tripped, but the current thread can prepare the value for the next run. Maybe you can also rearrange the code in the await method executed when the barrier is reset. I think tripped[0] = true; lock.notifyAll(); is needed to wake up the other threads, where missing = parties; tripped = new boolean[1]; // new generation is used to initialized the next run. Am I right? Michael Followed Michael's comments on new class RougueBarrier.
Added extension to ThreadExceptionHandler and new RougueBarrier with revision 384047. (Additions to JDO_Test had been checked in already on another JIRA issue.) Removed executable property from new file RogueBarrier.java with revision 386446.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$ svn diff src/java/org/apache/jdo/tck/util/ThreadExceptionHandler.java
Index: src/java/org/apache/jdo/tck/util/ThreadExceptionHandler.java
===================================================================
--- src/java/org/apache/jdo/tck/util/ThreadExceptionHandler.java (revisio
n 375502)
+++ src/java/org/apache/jdo/tck/util/ThreadExceptionHandler.java (working
copy)
@@ -32,7 +32,7 @@
* Map of uncaught exceptions. The thread is the key and the uncaught
* Throwable is the value in the map.
*/
- private Map uncaughtExceptions = new HashMap();
+ private final Map uncaughtExceptions = new HashMap();
/** Constructor. */
public ThreadExceptionHandler() {
@@ -53,11 +53,18 @@
}
/**
- * Returns all uncaught exception stored in this ThreadGroup.
+ * Returns all uncaught exceptions stored in this ThreadGroup.
* Each element in the returned set is a Map.Entry with the
* thread as the key and the uncaught Throwable is the value.
*/
public Set getAllUncaughtExceptions() {
return uncaughtExceptions.entrySet();
}
+
+ /**
+ * Clears all exceptions in this ThreadGroup.
+ */
+ public void clear() {
+ uncaughtExceptions.clear();
+ }
}