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

Comparing jsr166/src/test/tck/ThreadLocalRandom8Test.java (file contents):
Revision 1.6 by jsr166, Fri Sep 27 20:28:04 2013 UTC vs.
Revision 1.12 by jsr166, Fri Aug 4 03:30:21 2017 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.AtomicInteger;
9   import java.util.concurrent.atomic.LongAdder;
10  
11 + import junit.framework.Test;
12 + import junit.framework.TestSuite;
13 +
14   public class ThreadLocalRandom8Test 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(ThreadLocalRandom8Test.class);
# Line 117 | Line 119 | public class ThreadLocalRandom8Test exte
119          for (int least = -15485867; least < MAX_INT_BOUND; least += 524959) {
120              for (int bound = least + 2; bound > least && bound < MAX_INT_BOUND; bound += 67867967) {
121                  final int lo = least, hi = bound;
122 <                r.ints(size, lo, hi).parallel().
123 <                    forEach(x -> {if (x < lo || x >= hi)
124 <                                fails.getAndIncrement(); });
122 >                r.ints(size, lo, hi).parallel().forEach(
123 >                    x -> {
124 >                        if (x < lo || x >= hi)
125 >                            fails.getAndIncrement(); });
126              }
127          }
128          assertEquals(0, fails.get());
# Line 135 | Line 138 | public class ThreadLocalRandom8Test exte
138          for (long least = -86028121; least < MAX_LONG_BOUND; least += 1982451653L) {
139              for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
140                  final long lo = least, hi = bound;
141 <                r.longs(size, lo, hi).parallel().
142 <                    forEach(x -> {if (x < lo || x >= hi)
143 <                                fails.getAndIncrement(); });
141 >                r.longs(size, lo, hi).parallel().forEach(
142 >                    x -> {
143 >                        if (x < lo || x >= hi)
144 >                            fails.getAndIncrement(); });
145              }
146          }
147          assertEquals(0, fails.get());
# Line 153 | Line 157 | public class ThreadLocalRandom8Test exte
157          for (double least = 0.00011; least < 1.0e20; least *= 9) {
158              for (double bound = least * 1.0011; bound < 1.0e20; bound *= 17) {
159                  final double lo = least, hi = bound;
160 <                r.doubles(size, lo, hi).parallel().
161 <                    forEach(x -> {if (x < lo || x >= hi)
162 <                                fails.getAndIncrement(); });
160 >                r.doubles(size, lo, hi).parallel().forEach(
161 >                    x -> {
162 >                        if (x < lo || x >= hi)
163 >                            fails.getAndIncrement(); });
164              }
165          }
166          assertEquals(0, fails.get());
# Line 227 | Line 232 | public class ThreadLocalRandom8Test exte
232          assertEquals(size, counter.sum());
233      }
234  
235 +    /**
236 +     * A deserialized/reserialized ThreadLocalRandom is always
237 +     * identical to ThreadLocalRandom.current()
238 +     */
239 +    public void testSerialization() {
240 +        assertSame(
241 +            ThreadLocalRandom.current(),
242 +            serialClone(ThreadLocalRandom.current()));
243 +        // In the current implementation, there is exactly one shared instance
244 +        if (testImplementationDetails)
245 +            assertSame(
246 +                ThreadLocalRandom.current(),
247 +                java.util.concurrent.CompletableFuture.supplyAsync(
248 +                    () -> serialClone(ThreadLocalRandom.current())).join());
249 +    }
250 +
251   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines