17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.ByteArrayInputStream;
25 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27 import java.io.ObjectInputStream;
28 import java.io.ObjectOutputStream;
29 import java.util.HashSet;
30 import java.util.Random;
31 import java.util.concurrent.ThreadLocalRandom;
32
33 /*
34 * @test
35 * @bug 8016252
36 * @summary Verify that a serialized HashSet may successfully be deserialized.
37 */
38 public class Serialization {
39
40 private static final int NUM_SETS = 43;
41 private static final int MAX_CAPACITY = 257;
42 private static final float MAX_LOAD_FACTOR = 100.0F;
43
44 private static final Random rnd = ThreadLocalRandom.current();
45
46 private static HashSet<Integer> createHashSet() {
47 int capacity = rnd.nextInt(MAX_CAPACITY);
48 float loadFactor = Float.MIN_VALUE + rnd.nextFloat()*MAX_LOAD_FACTOR;
49 HashSet<Integer> hashSet = new HashSet<Integer>(capacity, loadFactor);
50 float multiplier = 2*rnd.nextFloat(); // range [0,2]
51 int size = (int)(capacity*loadFactor*multiplier);
52 for (int i = 0; i < size; i++) {
53 hashSet.add(rnd.nextInt());
54 }
55 return hashSet;
56 }
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.ByteArrayInputStream;
25 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27 import java.io.ObjectInputStream;
28 import java.io.ObjectOutputStream;
29 import java.util.HashSet;
30 import java.util.Random;
31 import java.util.concurrent.ThreadLocalRandom;
32
33 /*
34 * @test
35 * @bug 8016252
36 * @summary Verify that a serialized HashSet may successfully be deserialized.
37 * @key randomness
38 */
39 public class Serialization {
40
41 private static final int NUM_SETS = 43;
42 private static final int MAX_CAPACITY = 257;
43 private static final float MAX_LOAD_FACTOR = 100.0F;
44
45 private static final Random rnd = ThreadLocalRandom.current();
46
47 private static HashSet<Integer> createHashSet() {
48 int capacity = rnd.nextInt(MAX_CAPACITY);
49 float loadFactor = Float.MIN_VALUE + rnd.nextFloat()*MAX_LOAD_FACTOR;
50 HashSet<Integer> hashSet = new HashSet<Integer>(capacity, loadFactor);
51 float multiplier = 2*rnd.nextFloat(); // range [0,2]
52 int size = (int)(capacity*loadFactor*multiplier);
53 for (int i = 0; i < size; i++) {
54 hashSet.add(rnd.nextInt());
55 }
56 return hashSet;
57 }
|