--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/AbstractRandomTest.java Wed Dec 06 14:29:06 2017 +0000
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.incubator.http;
+
+import java.util.Random;
+
+/** Abstract supertype for tests that need random numbers within a given range. */
+public class AbstractRandomTest {
+
+ private static Long getSystemSeed() {
+ Long seed = null;
+ try {
+ // note that Long.valueOf(null) also throws a NumberFormatException
+ // so if the property is undefined this will still work correctly
+ seed = Long.valueOf(System.getProperty("seed"));
+ } catch (NumberFormatException e) {
+ // do nothing: seed is still null
+ }
+ return seed;
+ }
+
+ private static long getSeed() {
+ Long seed = getSystemSeed();
+ if (seed == null) {
+ seed = (new Random()).nextLong();
+ }
+ System.out.println("Seed from AbstractRandomTest.getSeed = "+seed+"L");
+ return seed;
+ }
+
+ private static Random random = new Random(getSeed());
+
+ protected static int randomRange(int lower, int upper) {
+ if (lower > upper)
+ throw new IllegalArgumentException("lower > upper");
+ int diff = upper - lower;
+ int r = lower + random.nextInt(diff);
+ return r - (r % 8); // round down to multiple of 8 (align for longs)
+ }
+}
--- a/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/AbstractSSLTubeTest.java Wed Dec 06 12:44:05 2017 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/AbstractSSLTubeTest.java Wed Dec 06 14:29:06 2017 +0000
@@ -73,21 +73,12 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
-public class AbstractSSLTubeTest {
+public class AbstractSSLTubeTest extends AbstractRandomTest {
public static final long COUNTER = 600;
public static final int LONGS_PER_BUF = 800;
public static final long TOTAL_LONGS = COUNTER * LONGS_PER_BUF;
public static final ByteBuffer SENTINEL = ByteBuffer.allocate(0);
- public static final Random rand = new Random();
-
- protected static int randomRange(int lower, int upper) {
- if (lower > upper)
- throw new IllegalArgumentException("lower > upper");
- int diff = upper - lower;
- int r = lower + rand.nextInt(diff);
- return r - (r % 8); // round down to multiple of 8 (align for longs)
- }
protected static ByteBuffer getBuffer(long startingAt) {
ByteBuffer buf = ByteBuffer.allocate(LONGS_PER_BUF * 8);
--- a/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/FlowTest.java Wed Dec 06 12:44:05 2017 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/FlowTest.java Wed Dec 06 14:29:06 2017 +0000
@@ -58,7 +58,7 @@
import jdk.incubator.http.internal.common.SSLFlowDelegate;
@Test
-public class FlowTest {
+public class FlowTest extends AbstractRandomTest {
private final SubmissionPublisher<List<ByteBuffer>> srcPublisher;
private final ExecutorService executor;
@@ -106,16 +106,6 @@
System.out.println("AAALPN = " + aa);
}
- static Random rand = new Random();
-
- static int randomRange(int lower, int upper) {
- if (lower > upper)
- throw new IllegalArgumentException("lower > upper");
- int diff = upper - lower;
- int r = lower + rand.nextInt(diff);
- return r - (r % 8); // round down to multiple of 8 (align for longs)
- }
-
private void handlePublisherException(Object o, Throwable t) {
System.out.println("Src Publisher exception");
t.printStackTrace(System.out);
--- a/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/SSLTubeTest.java Wed Dec 06 12:44:05 2017 +0000
+++ b/test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/SSLTubeTest.java Wed Dec 06 14:29:06 2017 +0000
@@ -23,55 +23,30 @@
package jdk.incubator.http;
-import jdk.incubator.http.internal.common.Demand;
import jdk.incubator.http.internal.common.FlowTube;
import jdk.incubator.http.internal.common.SSLFlowDelegate;
-import jdk.incubator.http.internal.common.SSLTube;
-import jdk.incubator.http.internal.common.SequentialScheduler;
import jdk.incubator.http.internal.common.Utils;
import org.testng.annotations.Test;
-import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
-import javax.net.ssl.TrustManagerFactory;
import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
import java.util.List;
-import java.util.Queue;
-import java.util.Random;
-import java.util.StringTokenizer;
import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Flow;
-import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SubmissionPublisher;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.Consumer;
@Test
public class SSLTubeTest extends AbstractSSLTubeTest {