Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions test/jdk/sun/net/ext/ExtendedSocketOptionsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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
Expand All @@ -21,8 +21,7 @@
* questions.
*/

import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -33,18 +32,22 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;

/**
* @test
* @bug 8260366
* @summary Verify that concurrent classloading of sun.net.ext.ExtendedSocketOptions and
* jdk.net.ExtendedSocketOptions doesn't lead to a deadlock
* @modules java.base/sun.net.ext:open
* jdk.net
* @run testng/othervm ExtendedSocketOptionsTest
* @run testng/othervm ExtendedSocketOptionsTest
* @run testng/othervm ExtendedSocketOptionsTest
* @run testng/othervm ExtendedSocketOptionsTest
* @run testng/othervm ExtendedSocketOptionsTest
* @run junit/othervm ExtendedSocketOptionsTest
* @run junit/othervm ExtendedSocketOptionsTest
* @run junit/othervm ExtendedSocketOptionsTest
* @run junit/othervm ExtendedSocketOptionsTest
* @run junit/othervm ExtendedSocketOptionsTest
Comment thread
mahendrachhipa marked this conversation as resolved.
Outdated
*/
public class ExtendedSocketOptionsTest {

Expand Down Expand Up @@ -83,13 +86,13 @@ public void testConcurrentClassLoad() throws Exception {
// check that the sun.net.ext.ExtendedSocketOptions#getInstance() does indeed return
// the registered instance
final Object extSocketOptions = callSunNetExtSocketOptionsGetInstance();
Assert.assertNotNull(extSocketOptions, "sun.net.ext.ExtendedSocketOptions#getInstance()" +
assertNotNull(extSocketOptions, "sun.net.ext.ExtendedSocketOptions#getInstance()" +
" unexpectedly returned null");
// now verify that each call to getInstance(), either in the tasks or here, returned the exact
// same instance of ExtendedSocketOptions
Assert.assertEquals(2, GetInstanceTask.extendedSocketOptionsInstances.size());
assertEquals(2, GetInstanceTask.extendedSocketOptionsInstances.size());
for (final Object inst : GetInstanceTask.extendedSocketOptionsInstances) {
Assert.assertSame(inst, extSocketOptions, "sun.net.ext.ExtendedSocketOptions#getInstance()" +
assertSame(inst, extSocketOptions, "sun.net.ext.ExtendedSocketOptions#getInstance()" +
Comment thread
mahendrachhipa marked this conversation as resolved.
Outdated
" returned different instances");
}
}
Expand Down
13 changes: 7 additions & 6 deletions test/jdk/sun/net/spi/DefaultProxySelectorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 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
Expand All @@ -21,18 +21,19 @@
* questions.
*/

import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;
import sun.net.spi.DefaultProxySelector;

import java.net.ProxySelector;
import java.net.URI;

import static org.junit.jupiter.api.Assertions.fail;

/**
* @test
* @bug 6563286 6797318 8177648
* @summary Tests sun.net.spi.DefaultProxySelector#select(URI)
* @run testng DefaultProxySelectorTest
* @run junit DefaultProxySelectorTest
* @modules java.base/sun.net.spi:+open
*/
public class DefaultProxySelectorTest {
Expand All @@ -46,7 +47,7 @@ public void testIllegalArgForNull() {
final ProxySelector selector = new DefaultProxySelector();
try {
selector.select(null);
Assert.fail("select() was expected to fail for null URI");
fail("select() was expected to fail for null URI");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could simplify and use assertThrows here, and in other places/files as well

} catch (IllegalArgumentException iae) {
// expected
}
Expand Down Expand Up @@ -82,7 +83,7 @@ public void testIllegalArgForNoScheme() throws Exception {
private static void assertFailsWithIAE(final ProxySelector selector, final URI uri) {
try {
selector.select(uri);
Assert.fail("select() was expected to fail for URI " + uri);
fail("select() was expected to fail for URI " + uri);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Use assertThrows, even consider removind this method.

} catch (IllegalArgumentException iae) {
// expected
}
Expand Down
15 changes: 8 additions & 7 deletions test/jdk/sun/net/www/MessageHeaderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
Expand All @@ -25,16 +25,17 @@
* @test
* @bug 8003948 8133686
* @modules java.base/sun.net.www
* @run testng MessageHeaderTest
* @run junit MessageHeaderTest
*/

import java.io.*;
import java.util.*;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;
import sun.net.www.MessageHeader;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MessageHeaderTest {
/* This test checks to see if the MessageHeader.getHeaders method
returns headers with the same value field in the order they were added
Expand All @@ -53,7 +54,7 @@ public void reverseMessageHeadersTest() throws Exception {

var actualHeaders = testHeader.getHeaders().get("test");

Assert.assertEquals(expectedHeaders, actualHeaders, String.format(errorMessageTemplate, expectedHeaders.toString(), actualHeaders.toString()));
assertEquals(expectedHeaders, actualHeaders, String.format(errorMessageTemplate, expectedHeaders.toString(), actualHeaders.toString()));
}

@Test
Expand Down Expand Up @@ -90,8 +91,8 @@ public void ntlmNegotiateTest () throws Exception {
boolean result = h.filterNTLMResponses("WWW-Authenticate");
String after = h.toString();
after = after.substring(after.indexOf('{'));
Assert.assertEquals(expected[i], after, i + " expected != after");
Assert.assertEquals(result, expectedResult[i], i + " result != expectedResult");
assertEquals(expected[i], after, i + " expected != after");
assertEquals(expectedResult[i], result, i + " result != expectedResult");
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,5 +26,5 @@
* @bug 8255124
* @summary Tests that KeepAliveStreamCleaner run does not throw an IllegalMonitorState Exception.
* @modules java.base/sun.net.www.http
* @run testng java.base/sun.net.www.http.KeepAliveStreamCleanerTest
* @run junit java.base/sun.net.www.http.KeepAliveStreamCleanerTest
*/
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,9 +23,9 @@

package sun.net.www.http;

import org.testng.annotations.Test;

@Test
import org.junit.jupiter.api.Test;

public class KeepAliveStreamCleanerTest {

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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
Expand Down Expand Up @@ -30,17 +30,16 @@
* @modules java.base/sun.net.www.http
* java.base/sun.net.www.protocol.http
* @build java.base/sun.net.www.http.HttpClientAccess
* @run testng/othervm RequestMethodEquality
* @run junit/othervm RequestMethodEquality
*/

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import jdk.test.lib.net.URIBuilder;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import sun.net.www.http.HttpClient;
import sun.net.www.http.HttpClientAccess;
import sun.net.www.http.KeepAliveCache;
Expand All @@ -52,21 +51,23 @@
import java.net.Proxy;
import java.net.URL;

import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class RequestMethodEquality {
private static final String TEST_CONTEXT = "/reqmethodtest";
private HttpServer server;
private CustomHandler handler;
private HttpClientAccess httpClientAccess;
private static HttpServer server;
private static CustomHandler handler;
private static HttpClientAccess httpClientAccess;

@BeforeTest
public void setup() throws Exception {
@BeforeAll
public static void setup() throws Exception {
handler = new CustomHandler();
server = createServer(handler);
httpClientAccess = new HttpClientAccess();
}

@AfterTest
public void tearDown() throws Exception {
@AfterAll
public static void tearDown() throws Exception {
if (server != null) {
server.stop(0);
}
Expand Down Expand Up @@ -111,7 +112,7 @@ public void testHttpClient() throws Exception {

// If both connectTimeout values are equal, it means the test retrieved the same broken
// HttpClient from the cache and is trying to re-use it.
Assert.assertNotEquals(originalConnectTimeout, cachedConnectTimeout, "Both connectTimeout values are equal.\nThis means the test is reusing a broken HttpClient rather than creating a new one.");
assertNotEquals(originalConnectTimeout, cachedConnectTimeout, "Both connectTimeout values are equal.\nThis means the test is reusing a broken HttpClient rather than creating a new one.");
Comment thread
mahendrachhipa marked this conversation as resolved.
} finally {
if (conn != null) {
conn.disconnect();
Expand Down
19 changes: 10 additions & 9 deletions test/jdk/sun/net/www/protocol/file/DirPermissionDenied.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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
Expand Down Expand Up @@ -28,7 +28,7 @@
* @library /test/lib
* @build DirPermissionDenied jdk.test.lib.process.*
* jdk.test.lib.util.FileUtils
* @run testng DirPermissionDenied
* @run junit DirPermissionDenied
*/

import java.io.IOException;
Expand All @@ -41,9 +41,10 @@

import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class DirPermissionDenied {
private static final Path TEST_DIR = Paths.get(
"DirPermissionDeniedDirectory");
Expand Down Expand Up @@ -79,8 +80,8 @@ public void doTest() throws MalformedURLException {
}
Comment thread
mahendrachhipa marked this conversation as resolved.
}

@BeforeTest
public void setup() throws Throwable {
@BeforeAll
public static void setup() throws Throwable {
// mkdir and chmod "333"
Files.createDirectories(TEST_DIR);
ProcessTools.executeCommand("chmod", "333", TEST_DIR.toString())
Expand All @@ -89,8 +90,8 @@ public void setup() throws Throwable {
.shouldHaveExitValue(0);
}

@AfterTest
public void tearDown() throws Throwable {
@AfterAll
public static void tearDown() throws Throwable {
// add read permission to ensure the dir removable
ProcessTools.executeCommand("chmod", "733", TEST_DIR.toString())
.outputTo(System.out)
Expand Down
30 changes: 15 additions & 15 deletions test/jdk/sun/net/www/protocol/http/HttpHeaderParserTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 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
Expand All @@ -28,7 +28,7 @@
* @library /test/lib
* @summary Sanity check that HttpHeaderParser works same as MessageHeader
* @modules java.base/sun.net.www java.base/sun.net.www.protocol.http:open
* @run testng/othervm HttpHeaderParserTest
* @run junit/othervm HttpHeaderParserTest
*/

import java.io.ByteArrayInputStream;
Expand All @@ -45,16 +45,17 @@
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.US_ASCII;
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 jdk.test.lib.net.HttpHeaderParser;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import sun.net.www.MessageHeader;

public class HttpHeaderParserTest {
@DataProvider(name = "responses")
public Object[][] responses() {
public static Object[][] responses() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider simplifying the method to use List.of and simply return List<String>

List<String> responses = new ArrayList<>();

String[] basic =
Expand Down Expand Up @@ -318,8 +319,8 @@ static final String mixedCRLF(String headers) {
return res.toString();
}


@Test(dataProvider = "responses")
@ParameterizedTest
@MethodSource("responses")
public void verifyHeaders(String respString) throws Exception {
System.out.println("\ntesting:\n\t" + respString
.replace("\r\n", "<CRLF>")
Expand Down Expand Up @@ -366,8 +367,7 @@ public void verifyHeaders(String respString) throws Exception {
availableBytes, headerStream.available()));
}

@DataProvider(name = "errors")
public Object[][] errors() {
public static Object[][] errors() {
Comment thread
mahendrachhipa marked this conversation as resolved.
Outdated
List<String> responses = new ArrayList<>();

// These responses are parsed, somewhat, by MessageHeaders but give
Expand Down Expand Up @@ -441,16 +441,16 @@ public Object[][] errors() {

};
Arrays.stream(bad).forEach(responses::add);

return responses.stream().map(p -> new Object[] { p }).toArray(Object[][]::new);
}

@Test(dataProvider = "errors", expectedExceptions = IOException.class)
@ParameterizedTest
@MethodSource("errors")
public void errors(String respString) throws IOException {
byte[] bytes = respString.getBytes(US_ASCII);
HttpHeaderParser decoder = new HttpHeaderParser();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
decoder.parse(bais);
assertThrows(IOException.class, () -> decoder.parse(bais));
}

void assertHeadersEqual(Map<String,List<String>> expected,
Expand Down
Loading