sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1522572 - in /sis/branches/JDK7: core/sis-metadata/src/test/java/org/apache/sis/metadata/ core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/ core/sis-utility/src/test/java/org/apache/sis/test/ core/sis-utility/...
Date Thu, 12 Sep 2013 13:34:36 GMT
Author: desruisseaux
Date: Thu Sep 12 13:34:35 2013
New Revision: 1522572

URL: http://svn.apache.org/r1522572
Log:
Differs the report of random generator seed number only in case of test failure.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -175,7 +175,7 @@ public abstract strictfp class MetadataT
      */
     @Test
     public void testPropertyValues() {
-        random = TestUtilities.createRandomNumberGenerator("testPropertyValues");
+        random = TestUtilities.createRandomNumberGenerator();
         for (final Class<?> type : types) {
             if (!CodeList.class.isAssignableFrom(type)) {
                 final Class<?> impl = getImplementation(type);

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -240,7 +240,7 @@ public final strictfp class TreeNodeChil
     public void testRemoveWithoutCollections() {
         final DefaultCitation  citation = metadataWithoutCollections();
         final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
-        testRemove(createRandomNumberGenerator("testRemoveWithoutCollections"), children);
+        testRemove(createRandomNumberGenerator(), children);
     }
 
     /**
@@ -255,7 +255,7 @@ public final strictfp class TreeNodeChil
     public void testRemoveWithSingletonInCollections() {
         final DefaultCitation  citation = metadataWithSingletonInCollections();
         final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
-        testRemove(createRandomNumberGenerator("testRemoveWithSingletonInCollections"), children);
+        testRemove(createRandomNumberGenerator(), children);
     }
 
     /**
@@ -270,7 +270,7 @@ public final strictfp class TreeNodeChil
     public void testRemoveWithMultiOccurrences() {
         final DefaultCitation  citation = metadataWithSingletonInCollections();
         final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
-        testRemove(createRandomNumberGenerator("testRemoveWithMultiOccurrences"), children);
+        testRemove(createRandomNumberGenerator(), children);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/GeneralMatrixTest.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -40,12 +40,11 @@ public final strictfp class GeneralMatri
     /**
      * Chooses a random size for the square matrix.
      *
-     * @param testMethod  The name of the method which need a random number generator.
      * @param needsRandom Ignored.
      */
     @Override
-    void initialize(final String testMethod, final boolean needsRandom) {
-        super.initialize(testMethod, true);
+    void initialize(final boolean needsRandom) {
+        super.initialize(true);
         size = 5 + random.nextInt(8); // Matrix sizes from 5 to 12 inclusive.
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -67,12 +67,11 @@ public abstract strictfp class MatrixTes
     /**
      * Initializes the test. This method shall be invoked at the beginning of each test method.
      *
-     * @param testMethod The name of the method which need a random number generator.
      * @param needsRandom {@code true} if the test method will need random numbers.
      */
-    void initialize(final String testMethod, final boolean needsRandom) {
+    void initialize(final boolean needsRandom) {
         if (needsRandom && random == null) {
-            random = TestUtilities.createRandomNumberGenerator(testMethod);
+            random = TestUtilities.createRandomNumberGenerator();
         }
     }
 
@@ -109,7 +108,7 @@ public abstract strictfp class MatrixTes
      * This is a convenience method for the {@link testConstructor()} methods in {@code Matrix1…4Test}
subclasses.
      */
     final double[] initConstructorTest(final int length) {
-        initialize("testConstructor", true);
+        initialize(true);
         final double[] elements = new double[length];
         for (int k=0; k<length; k++) {
             elements[k] = random.nextDouble() * 100;
@@ -127,7 +126,7 @@ public abstract strictfp class MatrixTes
      */
     @Test
     public void testGetElements() {
-        initialize("testGetElements", true);
+        initialize(true);
         final int numRow = getNumRow();
         final int numCol = getNumCol();
         final double[] elements = new double[numRow * numCol];
@@ -152,7 +151,7 @@ public abstract strictfp class MatrixTes
     @Test
     @DependsOnMethod("testGetElements")
     public void testSetElement() {
-        initialize("testSetElement", true);
+        initialize(true);
         final int numRow = getNumRow();
         final int numCol = getNumCol();
         final MatrixSIS matrix = Matrices.createZero(numRow, numCol);
@@ -179,7 +178,7 @@ public abstract strictfp class MatrixTes
     @Test
     @DependsOnMethod("testSetElement")
     public void testIsIdentity() {
-        initialize("testIsIdentity", false);
+        initialize(false);
         final int numRow = getNumRow();
         final int numCol = getNumCol();
         final MatrixSIS matrix = Matrices.create(numRow, numCol);

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -43,12 +43,11 @@ public final strictfp class NonSquareMat
     /**
      * Chooses a random size for the matrix and ensure that the matrix is not square.
      *
-     * @param testMethod  The name of the method which need a random number generator.
      * @param needsRandom Ignored.
      */
     @Override
-    void initialize(final String testMethod, final boolean needsRandom) {
-        super.initialize(testMethod, true);
+    void initialize(final boolean needsRandom) {
+        super.initialize(true);
         numRow = 5 + random.nextInt(8); // Matrix sizes from 5 to 12 inclusive.
         do numCol = 5 + random.nextInt(8);
         while (numCol == numRow);

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
Thu Sep 12 13:34:35 2013
@@ -89,6 +89,13 @@ public abstract strictfp class TestCase 
     public static final boolean PENDING_FUTURE_SIS_VERSION = false;
 
     /**
+     * The seed for the random number generator created by {@link TestUtilities#createRandomNumberGenerator(String)},
+     * or 0 if none. This information is used for printing the seed in case of test failure,
in order to allow the
+     * developer to reproduce the failure.
+     */
+    static long randomSeed;
+
+    /**
      * The output writer where to print debugging information (never {@code null}).
      * Texts sent to this printer will be show only if the test fails, or if the
      * {@value org.apache.sis.test.TestConfiguration#VERBOSE_OUTPUT_KEY} system property
@@ -174,6 +181,7 @@ public abstract strictfp class TestCase 
      * @param success {@code true} if this method is invoked on build success,
      */
     static void flushOutput() {
+        randomSeed = 0;
         System.out.flush();
         System.err.flush();
         synchronized (buffer) { // This is the lock used by the 'out' PrintWriter.

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestRunner.java [UTF-8]
Thu Sep 12 13:34:35 2013
@@ -21,6 +21,7 @@ import java.util.List;
 import java.util.HashSet;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.io.PrintWriter;
 
 import org.junit.Test;
 import org.junit.runner.Description;
@@ -55,7 +56,7 @@ import static org.apache.sis.util.collec
  * @author  Stephen Connolly
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from <a href="http://github.com/junit-team/junit.contrib/tree/master/assumes">junit-team</a>)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final class TestRunner extends BlockJUnit4ClassRunner {
@@ -117,10 +118,22 @@ public final class TestRunner extends Bl
          */
         @Override
         public void testFailure(final Failure failure) {
-            addDependencyFailure(failure.getDescription().getMethodName());
+            final String methodName = failure.getDescription().getMethodName();
+            addDependencyFailure(methodName);
+            final long seed = TestCase.randomSeed;
+            if (seed != 0) {
+                final PrintWriter out = TestCase.out;
+                out.print("Random number generator for “");
+                out.print(methodName);
+                out.print("” was created with seed ");
+                out.print(seed);
+                out.println('.');
+                // Seed we be cleared by TestCase.flushOutput()
+            }
             if (!TestCase.verbose) {
                 TestCase.flushOutput();
             }
+            // In verbose mode, the flush will be done by testFinished(…).
         }
 
         /**
@@ -335,8 +348,8 @@ public final class TestRunner extends Bl
     }
 
     /**
-     * Declares that the given method failed. Other methods depending on this method
-     * will be ignored.
+     * Declares that the given method failed.
+     * Other methods depending on this method will be ignored.
      *
      * @param methodName The name of the method that failed.
      */

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestUtilities.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -127,8 +127,13 @@ public final strictfp class TestUtilitie
     }
 
     /**
-     * Returns a new random number generator with a random seed. This method logs the seed
value
-     * to the {@link TestCase#out} stream, in order to allow reproducing a test in case of
failure.
+     * Returns a new random number generator with a random seed.
+     * If the test succeed, nothing else will happen. But if the test fails, then the seed
value will
+     * be logged to the {@link TestCase#out} stream in order to allow the developer to reproduce
the
+     * test failure.
+     *
+     * <p>This method shall be invoked only in the body of a test method - the random
number generator
+     * is not valid anymore after the test finished.</p>
      *
      * <p>This method doesn't need to be used in every cases. For example test cases
using
      * {@link Random#nextGaussian()} should create their own random numbers generator with
@@ -144,17 +149,13 @@ public final strictfp class TestUtilitie
      * the developer to reproduce the test with the exact same sequence of numbers.
      * Using this method, the seed can be retrieved in the messages sent to the output stream.</p>
      *
-     * @param  testMethod The name of the method which need a random number generator.
      * @return A new random number generator initialized with a random seed.
      */
-    public static Random createRandomNumberGenerator(final String testMethod) {
-        final long seed = StrictMath.round(StrictMath.random() * (1L << 48));
-        final PrintWriter out = TestCase.out;
-        out.print("Random number generator for “");
-        out.print(testMethod);
-        out.print("” created with seed ");
-        out.print(seed);
-        out.println('.');
+    public static Random createRandomNumberGenerator() {
+        long seed;
+        do seed = StrictMath.round(StrictMath.random() * (1L << 48));
+        while (seed == 0); // 0 is a sentinal value for "no generator".
+        TestCase.randomSeed = seed;
         return new Random(seed);
     }
 

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/collection/RangeSetTest.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -327,7 +327,7 @@ public final strictfp class RangeSetTest
     @Performance
     public void stress() throws InterruptedException {
         final PrintWriter out = TestCase.out;
-        final Random r = TestUtilities.createRandomNumberGenerator("stress");
+        final Random r = TestUtilities.createRandomNumberGenerator();
         for (int p=0; p<10; p++) {
             final long start = System.nanoTime();
             final RangeSet<Integer> set = RangeSet.create(Integer.class, true, false);

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelDataInputTest.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -67,7 +67,7 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testAllReadMethods() throws IOException {
-        final Random random = TestUtilities.createRandomNumberGenerator("testAllReadMethods");
+        final Random random = TestUtilities.createRandomNumberGenerator();
         final byte[] array = createRandomArray(ARRAY_MAX_SIZE * 1024, random);
         compareStreamToBuffer(random, array.length,
                 new DataInputStream(new ByteArrayInputStream(array)),
@@ -162,7 +162,7 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testReadString() throws IOException {
-        final Random random   = TestUtilities.createRandomNumberGenerator("testReadString");
+        final Random random   = TestUtilities.createRandomNumberGenerator();
         final String expected = "お元気ですか";
         final byte[] array    = expected.getBytes("UTF-8");
         assertEquals(expected.length()*3, array.length); // Sanity check.
@@ -181,7 +181,7 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testSeekOnForwardOnlyChannel() throws IOException {
-        final Random random = TestUtilities.createRandomNumberGenerator("testSeekOnForwardOnlyChannel");
+        final Random random = TestUtilities.createRandomNumberGenerator();
         int length = random.nextInt(2048) + 1024;
         final byte[] array = createRandomArray(length, random);
         length -= (Long.SIZE / Byte.SIZE); // Safety against buffer underflow.
@@ -205,7 +205,7 @@ public final strictfp class ChannelDataI
      */
     @Test
     public void testPrefetch() throws IOException {
-        final Random     random = TestUtilities.createRandomNumberGenerator("testPrefetch");
+        final Random     random = TestUtilities.createRandomNumberGenerator();
         final int        length = random.nextInt(256) + 128;
         final byte[]     array  = createRandomArray(length, random);
         final ByteBuffer buffer = ByteBuffer.allocate(random.nextInt(64) + 16);

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java?rev=1522572&r1=1522571&r2=1522572&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/ChannelImageInputStreamTest.java
[UTF-8] Thu Sep 12 13:34:35 2013
@@ -62,7 +62,7 @@ public final strictfp class ChannelImage
         int bitOffset = 0;
         int operation = 0;
         final ByteBuffer buffer = ByteBuffer.allocate(128);
-        final Random random = TestUtilities.createRandomNumberGenerator("testWithRandomData");
+        final Random random = TestUtilities.createRandomNumberGenerator();
         final ByteOrder byteOrder = random.nextBoolean() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
         final byte[] data = ChannelDataInputTest.createRandomArray(512 * 1024, random);
         try (ImageInputStream r = ImageIO.createImageInputStream(new ByteArrayInputStream(data));



Mime
View raw message