ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.60 by jsr166, Wed Oct 6 07:49:22 2010 UTC vs.
Revision 1.61 by jsr166, Mon Oct 11 03:54:10 2010 UTC

# Line 97 | Line 97 | public class JSR166TestCase extends Test
97          Boolean.getBoolean("jsr166.useSecurityManager");
98  
99      /**
100 +     * If true, report on stdout all "slow" tests, that is, ones that
101 +     * take more than profileThreshold milliseconds to execute.
102 +     */
103 +    private static final boolean profileTests =
104 +        Boolean.getBoolean("jsr166.profileTests");
105 +
106 +    /**
107 +     * The number of milliseconds that tests are permitted for
108 +     * execution without being reported, when profileTests is set.
109 +     */
110 +    private static final long profileThreshold =
111 +        Long.getLong("jsr166.profileThreshold", 100);
112 +
113 +    protected void runTest() throws Throwable {
114 +        if (profileTests)
115 +            runTestProfiled();
116 +        else
117 +            super.runTest();
118 +    }
119 +
120 +    protected void runTestProfiled() throws Throwable {
121 +        long t0 = System.nanoTime();
122 +        try {
123 +            super.runTest();
124 +        } finally {
125 +            long elapsedMillis =
126 +                (System.nanoTime() - t0) / (1000L * 1000L);
127 +            if (elapsedMillis >= profileThreshold)
128 +                System.out.printf("%n%s: %d%n", toString(), elapsedMillis);
129 +        }
130 +    }
131 +    
132 +    /**
133       * Runs all JSR166 unit tests using junit.textui.TestRunner
134       */
135      public static void main(String[] args) {
# Line 796 | Line 829 | public class JSR166TestCase extends Test
829          }
830      }
831  
832 +    public interface TrackedRunnable extends Runnable {
833 +        boolean isDone();
834 +    }
835 +
836 +    public static TrackedRunnable trackedRunnable(final long timeoutMillis) {
837 +        return new TrackedRunnable() {
838 +                private volatile boolean done = false;
839 +                public boolean isDone() { return done; }
840 +                public void run() {
841 +                    try {
842 +                        Thread.sleep(timeoutMillis);
843 +                        done = true;
844 +                    } catch (InterruptedException ok) {}
845 +                }
846 +            };
847 +    }
848 +
849      public static class TrackedShortRunnable implements Runnable {
850          public volatile boolean done = false;
851          public void run() {
852              try {
853 +                Thread.sleep(SHORT_DELAY_MS);
854 +                done = true;
855 +            } catch (InterruptedException ok) {}
856 +        }
857 +    }
858 +
859 +    public static class TrackedSmallRunnable implements Runnable {
860 +        public volatile boolean done = false;
861 +        public void run() {
862 +            try {
863                  Thread.sleep(SMALL_DELAY_MS);
864                  done = true;
865              } catch (InterruptedException ok) {}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines