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

Comparing jsr166/src/test/tck/ThreadLocalRandomTest.java (file contents):
Revision 1.19 by jsr166, Fri Sep 27 20:22:26 2013 UTC vs.
Revision 1.22 by jsr166, Sun Nov 13 03:36:50 2016 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6 < import junit.framework.*;
7 < import java.util.*;
6 >
7   import java.util.concurrent.ThreadLocalRandom;
8   import java.util.concurrent.atomic.AtomicLong;
9   import java.util.concurrent.atomic.AtomicReference;
10  
11 + import junit.framework.Test;
12 + import junit.framework.TestSuite;
13 +
14   public class ThreadLocalRandomTest extends JSR166TestCase {
15  
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run(suite());
17 >        main(suite(), args);
18      }
19      public static Test suite() {
20          return new TestSuite(ThreadLocalRandomTest.class);
# Line 50 | Line 52 | public class ThreadLocalRandomTest exten
52      }
53  
54      /**
55 +     * Repeated calls to next (only accessible via reflection) produce
56 +     * at least two distinct results, and repeated calls produce all
57 +     * possible values.
58 +     */
59 +    public void testNext() throws ReflectiveOperationException {
60 +        ThreadLocalRandom rnd = ThreadLocalRandom.current();
61 +        try {
62 +            java.lang.reflect.Method m
63 +                = ThreadLocalRandom.class.getDeclaredMethod(
64 +                    "next", new Class[] { int.class });
65 +            m.setAccessible(true);
66 +
67 +            int i;
68 +            {
69 +                int val = new java.util.Random().nextInt(4);
70 +                for (i = 0; i < NCALLS; i++) {
71 +                    int q = (int) m.invoke(rnd, new Object[] { 2 });
72 +                    if (val == q) break;
73 +                }
74 +                assertTrue(i < NCALLS);
75 +            }
76 +
77 +            {
78 +                int r = (int) m.invoke(rnd, new Object[] { 3 });
79 +                for (i = 0; i < NCALLS; i++) {
80 +                    int q = (int) m.invoke(rnd, new Object[] { 3 });
81 +                    assertTrue(q < (1<<3));
82 +                    if (r != q) break;
83 +                }
84 +                assertTrue(i < NCALLS);
85 +            }
86 +        } catch (SecurityException acceptable) {}
87 +    }
88 +
89 +    /**
90       * Repeated calls to nextInt produce at least two distinct results
91       */
92      public void testNextInt() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines