Skip to content

Commit

Permalink
Replace deprecated methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlipp committed Aug 8, 2024
1 parent 11e0bc8 commit e9c15b5
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
Expand Down Expand Up @@ -82,11 +83,12 @@ public void stopServer() throws InterruptedException {

@Test(timeout = 5000)
public void testGetSimpleWithoutPrefix()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
server.attach(new ContentProvider(server.channel(),
GetTest.class.getClassLoader(), "templates", URI.create("/")));
URL url = new URL("http", "localhost", server.getPort(),
"/simple.ftl.html");
URL url = new URI("http", null, "localhost", server.getPort(),
"/simple.ftl.html", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(4000);
conn.setReadTimeout(4000);
Expand All @@ -101,11 +103,12 @@ public void testGetSimpleWithoutPrefix()

@Test(timeout = 5000)
public void testGetStaticWithoutPrefix()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
server.attach(new ContentProvider(server.channel(),
GetTest.class.getClassLoader(), "templates", URI.create("/")));
URL url = new URL("http", "localhost", server.getPort(),
"/Readme.txt");
URL url = new URI("http", null, "localhost", server.getPort(),
"/Readme.txt", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(4000);
conn.setReadTimeout(4000);
Expand All @@ -120,12 +123,13 @@ public void testGetStaticWithoutPrefix()

@Test(timeout = 5000)
public void testGetSimpleWithPrefix()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
server.attach(new ContentProvider(server.channel(),
GetTest.class.getClassLoader(), "templates",
URI.create("/generated/")));
URL url = new URL("http", "localhost", server.getPort(),
"/generated/simple.ftl.html");
URL url = new URI("http", null, "localhost", server.getPort(),
"/generated/simple.ftl.html", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(4000);
conn.setReadTimeout(4000);
Expand All @@ -140,12 +144,13 @@ public void testGetSimpleWithPrefix()

@Test(timeout = 5000)
public void testGetStaticWithPrefix()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
server.attach(new ContentProvider(server.channel(),
GetTest.class.getClassLoader(), "templates",
URI.create("/generated/")));
URL url = new URL("http", "localhost", server.getPort(),
"/generated/Readme.txt");
URL url = new URI("http", null, "localhost", server.getPort(),
"/generated/Readme.txt", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(4000);
conn.setReadTimeout(4000);
Expand Down
39 changes: 26 additions & 13 deletions org.jgrapes.http/test/org/jgrapes/http/test/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.CharBuffer;
import java.text.ParseException;
Expand Down Expand Up @@ -250,8 +252,10 @@ public static void stopApps() throws InterruptedException {

@Test(timeout = 1500)
public void testUnknownHost()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL(protocol, "never.ever.known", srvPort(), "/");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI(protocol, null, "never.ever.known", srvPort(), "/",
null, null).toURL();
WaitForTests<ErrorReceived> doneWaiter = new WaitForTests<>(clntApp,
ErrorReceived.class, clntApp.defaultCriterion());
clntApp.startRequest(new Request.Out.Get(url), channel -> {
Expand All @@ -262,9 +266,11 @@ public void testUnknownHost()

@Test(timeout = 1500)
public void testConnectionRefused()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
// Though not impossible, it's highly unlikely to have a server here
URL url = new URL(protocol, "localhost", srvPort() + 1, "/top");
URL url = new URI(protocol, null, "localhost", srvPort() + 1, "/top",
null, null).toURL();
WaitForTests<ErrorReceived> doneWaiter = new WaitForTests<>(clntApp,
ErrorReceived.class, clntApp.defaultCriterion());
clntApp.startRequest(new Request.Out.Get(url), channel -> {
Expand All @@ -275,8 +281,10 @@ public void testConnectionRefused()

@Test(timeout = 1500)
public void testGetMatchTop()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL(protocol, "localhost", srvPort(), "/top");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI(protocol, null, "localhost", srvPort(), "/top",
null, null).toURL();
WaitForTests<InputReceived> done = new WaitForTests<>(clntApp,
InputReceived.class, clntApp.defaultCriterion());
clntApp.startRequest(new Request.Out.Get(url), channel -> {
Expand All @@ -291,8 +299,10 @@ public void testGetMatchTop()

@Test(timeout = 1500)
public void testPost()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL(protocol, "localhost", srvPort(), "/reflect");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI(protocol, null, "localhost", srvPort(), "/reflect",
null, null).toURL();
Request.Out.Post post = new Request.Out.Post(url);
post.httpRequest().setField("Content-Type",
"text/plain; charset=utf-8");
Expand All @@ -318,9 +328,10 @@ public void testPost()

@Test(timeout = 1500)
public void testWsEcho()
throws IOException, InterruptedException, ExecutionException {
URL url
= new URL(protocol, "localhost", srvPort(), "/ws/echo?store=42");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI(protocol, null, "localhost", srvPort(),
"/ws/echo", "store=42", null).toURL();
Request.Out.Get upgrade = new Request.Out.Get(url);
upgrade.httpRequest().setField(HttpField.UPGRADE,
new StringList("websocket"));
Expand Down Expand Up @@ -366,8 +377,10 @@ public void testWsEcho()

@Test(timeout = 1500)
public void testWsClientClose()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL(protocol, "localhost", srvPort(), "/ws/echo");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI(protocol, null, "localhost", srvPort(), "/ws/echo",
null, null).toURL();
Request.Out.Get upgrade = new Request.Out.Get(url);
upgrade.httpRequest().setField(HttpField.UPGRADE,
new StringList("websocket"));
Expand Down
54 changes: 34 additions & 20 deletions org.jgrapes.http/test/org/jgrapes/http/test/GetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
Expand Down Expand Up @@ -172,9 +174,11 @@ public static void stopServer() throws InterruptedException {

@Test(timeout = 1500)
public void testNoGetRoot()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
try {
URL url = new URL("http", "localhost", server.getPort(), "/");
URL url = new URI("http", null, "localhost", server.getPort(), "/",
null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand All @@ -188,10 +192,11 @@ public void testNoGetRoot()

@Test(timeout = 1500)
public void testNotFoundStatusOnly()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
try {
URL url = new URL("http", "localhost", server.getPort(),
"/not-found-status-only");
URL url = new URI("http", null, "localhost", server.getPort(),
"/not-found-status-only", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand All @@ -205,8 +210,10 @@ public void testNotFoundStatusOnly()

@Test(timeout = 1500)
public void testGetMatchTop()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL("http", "localhost", server.getPort(), "/top");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI("http", null, "localhost", server.getPort(), "/top",
null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand All @@ -220,8 +227,10 @@ public void testGetMatchTop()

@Test(timeout = 1500)
public void testGetMatchTopPlus()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL("http", "localhost", server.getPort(), "/top/plus");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI("http", null, "localhost", server.getPort(),
"/top/plus", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand All @@ -231,8 +240,10 @@ public void testGetMatchTopPlus()

@Test(timeout = 1500)
public void testGetMatchDynamic()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL("http", "localhost", server.getPort(), "/dynamic");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI("http", null, "localhost", server.getPort(),
"/dynamic", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand All @@ -246,9 +257,10 @@ public void testGetMatchDynamic()

@Test(timeout = 2500)
public void testGetUnversionedStatic()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL("http", "localhost", server.getPort(),
"/static-content/index.html");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI("http", null, "localhost", server.getPort(),
"/static-content/index.html", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(2000);
conn.setReadTimeout(2000);
Expand All @@ -262,9 +274,10 @@ public void testGetUnversionedStatic()

@Test(timeout = 2500)
public void testGetVersionedStatic()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL("http", "localhost", server.getPort(),
"/static-content/versioned-1.0.0.html");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI("http", null, "localhost", server.getPort(),
"/static-content/versioned-1.0.0.html", null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(2000);
conn.setReadTimeout(2000);
Expand All @@ -278,9 +291,10 @@ public void testGetVersionedStatic()

@Test(timeout = 2500)
public void testGetFromJar()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL("http", "localhost", server.getPort(),
"/from-jar/static-content/index.html");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI("http", null, "localhost", server.getPort(),
"/from-jar/static-content/index.html", null, null).toURL();
// Unconditional fetch
URLConnection conn = url.openConnection();
conn.setConnectTimeout(2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -59,9 +61,11 @@ public static void stopServer() throws InterruptedException {

@Test(timeout = 1500)
public void testGetRoot()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
try {
URL url = new URL("http", "localhost", server.getPort(), "/");
URL url = new URI("http", null, "localhost", server.getPort(), "/",
null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand Down
8 changes: 6 additions & 2 deletions org.jgrapes.http/test/org/jgrapes/http/test/PostTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.concurrent.ExecutionException;
import org.jgrapes.core.Channel;
Expand Down Expand Up @@ -69,8 +71,10 @@ public static void stopServer() throws InterruptedException {

@Test(timeout = 1500)
public void testPost()
throws IOException, InterruptedException, ExecutionException {
URL url = new URL("http", "localhost", server.getPort(), "/reflect");
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
URL url = new URI("http", null, "localhost", server.getPort(),
"/reflect", null, null).toURL();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand Down
7 changes: 5 additions & 2 deletions org.jgrapes.http/test/org/jgrapes/http/test/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.security.KeyManagementException;
Expand Down Expand Up @@ -199,10 +201,11 @@ public static void stopServer() throws InterruptedException {
@Test
public void testConcurrentGetRoot()
throws IOException, InterruptedException, ExecutionException,
TimeoutException {
TimeoutException, URISyntaxException {
Waiter waiter = new Waiter();

URL url = new URL("https", "localhost", server.getPort(), "/");
URL url = new URI("https", null, "localhost", server.getPort(), "/",
null, null).toURL();

int threadCount = 1000;
if (Boolean.parseBoolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.jgrapes.http.test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -49,9 +51,11 @@ public static void stopServer() throws InterruptedException {

@Test(timeout = 1500)
public void testGetRoot()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException, ExecutionException,
URISyntaxException {
try {
URL url = new URL("http", "localhost", server.getPort(), "/");
URL url = new URI("http", null, "localhost", server.getPort(), "/",
null, null).toURL();
URLConnection conn = url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,7 @@ private static final class MBeanView implements ManagedBufferPoolMXBean {

private static Set<ManagedBufferPool<?, ?>> allPools
= Collections.synchronizedSet(
Collections.newSetFromMap(
new WeakHashMap<ManagedBufferPool<?, ?>, Boolean>()));
Collections.newSetFromMap(new WeakHashMap<>()));

/**
* Adds the pool.
Expand Down

0 comments on commit e9c15b5

Please sign in to comment.