8144742: Instrument intermittently failing test GCDuringIteration.java
authordarcy
Fri, 04 Dec 2015 11:01:53 -0800
changeset 34435 5beaa7987970
parent 34434 16dd60e78af4
child 34436 33c20335507c
8144742: Instrument intermittently failing test GCDuringIteration.java Reviewed-by: rriggs, martin
jdk/test/TEST.groups
jdk/test/java/util/WeakHashMap/GCDuringIteration.java
--- a/jdk/test/TEST.groups	Thu Dec 03 17:44:18 2015 -0800
+++ b/jdk/test/TEST.groups	Fri Dec 04 11:01:53 2015 -0800
@@ -30,6 +30,7 @@
     -java/lang/ProcessHandle/TreeTest.java \
     -java/util/zip/TestLocalTime.java \
     :jdk_util \
+    -java/util/WeakHashMap/GCDuringIteration.java \
     -java/util/concurrent/Phaser/Basic.java \
     sun/nio/cs/ISO8859x.java \
     java/nio/Buffer \
@@ -40,6 +41,7 @@
     java/lang/ProcessHandle/TreeTest.java \
     java/util/zip/TestLocalTime.java \
     java/util/concurrent/Phaser/Basic.java \
+    java/util/WeakHashMap/GCDuringIteration.java \
     :jdk_io \
     :jdk_nio \
     -sun/nio/cs/ISO8859x.java \
--- a/jdk/test/java/util/WeakHashMap/GCDuringIteration.java	Thu Dec 03 17:44:18 2015 -0800
+++ b/jdk/test/java/util/WeakHashMap/GCDuringIteration.java	Fri Dec 04 11:01:53 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,13 +24,17 @@
 /*
  * @test
  * @bug 6499848
+ * @library /lib/testlibrary/
+ * @build jdk.testlibrary.RandomFactory
+ * @run main GCDuringIteration
  * @summary Check that iterators work properly in the presence of
  *          concurrent finalization and removal of elements.
- * @key randomness
+ * @key randomness intermittent
  */
 
 import java.util.*;
 import java.util.concurrent.CountDownLatch;
+import jdk.testlibrary.RandomFactory;
 
 public class GCDuringIteration {
     private static void waitForFinalizersToRun() {
@@ -65,8 +69,9 @@
         equal(map.values().iterator().next(), v);
     }
 
+    static final Random rnd = RandomFactory.getRandom();
+
     void checkIterator(final Iterator<Map.Entry<Foo, Integer>> it, int first) {
-        final Random rnd = new Random();
         for (int i = first; i >= 0; --i) {
             if (rnd.nextBoolean()) check(it.hasNext());
             equal(it.next().getValue(), i);
@@ -86,7 +91,7 @@
         final int n = 10;
         // Create array of strong refs
         final Foo[] foos = new Foo[2*n];
-        final Map<Foo,Integer> map = new WeakHashMap<Foo,Integer>(foos.length);
+        final Map<Foo,Integer> map = new WeakHashMap<>(foos.length);
         check(map.isEmpty());
         equal(map.size(), 0);