mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-09 23:50:22 +00:00
8378598: Refactor tests under test/jdk/java/net/httpclient/websocket from TestNG to JUnit
Reviewed-by: vyazici
This commit is contained in:
parent
a0c0a36179
commit
dfea6eb9f8
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,12 +24,11 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* Abort
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ProtocolException;
|
||||
@ -44,10 +43,12 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static java.net.http.HttpClient.newHttpClient;
|
||||
import static java.net.http.WebSocket.NORMAL_CLOSURE;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertThrows;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Abort {
|
||||
|
||||
@ -79,7 +80,7 @@ public class Abort {
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
List<MockListener.Invocation> inv = listener.invocationsSoFar();
|
||||
// no more invocations after onOpen as WebSocket was aborted
|
||||
assertEquals(inv, List.of(MockListener.Invocation.onOpen(webSocket)));
|
||||
assertEquals(List.of(MockListener.Invocation.onOpen(webSocket)), inv);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -119,7 +120,7 @@ public class Abort {
|
||||
List<MockListener.Invocation> expected = List.of(
|
||||
MockListener.Invocation.onOpen(webSocket),
|
||||
MockListener.Invocation.onText(webSocket, "", true));
|
||||
assertEquals(inv, expected);
|
||||
assertEquals(expected, inv);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -159,7 +160,7 @@ public class Abort {
|
||||
List<MockListener.Invocation> expected = List.of(
|
||||
MockListener.Invocation.onOpen(webSocket),
|
||||
MockListener.Invocation.onBinary(webSocket, ByteBuffer.allocate(0), true));
|
||||
assertEquals(inv, expected);
|
||||
assertEquals(expected, inv);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -198,7 +199,7 @@ public class Abort {
|
||||
List<MockListener.Invocation> expected = List.of(
|
||||
MockListener.Invocation.onOpen(webSocket),
|
||||
MockListener.Invocation.onPing(webSocket, ByteBuffer.allocate(0)));
|
||||
assertEquals(inv, expected);
|
||||
assertEquals(expected, inv);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -237,7 +238,7 @@ public class Abort {
|
||||
List<MockListener.Invocation> expected = List.of(
|
||||
MockListener.Invocation.onOpen(webSocket),
|
||||
MockListener.Invocation.onPong(webSocket, ByteBuffer.allocate(0)));
|
||||
assertEquals(inv, expected);
|
||||
assertEquals(expected, inv);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -277,7 +278,7 @@ public class Abort {
|
||||
List<MockListener.Invocation> expected = List.of(
|
||||
MockListener.Invocation.onOpen(webSocket),
|
||||
MockListener.Invocation.onClose(webSocket, 1005, ""));
|
||||
assertEquals(inv, expected);
|
||||
assertEquals(expected, inv);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -318,7 +319,7 @@ public class Abort {
|
||||
MockListener.Invocation.onOpen(webSocket),
|
||||
MockListener.Invocation.onError(webSocket, ProtocolException.class));
|
||||
System.out.println("actual invocations:" + Arrays.toString(inv.toArray()));
|
||||
assertEquals(inv, expected);
|
||||
assertEquals(expected, inv);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -396,7 +397,7 @@ public class Abort {
|
||||
ws.abort();
|
||||
assertTrue(ws.isInputClosed());
|
||||
assertTrue(ws.isOutputClosed());
|
||||
assertEquals(ws.getSubprotocol(), "");
|
||||
assertEquals("", ws.getSubprotocol());
|
||||
}
|
||||
// at this point valid requests MUST be a no-op:
|
||||
for (int j = 0; j < 3; j++) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,11 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* AutomaticPong
|
||||
*/
|
||||
import jdk.internal.net.http.websocket.Frame;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.http.WebSocket;
|
||||
@ -39,10 +37,14 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static java.net.http.HttpClient.newHttpClient;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class AutomaticPong {
|
||||
/*
|
||||
@ -86,7 +88,7 @@ public class AutomaticPong {
|
||||
MockListener.Invocation.onPing(webSocket, hello),
|
||||
MockListener.Invocation.onClose(webSocket, 1005, "")
|
||||
);
|
||||
assertEquals(actual, expected);
|
||||
assertEquals(expected, actual);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -104,7 +106,8 @@ public class AutomaticPong {
|
||||
* b) the last Pong corresponds to the last Ping
|
||||
* c) there are no unrelated Pongs
|
||||
*/
|
||||
@Test(dataProvider = "nPings")
|
||||
@ParameterizedTest
|
||||
@MethodSource("nPings")
|
||||
public void automaticPongs(int nPings) throws Exception {
|
||||
// big enough to not bother with resize
|
||||
ByteBuffer buffer = ByteBuffer.allocate(65536);
|
||||
@ -133,7 +136,7 @@ public class AutomaticPong {
|
||||
.join();
|
||||
try {
|
||||
List<MockListener.Invocation> inv = listener.invocations();
|
||||
assertEquals(inv.size(), nPings + 2); // n * onPing + onOpen + onClose
|
||||
assertEquals(nPings + 2, inv.size()); // n * onPing + onOpen + onClose
|
||||
|
||||
ByteBuffer data = server.read();
|
||||
Frame.Reader reader = new Frame.Reader();
|
||||
@ -171,7 +174,7 @@ public class AutomaticPong {
|
||||
closed = true;
|
||||
return;
|
||||
}
|
||||
assertEquals(value, Frame.Opcode.PONG);
|
||||
assertEquals(Frame.Opcode.PONG, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -182,7 +185,7 @@ public class AutomaticPong {
|
||||
@Override
|
||||
public void payloadLen(long value) {
|
||||
if (!closed)
|
||||
assertEquals(value, 4);
|
||||
assertEquals(4, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -222,8 +225,7 @@ public class AutomaticPong {
|
||||
}
|
||||
|
||||
|
||||
@DataProvider(name = "nPings")
|
||||
public Object[][] nPings() {
|
||||
public static Object[][] nPings() {
|
||||
return new Object[][]{{1}, {2}, {4}, {8}, {9}, {256}};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,14 +24,12 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.debug=true
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* BlowupOutputQueue
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -43,7 +41,8 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class BlowupOutputQueue extends PendingOperations {
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2026, 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
|
||||
@ -29,7 +29,7 @@
|
||||
* @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.common.TestServerConfigurator
|
||||
* @modules java.net.http/jdk.internal.net.http.common
|
||||
* jdk.httpserver
|
||||
* @run testng/othervm -Djdk.internal.httpclient.debug=true HandshakeUrlEncodingTest
|
||||
* @run junit/othervm -Djdk.internal.httpclient.debug=true HandshakeUrlEncodingTest
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
@ -39,10 +39,6 @@ import com.sun.net.httpserver.HttpExchange;
|
||||
import jdk.httpclient.test.lib.common.TestServerConfigurator;
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.IOException;
|
||||
@ -58,20 +54,25 @@ import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static java.net.http.HttpClient.Builder.NO_PROXY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.fail;
|
||||
import static java.lang.System.out;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
|
||||
public class HandshakeUrlEncodingTest {
|
||||
|
||||
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
HttpServer httpTestServer;
|
||||
HttpsServer httpsTestServer;
|
||||
String httpURI;
|
||||
String httpsURI;
|
||||
private static HttpServer httpTestServer;
|
||||
private static HttpsServer httpsTestServer;
|
||||
private static String httpURI;
|
||||
private static String httpsURI;
|
||||
|
||||
static String queryPart;
|
||||
|
||||
@ -79,8 +80,7 @@ public class HandshakeUrlEncodingTest {
|
||||
// a shared executor helps reduce the amount of threads created by the test
|
||||
static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
@DataProvider(name = "variants")
|
||||
public Object[][] variants() {
|
||||
public static Object[][] variants() {
|
||||
return new Object[][]{
|
||||
{ httpURI, false },
|
||||
{ httpsURI, false },
|
||||
@ -97,7 +97,8 @@ public class HandshakeUrlEncodingTest {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test(dataProvider = "variants")
|
||||
@ParameterizedTest
|
||||
@MethodSource("variants")
|
||||
public void test(String uri, boolean sameClient) {
|
||||
HttpClient client = null;
|
||||
out.println("The url is " + uri);
|
||||
@ -119,22 +120,21 @@ public class HandshakeUrlEncodingTest {
|
||||
final WebSocketHandshakeException wse = (WebSocketHandshakeException) t;
|
||||
assertNotNull(wse.getResponse());
|
||||
assertNotNull(wse.getResponse().uri());
|
||||
assertNotNull(wse.getResponse().statusCode());
|
||||
final String rawQuery = wse.getResponse().uri().getRawQuery();
|
||||
final String expectedRawQuery = "&raw=abc+def/ghi=xyz&encoded=abc%2Bdef%2Fghi%3Dxyz";
|
||||
assertEquals(rawQuery, expectedRawQuery);
|
||||
assertEquals(expectedRawQuery, rawQuery);
|
||||
final String body = (String) wse.getResponse().body();
|
||||
final String expectedBody = "/?" + expectedRawQuery;
|
||||
assertEquals(body, expectedBody);
|
||||
assertEquals(expectedBody, body);
|
||||
out.println("Status code is " + wse.getResponse().statusCode());
|
||||
out.println("Response is " + wse.getResponse());
|
||||
assertEquals(wse.getResponse().statusCode(), 400);
|
||||
assertEquals(400, wse.getResponse().statusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
public void setup() throws Exception {
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
|
||||
queryPart = "?&raw=abc+def/ghi=xyz&encoded=abc%2Bdef%2Fghi%3Dxyz";
|
||||
httpTestServer = HttpServer.create(sa, 10);
|
||||
@ -164,8 +164,8 @@ public class HandshakeUrlEncodingTest {
|
||||
httpsTestServer.start();
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void teardown() {
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
httpTestServer.stop(0);
|
||||
httpsTestServer.stop(0);
|
||||
executor.shutdownNow();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, 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
|
||||
@ -25,7 +25,7 @@
|
||||
* @test
|
||||
* @bug 8159053
|
||||
* @modules java.net.http/jdk.internal.net.http.websocket:open
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* --add-reads java.net.http=ALL-UNNAMED
|
||||
* java.net.http/jdk.internal.net.http.websocket.HeaderWriterTest
|
||||
*/
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, 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
|
||||
@ -25,7 +25,7 @@
|
||||
* @test
|
||||
* @bug 8159053
|
||||
* @modules java.net.http/jdk.internal.net.http.websocket:open
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* --add-reads java.net.http=ALL-UNNAMED
|
||||
* java.net.http/jdk.internal.net.http.websocket.MaskerTest
|
||||
*/
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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
|
||||
@ -25,7 +25,7 @@
|
||||
* @test
|
||||
* @bug 8159053
|
||||
* @modules java.net.http/jdk.internal.net.http.websocket:open
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* --add-reads java.net.http=ALL-UNNAMED
|
||||
* java.net.http/jdk.internal.net.http.websocket.MessageQueueTest
|
||||
*/
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,28 +24,30 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* -Djdk.internal.httpclient.debug=true
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* PendingBinaryPingClose
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingBinaryPingClose extends PendingOperations {
|
||||
|
||||
CompletableFuture<WebSocket> cfBinary;
|
||||
CompletableFuture<WebSocket> cfPing;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingBinaryPingClose(boolean last) throws Exception {
|
||||
repeatable(() -> {
|
||||
server = Support.notReadingServer();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,28 +24,30 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* -Djdk.internal.httpclient.debug=true
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* PendingBinaryPongClose
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingBinaryPongClose extends PendingOperations {
|
||||
|
||||
CompletableFuture<WebSocket> cfBinary;
|
||||
CompletableFuture<WebSocket> cfPong;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingBinaryPongClose(boolean last) throws Exception {
|
||||
repeatable(() -> {
|
||||
server = Support.notReadingServer();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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
|
||||
@ -21,9 +21,6 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.WebSocket;
|
||||
@ -35,6 +32,8 @@ import java.util.function.BooleanSupplier;
|
||||
import static java.net.http.HttpClient.Builder.NO_PROXY;
|
||||
import static java.net.http.HttpClient.newBuilder;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
/* Common infrastructure for tests that check pending operations */
|
||||
public class PendingOperations {
|
||||
|
||||
@ -54,7 +53,7 @@ public class PendingOperations {
|
||||
return newBuilder().proxy(NO_PROXY).build();
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
@AfterEach
|
||||
public void cleanup() {
|
||||
// make sure we have a trace both on System.out and System.err
|
||||
// to help with diagnosis.
|
||||
@ -85,8 +84,7 @@ public class PendingOperations {
|
||||
Support.assertNotDone(future);
|
||||
}
|
||||
|
||||
@DataProvider(name = "booleans")
|
||||
public Object[][] booleans() {
|
||||
public static Object[][] booleans() {
|
||||
return new Object[][]{{Boolean.TRUE}, {Boolean.FALSE}};
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* PendingPingBinaryClose
|
||||
*/
|
||||
@ -33,21 +33,23 @@
|
||||
// * -Djdk.internal.httpclient.debug=true
|
||||
// * -Djdk.internal.httpclient.websocket.debug=true
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingPingBinaryClose extends PendingOperations {
|
||||
|
||||
CompletableFuture<WebSocket> cfBinary;
|
||||
CompletableFuture<WebSocket> cfPing;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingPingBinaryClose(boolean last) throws Exception {
|
||||
repeatable( () -> {
|
||||
server = Support.notReadingServer();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* PendingPingTextClose
|
||||
*/
|
||||
@ -33,14 +33,15 @@
|
||||
// * -Djdk.internal.httpclient.debug=true
|
||||
// * -Djdk.internal.httpclient.websocket.debug=true
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingPingTextClose extends PendingOperations {
|
||||
|
||||
static boolean debug = false; // avoid too verbose output
|
||||
@ -48,7 +49,8 @@ public class PendingPingTextClose extends PendingOperations {
|
||||
CompletableFuture<WebSocket> cfPing;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingPingTextClose(boolean last) throws Exception {
|
||||
try {
|
||||
repeatable(() -> {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* PendingPongBinaryClose
|
||||
*/
|
||||
@ -33,21 +33,23 @@
|
||||
// * -Djdk.internal.httpclient.debug=true
|
||||
// * -Djdk.internal.httpclient.websocket.debug=true
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingPongBinaryClose extends PendingOperations {
|
||||
|
||||
CompletableFuture<WebSocket> cfBinary;
|
||||
CompletableFuture<WebSocket> cfPong;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingPongBinaryClose(boolean last) throws Exception {
|
||||
repeatable( () -> {
|
||||
server = Support.notReadingServer();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* PendingPongTextClose
|
||||
*/
|
||||
@ -33,21 +33,23 @@
|
||||
// * -Djdk.internal.httpclient.debug=true
|
||||
// * -Djdk.internal.httpclient.websocket.debug=true
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingPongTextClose extends PendingOperations {
|
||||
|
||||
CompletableFuture<WebSocket> cfText;
|
||||
CompletableFuture<WebSocket> cfPong;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingPongTextClose(boolean last) throws Exception {
|
||||
repeatable( () -> {
|
||||
server = Support.notReadingServer();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,15 +24,13 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.debug=true
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* PendingTextPingClose
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
@ -40,13 +38,17 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingTextPingClose extends PendingOperations {
|
||||
|
||||
CompletableFuture<WebSocket> cfText;
|
||||
CompletableFuture<WebSocket> cfPing;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingTextPingClose(boolean last) throws Exception {
|
||||
repeatable(() -> {
|
||||
server = Support.notReadingServer();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,15 +24,13 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.debug=true
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* -Djdk.httpclient.sendBufferSize=8192
|
||||
* PendingTextPongClose
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
@ -40,13 +38,17 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class PendingTextPongClose extends PendingOperations {
|
||||
|
||||
CompletableFuture<WebSocket> cfText;
|
||||
CompletableFuture<WebSocket> cfPong;
|
||||
CompletableFuture<WebSocket> cfClose;
|
||||
|
||||
@Test(dataProvider = "booleans")
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleans")
|
||||
public void pendingTextPongClose(boolean last) throws Exception {
|
||||
repeatable(() -> {
|
||||
server = Support.notReadingServer();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, 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
|
||||
@ -25,6 +25,8 @@
|
||||
* @test
|
||||
* @bug 8159053
|
||||
* @modules java.net.http/jdk.internal.net.http.websocket:open
|
||||
* @run testng/othervm/timeout=240 --add-reads java.net.http=ALL-UNNAMED java.net.http/jdk.internal.net.http.websocket.ReaderTest
|
||||
* @run junit/othervm/timeout=240
|
||||
* --add-reads java.net.http=ALL-UNNAMED
|
||||
* java.net.http/jdk.internal.net.http.websocket.ReaderTest
|
||||
*/
|
||||
public final class ReaderDriver { }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2026, 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
|
||||
@ -22,18 +22,9 @@
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.testng.Assert.assertThrows;
|
||||
|
||||
/**
|
||||
* Helper class to create instances of DummySecureWebSocketServer which
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,22 +24,22 @@
|
||||
/*
|
||||
* @test
|
||||
* @build DummyWebSocketServer
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* SendTest
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.http.WebSocket;
|
||||
|
||||
import static java.net.http.HttpClient.Builder.NO_PROXY;
|
||||
import static java.net.http.HttpClient.newBuilder;
|
||||
import static java.net.http.WebSocket.NORMAL_CLOSURE;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertThrows;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class SendTest {
|
||||
|
||||
@ -90,7 +90,7 @@ public class SendTest {
|
||||
try {
|
||||
webSocket.sendClose(NORMAL_CLOSURE, "").join();
|
||||
assertTrue(webSocket.isOutputClosed());
|
||||
assertEquals(webSocket.getSubprotocol(), "");
|
||||
assertEquals("", webSocket.getSubprotocol());
|
||||
webSocket.request(1); // No exceptions must be thrown
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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
|
||||
@ -32,8 +32,8 @@ import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.testng.Assert.assertThrows;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class Support {
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2026, 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
|
||||
@ -29,7 +29,7 @@
|
||||
* @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.common.TestServerConfigurator
|
||||
* @modules java.net.http/jdk.internal.net.http.common
|
||||
* jdk.httpserver
|
||||
* @run testng/othervm -Djdk.internal.httpclient.debug=true WSHandshakeExceptionTest
|
||||
* @run junit/othervm -Djdk.internal.httpclient.debug=true WSHandshakeExceptionTest
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
@ -37,8 +37,6 @@ import com.sun.net.httpserver.HttpServer;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -49,10 +47,6 @@ import java.net.http.WebSocketHandshakeException;
|
||||
|
||||
import jdk.httpclient.test.lib.common.TestServerConfigurator;
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
@ -62,29 +56,33 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static java.net.http.HttpClient.Builder.NO_PROXY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
import static java.lang.System.out;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class WSHandshakeExceptionTest {
|
||||
|
||||
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
HttpServer httpTestServer; // HTTP/1.1 [ 2 servers ]
|
||||
HttpsServer httpsTestServer; // HTTPS/1.1
|
||||
String httpURI;
|
||||
String httpsURI;
|
||||
String httpNonUtf8URI;
|
||||
String httpsNonUtf8URI;
|
||||
HttpClient sharedClient;
|
||||
private static HttpServer httpTestServer; // HTTP/1.1 [ 2 servers ]
|
||||
private static HttpsServer httpsTestServer; // HTTPS/1.1
|
||||
private static String httpURI;
|
||||
private static String httpsURI;
|
||||
private static String httpNonUtf8URI;
|
||||
private static String httpsNonUtf8URI;
|
||||
private static HttpClient sharedClient;
|
||||
|
||||
static final int ITERATION_COUNT = 4;
|
||||
// a shared executor helps reduce the amount of threads created by the test
|
||||
static final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
@DataProvider(name = "variants")
|
||||
public Object[][] variants() {
|
||||
public static Object[][] variants() {
|
||||
return new Object[][]{
|
||||
{ httpURI, false },
|
||||
{ httpsURI, false },
|
||||
@ -106,7 +104,8 @@ public class WSHandshakeExceptionTest {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test(dataProvider = "variants")
|
||||
@ParameterizedTest
|
||||
@MethodSource("variants")
|
||||
public void test(String uri, boolean sameClient) {
|
||||
HttpClient client = sharedClient;
|
||||
boolean pause;
|
||||
@ -132,7 +131,7 @@ public class WSHandshakeExceptionTest {
|
||||
WebSocketHandshakeException wse = (WebSocketHandshakeException) t;
|
||||
assertNotNull(wse.getResponse());
|
||||
assertNotNull(wse.getResponse().body());
|
||||
assertEquals(wse.getResponse().body().getClass(), String.class);
|
||||
assertEquals(String.class, wse.getResponse().body().getClass());
|
||||
String body = (String)wse.getResponse().body();
|
||||
out.println("Status code is " + wse.getResponse().statusCode());
|
||||
out.println("Response is " + body);
|
||||
@ -145,7 +144,7 @@ public class WSHandshakeExceptionTest {
|
||||
// default HttpServer 404 body expected
|
||||
assertTrue(body.contains("404"));
|
||||
}
|
||||
assertEquals(wse.getResponse().statusCode(), 404);
|
||||
assertEquals(404, wse.getResponse().statusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,8 +158,8 @@ public class WSHandshakeExceptionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
public void setup() throws Exception {
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
// HTTP/1.1
|
||||
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
|
||||
httpTestServer = HttpServer.create(sa, 0);
|
||||
@ -178,8 +177,8 @@ public class WSHandshakeExceptionTest {
|
||||
httpsTestServer.start();
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void teardown() {
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
sharedClient = null;
|
||||
gc(100);
|
||||
httpTestServer.stop(0);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, 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
|
||||
@ -26,12 +26,9 @@
|
||||
* @bug 8159053
|
||||
* @build DummyWebSocketServer
|
||||
* Support
|
||||
* @run testng/othervm WebSocketBuilderTest
|
||||
* @run junit/othervm WebSocketBuilderTest
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.WebSocket;
|
||||
@ -42,7 +39,10 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.testng.Assert.assertThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/*
|
||||
* In some places in this test a new String is created out of a string literal.
|
||||
@ -98,7 +98,8 @@ public final class WebSocketBuilderTest {
|
||||
.connectTimeout(null));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "badURIs")
|
||||
@ParameterizedTest
|
||||
@MethodSource("badURIs")
|
||||
void illegalURI(URI uri) {
|
||||
WebSocket.Builder b = HttpClient.newHttpClient().newWebSocketBuilder();
|
||||
assertFails(IllegalArgumentException.class,
|
||||
@ -129,7 +130,8 @@ public final class WebSocketBuilderTest {
|
||||
// TODO: test for bad syntax headers
|
||||
// TODO: test for overwrites (subprotocols) and additions (headers)
|
||||
|
||||
@Test(dataProvider = "badSubprotocols")
|
||||
@ParameterizedTest
|
||||
@MethodSource("badSubprotocols")
|
||||
public void illegalSubprotocolsSyntax(String s) {
|
||||
WebSocket.Builder b = HttpClient.newHttpClient()
|
||||
.newWebSocketBuilder()
|
||||
@ -138,7 +140,8 @@ public final class WebSocketBuilderTest {
|
||||
b.buildAsync(VALID_URI, listener()));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "duplicatingSubprotocols")
|
||||
@ParameterizedTest
|
||||
@MethodSource("duplicatingSubprotocols")
|
||||
public void illegalSubprotocolsDuplicates(String mostPreferred,
|
||||
String[] lesserPreferred) {
|
||||
WebSocket.Builder b = HttpClient.newHttpClient()
|
||||
@ -148,7 +151,8 @@ public final class WebSocketBuilderTest {
|
||||
b.buildAsync(VALID_URI, listener()));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "badConnectTimeouts")
|
||||
@ParameterizedTest
|
||||
@MethodSource("badConnectTimeouts")
|
||||
public void illegalConnectTimeout(Duration d) {
|
||||
WebSocket.Builder b = HttpClient.newHttpClient()
|
||||
.newWebSocketBuilder()
|
||||
@ -157,8 +161,7 @@ public final class WebSocketBuilderTest {
|
||||
b.buildAsync(VALID_URI, listener()));
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] badURIs() {
|
||||
public static Object[][] badURIs() {
|
||||
return new Object[][]{
|
||||
{URI.create("http://example.com")},
|
||||
{URI.create("ftp://example.com")},
|
||||
@ -167,8 +170,7 @@ public final class WebSocketBuilderTest {
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] badConnectTimeouts() {
|
||||
public static Object[][] badConnectTimeouts() {
|
||||
return new Object[][]{
|
||||
{Duration.ofDays(0)},
|
||||
{Duration.ofDays(-1)},
|
||||
@ -188,7 +190,6 @@ public final class WebSocketBuilderTest {
|
||||
|
||||
// https://tools.ietf.org/html/rfc7230#section-3.2.6
|
||||
// https://tools.ietf.org/html/rfc20
|
||||
@DataProvider
|
||||
public static Object[][] badSubprotocols() {
|
||||
return new Object[][]{
|
||||
{""},
|
||||
@ -215,7 +216,6 @@ public final class WebSocketBuilderTest {
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public static Object[][] duplicatingSubprotocols() {
|
||||
return new Object[][]{
|
||||
{"a.b.c", new String[]{"a.b.c"}},
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @bug 8159053
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* -Djdk.internal.httpclient.debug=true
|
||||
* -Djdk.httpclient.websocket.writeBufferSize=1024
|
||||
@ -32,8 +32,6 @@
|
||||
*/
|
||||
|
||||
import jdk.internal.net.http.websocket.Frame;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.http.WebSocket;
|
||||
@ -43,8 +41,11 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import static java.net.http.HttpClient.Builder.NO_PROXY;
|
||||
import static java.net.http.HttpClient.newBuilder;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
/*
|
||||
@ -52,7 +53,7 @@ import static org.testng.Assert.assertTrue;
|
||||
* possible fragmentation.
|
||||
*/
|
||||
public class WebSocketExtendedTest {
|
||||
// * run testng/othervm
|
||||
// * run junit/othervm
|
||||
// * -Djdk.httpclient.websocket.writeBufferSize=16
|
||||
// * -Djdk.httpclient.sendBufferSize=32 WebSocketTextTest
|
||||
|
||||
@ -65,7 +66,8 @@ public class WebSocketExtendedTest {
|
||||
|
||||
// FIXME ensure subsequent (sendText/Binary, false) only CONTINUATIONs
|
||||
|
||||
@Test(dataProvider = "binary")
|
||||
@ParameterizedTest
|
||||
@MethodSource("binary")
|
||||
public void binary(ByteBuffer expected) throws IOException, InterruptedException {
|
||||
try (DummyWebSocketServer server = new DummyWebSocketServer()) {
|
||||
server.open();
|
||||
@ -76,15 +78,16 @@ public class WebSocketExtendedTest {
|
||||
ws.sendBinary(expected.duplicate(), true).join();
|
||||
ws.abort();
|
||||
List<DummyWebSocketServer.DecodedFrame> frames = server.readFrames();
|
||||
assertEquals(frames.size(), 1);
|
||||
assertEquals(1, frames.size());
|
||||
DummyWebSocketServer.DecodedFrame f = frames.get(0);
|
||||
assertTrue(f.last());
|
||||
assertEquals(f.opcode(), Frame.Opcode.BINARY);
|
||||
assertEquals(f.data(), expected);
|
||||
assertEquals(Frame.Opcode.BINARY, f.opcode());
|
||||
assertEquals(expected, f.data());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "pingPong")
|
||||
@ParameterizedTest
|
||||
@MethodSource("pingPongSizes")
|
||||
public void ping(ByteBuffer expected) throws Exception {
|
||||
try (DummyWebSocketServer server = new DummyWebSocketServer()) {
|
||||
server.open();
|
||||
@ -95,17 +98,18 @@ public class WebSocketExtendedTest {
|
||||
ws.sendPing(expected.duplicate()).join();
|
||||
ws.abort();
|
||||
List<DummyWebSocketServer.DecodedFrame> frames = server.readFrames();
|
||||
assertEquals(frames.size(), 1);
|
||||
assertEquals(1, frames.size());
|
||||
DummyWebSocketServer.DecodedFrame f = frames.get(0);
|
||||
assertEquals(f.opcode(), Frame.Opcode.PING);
|
||||
assertEquals(Frame.Opcode.PING, f.opcode());
|
||||
ByteBuffer actual = ByteBuffer.allocate(expected.remaining());
|
||||
actual.put(f.data());
|
||||
actual.flip();
|
||||
assertEquals(actual, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "pingPong")
|
||||
@ParameterizedTest
|
||||
@MethodSource("pingPongSizes")
|
||||
public void pong(ByteBuffer expected) throws Exception {
|
||||
try (DummyWebSocketServer server = new DummyWebSocketServer()) {
|
||||
server.open();
|
||||
@ -116,17 +120,18 @@ public class WebSocketExtendedTest {
|
||||
ws.sendPong(expected.duplicate()).join();
|
||||
ws.abort();
|
||||
List<DummyWebSocketServer.DecodedFrame> frames = server.readFrames();
|
||||
assertEquals(frames.size(), 1);
|
||||
assertEquals(1, frames.size());
|
||||
DummyWebSocketServer.DecodedFrame f = frames.get(0);
|
||||
assertEquals(f.opcode(), Frame.Opcode.PONG);
|
||||
assertEquals(Frame.Opcode.PONG, f.opcode());
|
||||
ByteBuffer actual = ByteBuffer.allocate(expected.remaining());
|
||||
actual.put(f.data());
|
||||
actual.flip();
|
||||
assertEquals(actual, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "close")
|
||||
@ParameterizedTest
|
||||
@MethodSource("closeArguments")
|
||||
public void close(int statusCode, String reason) throws Exception {
|
||||
try (DummyWebSocketServer server = new DummyWebSocketServer()) {
|
||||
server.open();
|
||||
@ -137,18 +142,19 @@ public class WebSocketExtendedTest {
|
||||
ws.sendClose(statusCode, reason).join();
|
||||
ws.abort();
|
||||
List<DummyWebSocketServer.DecodedFrame> frames = server.readFrames();
|
||||
assertEquals(frames.size(), 1);
|
||||
assertEquals(1, frames.size());
|
||||
DummyWebSocketServer.DecodedFrame f = frames.get(0);
|
||||
assertEquals(f.opcode(), Frame.Opcode.CLOSE);
|
||||
assertEquals(Frame.Opcode.CLOSE, f.opcode());
|
||||
ByteBuffer actual = ByteBuffer.allocate(Frame.MAX_CONTROL_FRAME_PAYLOAD_LENGTH);
|
||||
actual.put(f.data());
|
||||
actual.flip();
|
||||
assertEquals(actual.getChar(), statusCode);
|
||||
assertEquals(StandardCharsets.UTF_8.decode(actual).toString(), reason);
|
||||
assertEquals(statusCode, actual.getChar());
|
||||
assertEquals(reason, StandardCharsets.UTF_8.decode(actual).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "text")
|
||||
@ParameterizedTest
|
||||
@MethodSource("texts")
|
||||
public void text(String expected) throws Exception {
|
||||
try (DummyWebSocketServer server = new DummyWebSocketServer()) {
|
||||
server.open();
|
||||
@ -163,12 +169,11 @@ public class WebSocketExtendedTest {
|
||||
ByteBuffer actual = ByteBuffer.allocate(maxBytes);
|
||||
frames.stream().forEachOrdered(f -> actual.put(f.data()));
|
||||
actual.flip();
|
||||
assertEquals(StandardCharsets.UTF_8.decode(actual).toString(), expected);
|
||||
assertEquals(expected, StandardCharsets.UTF_8.decode(actual).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name = "pingPong")
|
||||
public Object[][] pingPongSizes() {
|
||||
public static Object[][] pingPongSizes() {
|
||||
return new Object[][]{
|
||||
{bytes( 0)},
|
||||
{bytes( 1)},
|
||||
@ -177,8 +182,7 @@ public class WebSocketExtendedTest {
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name = "close")
|
||||
public Object[][] closeArguments() {
|
||||
public static Object[][] closeArguments() {
|
||||
return new Object[][]{
|
||||
{WebSocket.NORMAL_CLOSURE, utf8String( 0)},
|
||||
{WebSocket.NORMAL_CLOSURE, utf8String( 1)},
|
||||
@ -216,16 +220,14 @@ public class WebSocketExtendedTest {
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
@DataProvider(name = "text")
|
||||
public Object[][] texts() {
|
||||
public static Object[][] texts() {
|
||||
return new Object[][]{
|
||||
{utf8String( 0)},
|
||||
{utf8String(1024)},
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name = "binary")
|
||||
public Object[][] binary() {
|
||||
public static Object[][] binary() {
|
||||
return new Object[][]{
|
||||
{bytes( 0)},
|
||||
{bytes(1024)},
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2026, 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
|
||||
@ -28,7 +28,7 @@
|
||||
* @library /test/lib
|
||||
* @compile SecureSupport.java DummySecureWebSocketServer.java ../ProxyServer.java
|
||||
* @build jdk.test.lib.net.SimpleSSLContext WebSocketProxyTest
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* -Djdk.internal.httpclient.debug=true
|
||||
* -Djdk.internal.httpclient.websocket.debug=true
|
||||
* -Djdk.httpclient.HttpClient.log=errors,requests,headers
|
||||
@ -61,16 +61,18 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import static java.net.http.HttpClient.newBuilder;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.FileAssert.fail;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class WebSocketProxyTest {
|
||||
|
||||
@ -132,8 +134,7 @@ public class WebSocketProxyTest {
|
||||
@Override public String toString() { return "AUTH_TUNNELING_PROXY_SERVER"; }
|
||||
};
|
||||
|
||||
@DataProvider(name = "servers")
|
||||
public Object[][] servers() {
|
||||
public static Object[][] servers() {
|
||||
return new Object[][] {
|
||||
{ SERVER_WITH_CANNED_DATA, TUNNELING_PROXY_SERVER },
|
||||
{ SERVER_WITH_CANNED_DATA, AUTH_TUNNELING_PROXY_SERVER },
|
||||
@ -175,7 +176,8 @@ public class WebSocketProxyTest {
|
||||
return "%s and %s %s".formatted(actual, expected, message);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "servers")
|
||||
@ParameterizedTest
|
||||
@MethodSource("servers")
|
||||
public void simpleAggregatingBinaryMessages
|
||||
(Function<int[],DummySecureWebSocketServer> serverSupplier,
|
||||
Supplier<ProxyServer> proxyServerSupplier)
|
||||
@ -263,7 +265,7 @@ public class WebSocketProxyTest {
|
||||
.join();
|
||||
|
||||
List<byte[]> a = actual.join();
|
||||
assertEquals(ofBytes(a), ofBytes(expected), diagnose(a, expected));
|
||||
assertEquals(ofBytes(expected), ofBytes(a), diagnose(a, expected));
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,7 +361,7 @@ public class WebSocketProxyTest {
|
||||
} catch (CompletionException expected) {
|
||||
WebSocketHandshakeException e = (WebSocketHandshakeException)expected.getCause();
|
||||
HttpResponse<?> response = e.getResponse();
|
||||
assertEquals(response.statusCode(), 407);
|
||||
assertEquals(407, response.statusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -398,7 +400,7 @@ public class WebSocketProxyTest {
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
@BeforeEach
|
||||
public void breakBetweenTests() {
|
||||
System.gc();
|
||||
try {Thread.sleep(100); } catch (InterruptedException x) { /* OK */ }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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
|
||||
@ -27,12 +27,10 @@
|
||||
* @library ../access
|
||||
* @build DummyWebSocketServer
|
||||
* java.net.http/jdk.internal.net.http.HttpClientTimerAccess
|
||||
* @run testng/othervm
|
||||
* @run junit/othervm
|
||||
* WebSocketTest
|
||||
*/
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Authenticator;
|
||||
@ -63,9 +61,13 @@ import static java.net.http.HttpClient.newBuilder;
|
||||
import static java.net.http.WebSocket.NORMAL_CLOSURE;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static jdk.internal.net.http.HttpClientTimerAccess.assertNoResponseTimerEventRegistrations;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertThrows;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class WebSocketTest {
|
||||
|
||||
@ -264,8 +266,7 @@ public class WebSocketTest {
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name = "sequence")
|
||||
public Object[][] data1() {
|
||||
public static Object[][] data1() {
|
||||
int[] CLOSE = {
|
||||
0x81, 0x00, // ""
|
||||
0x82, 0x00, // []
|
||||
@ -292,7 +293,8 @@ public class WebSocketTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "sequence")
|
||||
@ParameterizedTest
|
||||
@MethodSource("data1")
|
||||
public void listenerSequentialOrder(int[] binary, long requestSize)
|
||||
throws IOException
|
||||
{
|
||||
@ -470,8 +472,7 @@ public class WebSocketTest {
|
||||
@Override public String toString() { return "AUTH_SERVER_WITH_CANNED_DATA"; }
|
||||
};
|
||||
|
||||
@DataProvider(name = "servers")
|
||||
public Object[][] servers() {
|
||||
public static Object[][] servers() {
|
||||
return new Object[][] {
|
||||
{ SERVER_WITH_CANNED_DATA },
|
||||
{ AUTH_SERVER_WITH_CANNED_DATA },
|
||||
@ -507,7 +508,8 @@ public class WebSocketTest {
|
||||
return "%s and %s %s".formatted(actual, expected, message);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "servers")
|
||||
@ParameterizedTest
|
||||
@MethodSource("servers")
|
||||
public void simpleAggregatingBinaryMessages
|
||||
(Function<int[],DummyWebSocketServer> serverSupplier)
|
||||
throws IOException
|
||||
@ -600,14 +602,15 @@ public class WebSocketTest {
|
||||
.join();
|
||||
try {
|
||||
List<byte[]> a = actual.join();
|
||||
assertEquals(ofBytes(a), ofBytes(expected), diagnose(a, expected));
|
||||
assertEquals(ofBytes(expected), ofBytes(a), diagnose(a, expected));
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "servers")
|
||||
@ParameterizedTest
|
||||
@MethodSource("servers")
|
||||
public void simpleAggregatingTextMessages
|
||||
(Function<int[],DummyWebSocketServer> serverSupplier)
|
||||
throws IOException
|
||||
@ -683,7 +686,7 @@ public class WebSocketTest {
|
||||
.join();
|
||||
try {
|
||||
List<String> a = actual.join();
|
||||
assertEquals(a, expected);
|
||||
assertEquals(expected, a);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -694,7 +697,8 @@ public class WebSocketTest {
|
||||
* Exercises the scenario where requests for more messages are made prior to
|
||||
* completing the returned CompletionStage instances.
|
||||
*/
|
||||
@Test(dataProvider = "servers")
|
||||
@ParameterizedTest
|
||||
@MethodSource("servers")
|
||||
public void aggregatingTextMessages
|
||||
(Function<int[],DummyWebSocketServer> serverSupplier)
|
||||
throws IOException
|
||||
@ -784,7 +788,7 @@ public class WebSocketTest {
|
||||
.join();
|
||||
try {
|
||||
List<String> a = actual.join();
|
||||
assertEquals(a, expected);
|
||||
assertEquals(expected, a);
|
||||
} finally {
|
||||
webSocket.abort();
|
||||
}
|
||||
@ -853,7 +857,7 @@ public class WebSocketTest {
|
||||
} catch (CompletionException expected) {
|
||||
WebSocketHandshakeException e = (WebSocketHandshakeException)expected.getCause();
|
||||
HttpResponse<?> response = e.getResponse();
|
||||
assertEquals(response.statusCode(), 401);
|
||||
assertEquals(401, response.statusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, 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
|
||||
@ -23,7 +23,6 @@
|
||||
|
||||
package jdk.internal.net.http.websocket;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import jdk.internal.net.http.websocket.Frame.HeaderWriter;
|
||||
import jdk.internal.net.http.websocket.Frame.Opcode;
|
||||
|
||||
@ -32,10 +31,12 @@ import java.util.OptionalInt;
|
||||
|
||||
import static java.util.OptionalInt.empty;
|
||||
import static java.util.OptionalInt.of;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static jdk.internal.net.http.websocket.TestSupport.assertThrows;
|
||||
import static jdk.internal.net.http.websocket.TestSupport.forEachPermutation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HeaderWriterTest {
|
||||
|
||||
private long cases, frames;
|
||||
@ -109,7 +110,7 @@ public class HeaderWriterTest {
|
||||
ByteBuffer actual = ByteBuffer.allocate(Frame.MAX_HEADER_SIZE_BYTES + 2);
|
||||
writer.write(actual);
|
||||
actual.flip();
|
||||
assertEquals(actual, expected);
|
||||
assertEquals(expected, actual);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, 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
|
||||
@ -23,17 +23,17 @@
|
||||
|
||||
package jdk.internal.net.http.websocket;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static jdk.internal.net.http.websocket.Frame.Masker.applyMask;
|
||||
import static jdk.internal.net.http.websocket.TestSupport.forEachBufferPartition;
|
||||
import static jdk.internal.net.http.websocket.TestSupport.fullCopy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class MaskerTest {
|
||||
|
||||
private static final SecureRandom random = new SecureRandom();
|
||||
@ -98,14 +98,14 @@ public class MaskerTest {
|
||||
int dstRemaining = dstCopy.remaining();
|
||||
int masked = Math.min(srcRemaining, dstRemaining);
|
||||
// 1. position check
|
||||
assertEquals(src.position(), srcCopy.position() + masked);
|
||||
assertEquals(dst.position(), dstCopy.position() + masked);
|
||||
assertEquals(srcCopy.position() + masked, src.position());
|
||||
assertEquals(dstCopy.position() + masked, dst.position());
|
||||
// 2. masking check
|
||||
src.position(srcCopy.position());
|
||||
dst.position(dstCopy.position());
|
||||
for (; src.hasRemaining() && dst.hasRemaining();
|
||||
offset = (offset + 1) & 3) {
|
||||
assertEquals(dst.get(), src.get() ^ maskBytes[offset]);
|
||||
assertEquals(src.get() ^ maskBytes[offset], dst.get());
|
||||
}
|
||||
// 3. corruption check
|
||||
// 3.1 src contents haven't changed
|
||||
@ -113,7 +113,7 @@ public class MaskerTest {
|
||||
int srcLimit = src.limit();
|
||||
src.clear();
|
||||
srcCopy.clear();
|
||||
assertEquals(src, srcCopy);
|
||||
assertEquals(srcCopy, src);
|
||||
src.limit(srcLimit).position(srcPosition); // restore src
|
||||
// 3.2 dst leading and trailing regions' contents haven't changed
|
||||
int dstPosition = dst.position();
|
||||
@ -122,11 +122,11 @@ public class MaskerTest {
|
||||
// leading
|
||||
dst.position(0).limit(dstInitialPosition);
|
||||
dstCopy.position(0).limit(dstInitialPosition);
|
||||
assertEquals(dst, dstCopy);
|
||||
assertEquals(dstCopy, dst);
|
||||
// trailing
|
||||
dst.limit(dst.capacity()).position(dstLimit);
|
||||
dstCopy.limit(dst.capacity()).position(dstLimit);
|
||||
assertEquals(dst, dstCopy);
|
||||
assertEquals(dstCopy, dst);
|
||||
// restore dst
|
||||
dst.position(dstPosition).limit(dstLimit);
|
||||
return offset;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, 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
|
||||
@ -23,9 +23,6 @@
|
||||
|
||||
package jdk.internal.net.http.websocket;
|
||||
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
@ -46,10 +43,14 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static jdk.internal.net.http.websocket.MessageQueue.effectiveCapacityOf;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertThrows;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/*
|
||||
* A unit test for MessageQueue. The test is aware of the details of the queue
|
||||
@ -59,7 +60,6 @@ public class MessageQueueTest {
|
||||
|
||||
private static final Random r = new SecureRandom();
|
||||
|
||||
@DataProvider(name = "illegalCapacities")
|
||||
public static Object[][] illegalCapacities() {
|
||||
return new Object[][]{
|
||||
new Object[]{Integer.MIN_VALUE},
|
||||
@ -69,17 +69,20 @@ public class MessageQueueTest {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "illegalCapacities")
|
||||
@ParameterizedTest
|
||||
@MethodSource("illegalCapacities")
|
||||
public void illegalCapacity(int n) {
|
||||
assertThrows(IllegalArgumentException.class, () -> new MessageQueue(n));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "capacities")
|
||||
@ParameterizedTest
|
||||
@MethodSource("capacities")
|
||||
public void emptiness(int n) {
|
||||
assertTrue(new MessageQueue(n).isEmpty());
|
||||
}
|
||||
|
||||
@Test(dataProvider = "capacities")
|
||||
@ParameterizedTest
|
||||
@MethodSource("capacities")
|
||||
public void fullness(int n) throws IOException {
|
||||
MessageQueue q = new MessageQueue(n);
|
||||
int cap = effectiveCapacityOf(n);
|
||||
@ -97,7 +100,7 @@ public class MessageQueueTest {
|
||||
for (int i = 0; i < cap; i++) {
|
||||
Message expected = referenceQueue.remove();
|
||||
Message actual = new Remover().removeFrom(q);
|
||||
assertEquals(actual, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +147,8 @@ public class MessageQueueTest {
|
||||
action, future);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "capacities")
|
||||
@ParameterizedTest
|
||||
@MethodSource("capacities")
|
||||
public void caterpillarWalk(int n) throws IOException {
|
||||
// System.out.println("n: " + n);
|
||||
int cap = effectiveCapacityOf(n);
|
||||
@ -164,7 +168,7 @@ public class MessageQueueTest {
|
||||
for (int i = 0; i < p; i++) {
|
||||
Message expected = referenceQueue.remove();
|
||||
Message actual = remover.removeFrom(q);
|
||||
assertEquals(actual, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
@ -243,7 +247,7 @@ public class MessageQueueTest {
|
||||
f.get(); // Just to check for exceptions
|
||||
}
|
||||
consumer.get(); // Waiting for consumer to collect all the messages
|
||||
assertEquals(actualList.size(), expectedList.size());
|
||||
assertEquals(expectedList.size(), actualList.size());
|
||||
for (Message m : expectedList) {
|
||||
assertTrue(actualList.remove(m));
|
||||
}
|
||||
@ -257,7 +261,8 @@ public class MessageQueueTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "capacities")
|
||||
@ParameterizedTest
|
||||
@MethodSource("capacities")
|
||||
public void testSingleThreaded(int n) throws IOException {
|
||||
Queue<Message> referenceQueue = new LinkedList<>();
|
||||
MessageQueue q = new MessageQueue(n);
|
||||
@ -271,13 +276,12 @@ public class MessageQueueTest {
|
||||
for (int i = 0; i < cap; i++) {
|
||||
Message expected = referenceQueue.remove();
|
||||
Message actual = new Remover().removeFrom(q);
|
||||
assertEquals(actual, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
@DataProvider(name = "capacities")
|
||||
public Object[][] capacities() {
|
||||
public static Object[][] capacities() {
|
||||
return new Object[][]{
|
||||
new Object[]{ 1},
|
||||
new Object[]{ 2},
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2026, 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
|
||||
@ -23,7 +23,6 @@
|
||||
|
||||
package jdk.internal.net.http.websocket;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import jdk.internal.net.http.websocket.Frame.Opcode;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@ -35,10 +34,12 @@ import java.util.function.IntUnaryOperator;
|
||||
|
||||
import static java.util.OptionalInt.empty;
|
||||
import static java.util.OptionalInt.of;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static jdk.internal.net.http.websocket.TestSupport.assertThrows;
|
||||
import static jdk.internal.net.http.websocket.TestSupport.forEachBufferPartition;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ReaderTest {
|
||||
|
||||
private long cases, frames;
|
||||
@ -128,15 +129,15 @@ public class ReaderTest {
|
||||
for (ByteBuffer b : buffers) {
|
||||
r.readFrame(b, c);
|
||||
}
|
||||
assertEquals(fin, c.fin());
|
||||
assertEquals(rsv1, c.rsv1());
|
||||
assertEquals(rsv2, c.rsv2());
|
||||
assertEquals(rsv3, c.rsv3());
|
||||
assertEquals(opcode, c.opcode());
|
||||
assertEquals(mask.isPresent(), c.mask());
|
||||
assertEquals(payloadLen, c.payloadLen());
|
||||
assertEquals(mask, c.maskingKey());
|
||||
assertEquals(payloadLen == 0, c.isEndFrame());
|
||||
assertEquals(c.fin(), fin);
|
||||
assertEquals(c.rsv1(), rsv1);
|
||||
assertEquals(c.rsv2(), rsv2);
|
||||
assertEquals(c.rsv3(), rsv3);
|
||||
assertEquals(c.opcode(), opcode);
|
||||
assertEquals(c.mask(), mask.isPresent());
|
||||
assertEquals(c.payloadLen(), payloadLen);
|
||||
assertEquals(c.maskingKey(), mask);
|
||||
assertEquals(c.isEndFrame(), payloadLen == 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2026, 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
|
||||
@ -25,7 +25,7 @@
|
||||
* @test
|
||||
* @summary Basic sanity checks for WebSocket URI from the Builder
|
||||
* @compile ../DummyWebSocketServer.java ../../ProxyServer.java
|
||||
* @run testng/othervm WSSanityTest
|
||||
* @run junit/othervm WSSanityTest
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
@ -38,20 +38,21 @@ import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.WebSocket;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class WSSanityTest {
|
||||
|
||||
URI wsURI;
|
||||
DummyWebSocketServer webSocketServer;
|
||||
InetSocketAddress proxyAddress;
|
||||
private static URI wsURI;
|
||||
private static DummyWebSocketServer webSocketServer;
|
||||
private static InetSocketAddress proxyAddress;
|
||||
|
||||
@BeforeTest
|
||||
public void setup() throws Exception {
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
ProxyServer proxyServer = new ProxyServer(0, true);
|
||||
proxyAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(),
|
||||
proxyServer.getPort());
|
||||
@ -63,8 +64,8 @@ public class WSSanityTest {
|
||||
System.out.println("DummyWebSocketServer: " + wsURI);
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void teardown() {
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
webSocketServer.close();
|
||||
}
|
||||
|
||||
@ -75,8 +76,7 @@ public class WSSanityTest {
|
||||
T run() throws Exception;
|
||||
}
|
||||
|
||||
@DataProvider(name = "passingScenarios")
|
||||
public Object[][] passingScenarios() {
|
||||
public static Object[][] passingScenarios() {
|
||||
HttpClient noProxyClient = HttpClient.newHttpClient();
|
||||
return new Object[][]{
|
||||
{ (ExceptionAction<?>)() -> {
|
||||
@ -146,14 +146,15 @@ public class WSSanityTest {
|
||||
HttpClient client = HttpClient.newBuilder().proxy(ps).build();
|
||||
client.newWebSocketBuilder()
|
||||
.buildAsync(wsURI, noOpListener).get().abort();
|
||||
assertEquals(ps.count(), 1); // ps.select only invoked once
|
||||
assertEquals(1, ps.count()); // ps.select only invoked once
|
||||
return null; },
|
||||
"7" },
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "passingScenarios")
|
||||
@ParameterizedTest
|
||||
@MethodSource("passingScenarios")
|
||||
public void testScenarios(ExceptionAction<?> action, String dataProviderId)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user