diff --git a/hazelcast/src/main/java/com/hazelcast/gcp/GcpAuthenticator.java b/hazelcast/src/main/java/com/hazelcast/gcp/GcpAuthenticator.java index f6d3bd0ed4bd..3854ce578df4 100644 --- a/hazelcast/src/main/java/com/hazelcast/gcp/GcpAuthenticator.java +++ b/hazelcast/src/main/java/com/hazelcast/gcp/GcpAuthenticator.java @@ -21,10 +21,11 @@ import com.hazelcast.internal.json.JsonObject; import com.hazelcast.spi.utils.RestClient; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.InputStreamReader; +import java.io.Reader; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.security.KeyFactory; import java.security.PrivateKey; import java.security.Signature; @@ -73,8 +74,10 @@ String refreshAccessToken(String privateKeyPath, long currentTimeMs) { private String createBody(String privateKeyPath, long currentTimeMs) throws Exception { - JsonObject privateKeyJson = Json.parse( - new InputStreamReader(new FileInputStream(privateKeyPath), StandardCharsets.UTF_8)).asObject(); + JsonObject privateKeyJson; + try (Reader reader = Files.newBufferedReader(Paths.get(privateKeyPath))) { + privateKeyJson = Json.parse(reader).asObject(); + } String privateKey = privateKeyJson.get("private_key").asString(); String clientEmail = privateKeyJson.get("client_email").asString(); diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/MessageTaskSecurityTest.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/MessageTaskSecurityTest.java index 92763c1c2f21..85767972cb18 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/MessageTaskSecurityTest.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/MessageTaskSecurityTest.java @@ -16,22 +16,6 @@ package com.hazelcast.client.protocol; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.reflections.Reflections; - import com.hazelcast.client.impl.protocol.task.AbstractMessageTask; import com.hazelcast.client.impl.protocol.task.AddBackupListenerMessageTask; import com.hazelcast.client.impl.protocol.task.AddClusterViewListenerMessageTask; @@ -70,15 +54,27 @@ import com.hazelcast.sql.impl.client.SqlFetchMessageTask; import com.hazelcast.test.HazelcastParallelClassRunner; import com.hazelcast.test.annotation.QuickTest; - import javassist.ClassPool; -import javassist.NotFoundException; -import javassist.bytecode.BadBytecode; import javassist.bytecode.ClassFile; import javassist.bytecode.CodeAttribute; import javassist.bytecode.CodeIterator; import javassist.bytecode.MethodInfo; import javassist.bytecode.Mnemonic; +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.reflections.Reflections; + +import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; /** * Verifies the {@code getRequiredPermission()} method doesn't simply return null in client {@link MessageTask} instances. @@ -152,7 +148,7 @@ private void assertGetRequiredPermission(String clsname) throws Exception { assertFalse(clsname + " returns null in getRequiredPermission()", returnsNull); } - private boolean doesGetRequiredPermissionSimpleReturnNull(String clsname) throws NotFoundException, Exception, BadBytecode { + private boolean doesGetRequiredPermissionSimpleReturnNull(String clsname) throws Exception { if (clsname == null) { fail("Class with getRequiredPermission() method implementation not found"); } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0.java index 6f251cb4160f..bf1e39901835 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_0 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0_1.java index 5234f4f0ceb6..86fb142c858e 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_0_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_0_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.1.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.1.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_1.java index 4d4e05e42960..0806737c6602 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.1.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.1.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_2.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_2.java index 80ff285a90ed..20e419bf92b9 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_2.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_2.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_2 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.2.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.2.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_3.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_3.java index 62dd4f2509f0..4b1053fac09e 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_3.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_3.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_3 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.3.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.3.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_4.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_4.java index 864f743d63e9..87059c3b01e7 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_4.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_4.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_4 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.4.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.4.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_5.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_5.java index 96a205a78924..2df37bfe4274 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_5.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_5.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_5 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.5.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.5.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_6.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_6.java index ff2dfc0c1713..b7b83d7d3cd8 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_6.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_6.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_6 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.6.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.6.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_7.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_7.java index 44d35777e635..2cd38aff55d9 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_7.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityNullTest_2_7.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityNullTest_2_7 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.7.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.7.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0.java index 8cc9cf8eed16..f0fe615c3499 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_0 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0_1.java index 2f1de51219a1..c91284bacbff 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_0_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_0_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.1.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.1.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_1.java index 2e988982592a..baf21dcf9bd7 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.1.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.1.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_2.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_2.java index 1876249ea6c7..f68dfd78f230 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_2.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_2.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_2 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.2.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.2.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_3.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_3.java index 26cf9fdca434..7dc0581864ff 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_3.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_3.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_3 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.3.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.3.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_4.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_4.java index 214aef8264a0..0069ddde51d0 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_4.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_4.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_4 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.4.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.4.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_5.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_5.java index 9ce991759d92..85007cabb7fe 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_5.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_5.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_5 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.5.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.5.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_6.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_6.java index 3f9e2599fd4c..bf6fca79abac 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_6.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_6.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_6 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.6.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.6.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_7.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_7.java index 1193636dbf38..bcf42f0874d5 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_7.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/ClientCompatibilityTest_2_7.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -53,15 +51,15 @@ public class ClientCompatibilityTest_2_7 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.7.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.7.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0.java index 9008041ad973..47a9ae086031 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_0 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0_1.java index 8a038d213ca8..29d085e2e925 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_0_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_0_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.1.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.1.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_1.java index f33cd079ec3d..eeb81275c7f1 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.1.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.1.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_2.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_2.java index dc7ebefc442e..18c35d326d85 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_2.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_2.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_2 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.2.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.2.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_3.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_3.java index 2fb3ea5d4659..aed691a5c99c 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_3.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_3.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_3 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.3.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.3.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_4.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_4.java index f57daf5acb54..b20f700b111a 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_4.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_4.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_4 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.4.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.4.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_5.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_5.java index dddfe0e20e84..225ca70e89ea 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_5.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_5.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_5 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.5.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.5.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_6.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_6.java index 8be3d007aa3c..a9b0e61778d5 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_6.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_6.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_6 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.6.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.6.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_7.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_7.java index 362c8e12138a..492e1c870b30 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_7.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityNullTest_2_7.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityNullTest_2_7 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.7.protocol.compatibility.null.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.7.protocol.compatibility.null.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0.java index 8f5daafe16c0..8584ca1ccbc2 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_0 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0_1.java index 83cbeb972f99..1b7410f65705 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_0_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_0_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.0.1.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.0.1.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_1.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_1.java index 5eeb16ce65f7..1d79caf4673c 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_1.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_1.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_1 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.1.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.1.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_2.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_2.java index 0975992412db..1b0cd1e103ee 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_2.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_2.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_2 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.2.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.2.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_3.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_3.java index f2bb7fa62d7b..7abf44aa0ed9 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_3.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_3.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_3 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.3.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.3.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_4.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_4.java index 9f2743e57e0d..ed8269db457b 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_4.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_4.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_4 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.4.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.4.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_5.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_5.java index 0c1c5795a4c9..83671f186f98 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_5.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_5.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_5 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.5.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.5.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_6.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_6.java index 28c5cf696cb0..52f4caf76727 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_6.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_6.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_6 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.6.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.6.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_7.java b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_7.java index 6901c49c0088..65da69de3963 100644 --- a/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_7.java +++ b/hazelcast/src/test/java/com/hazelcast/client/protocol/compatibility/MemberCompatibilityTest_2_7.java @@ -28,8 +28,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; @@ -52,15 +50,15 @@ public class MemberCompatibilityTest_2_7 { @Before public void setUp() throws IOException { - File file = new File(getClass().getResource("/2.7.protocol.compatibility.binary").getFile()); - InputStream inputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - inputStream.read(data); - ByteBuffer buffer = ByteBuffer.wrap(data); - ClientMessageReader reader = new ClientMessageReader(0); - while (reader.readFrom(buffer, true)) { - clientMessages.add(reader.getClientMessage()); - reader.reset(); + try (InputStream inputStream = getClass().getResourceAsStream("/2.7.protocol.compatibility.binary")) { + assert inputStream != null; + byte[] data = inputStream.readAllBytes(); + ByteBuffer buffer = ByteBuffer.wrap(data); + ClientMessageReader reader = new ClientMessageReader(0); + while (reader.readFrom(buffer, true)) { + clientMessages.add(reader.getClientMessage()); + reader.reset(); + } } } diff --git a/hazelcast/src/test/java/com/hazelcast/cluster/TcpIpMemberConnectionLossTest.java b/hazelcast/src/test/java/com/hazelcast/cluster/TcpIpMemberConnectionLossTest.java index ebea238802a1..f54588554a7a 100644 --- a/hazelcast/src/test/java/com/hazelcast/cluster/TcpIpMemberConnectionLossTest.java +++ b/hazelcast/src/test/java/com/hazelcast/cluster/TcpIpMemberConnectionLossTest.java @@ -148,13 +148,11 @@ void stop() { running = false; while (thread.isAlive()) { //break it out of a potential accept call - try { - new Socket(host, port); + try (Socket ignored = new Socket(host, port)) { } catch (IOException e) { //ignore } } } - } } diff --git a/hazelcast/src/test/java/com/hazelcast/internal/config/yaml/W3cDomTest.java b/hazelcast/src/test/java/com/hazelcast/internal/config/yaml/W3cDomTest.java index 49cbd6d7b6a5..0ba8ddbf1929 100644 --- a/hazelcast/src/test/java/com/hazelcast/internal/config/yaml/W3cDomTest.java +++ b/hazelcast/src/test/java/com/hazelcast/internal/config/yaml/W3cDomTest.java @@ -30,6 +30,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.io.IOException; import java.io.InputStream; import static com.hazelcast.internal.config.yaml.EmptyNamedNodeMap.emptyNamedNodeMap; @@ -40,7 +41,7 @@ import static org.junit.Assert.assertTrue; /** - * A modified copy of the of the main test case of {@link YamlTest} that + * A modified copy of the main test case of {@link YamlTest} that * verifies the behavior of the W3C DOM adapters' supported methods. *
* These tests utilize that we work with the node adapters with which we
@@ -52,9 +53,11 @@ public class W3cDomTest extends HazelcastTestSupport {
private static final int NOT_EXISTING = 42;
@Test
- public void testW3cDomAdapter() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map-extended.yaml");
- YamlNode yamlRoot = YamlLoader.load(inputStream, "root-map");
+ public void testW3cDomAdapter() throws IOException {
+ YamlNode yamlRoot;
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map-extended.yaml")) {
+ yamlRoot = YamlLoader.load(inputStream, "root-map");
+ }
Node domRoot = W3cDomUtil.asW3cNode(yamlRoot);
NamedNodeMap rootAttributes = domRoot.getAttributes();
diff --git a/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/AdvancedNetworkIntegrationTest.java b/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/AdvancedNetworkIntegrationTest.java
index 02f4db5aa518..e312a6279c4f 100644
--- a/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/AdvancedNetworkIntegrationTest.java
+++ b/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/AdvancedNetworkIntegrationTest.java
@@ -297,10 +297,8 @@ public void doShutdownIfSomeMembersCanBeConnectedWithRequiredMember() {
private void assertLocalPortsOpen(int... ports) {
for (int port : ports) {
- Socket socket = new Socket();
- try {
+ try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress("127.0.0.1", port));
- socket.close();
} catch (IOException e) {
fail("Failed to connect to port " + port + ": " + e.getMessage());
}
diff --git a/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/iobalancer/IOBalancerMemoryLeakTest.java b/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/iobalancer/IOBalancerMemoryLeakTest.java
index e80c0cf5fdb1..e89194294cb8 100644
--- a/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/iobalancer/IOBalancerMemoryLeakTest.java
+++ b/hazelcast/src/test/java/com/hazelcast/internal/networking/nio/iobalancer/IOBalancerMemoryLeakTest.java
@@ -84,12 +84,10 @@ public void testMemoryLeak_with_SocketConnections() {
Runnable runnable = () -> {
for (int i = 0; i < connectionCountPerThread; i++) {
- Socket socket;
- try {
- socket = new Socket(address.getHost(), address.getPort());
+
+ try (Socket socket = new Socket(address.getHost(), address.getPort())) {
socket.getOutputStream().write(Protocols.CLUSTER.getBytes());
sleepMillis(1000);
- socket.close();
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/hazelcast/src/test/java/com/hazelcast/internal/yaml/YamlTest.java b/hazelcast/src/test/java/com/hazelcast/internal/yaml/YamlTest.java
index 7c4a3410fe23..9427653b2421 100644
--- a/hazelcast/src/test/java/com/hazelcast/internal/yaml/YamlTest.java
+++ b/hazelcast/src/test/java/com/hazelcast/internal/yaml/YamlTest.java
@@ -48,118 +48,144 @@ public class YamlTest {
public ExpectedException expectedException = ExpectedException.none();
@Test
- public void testYamlFromInputStream() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- YamlNode root = YamlLoader.load(inputStream, "root-map");
- verify(root);
+ public void testYamlFromInputStream() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ YamlNode root = YamlLoader.load(inputStream, "root-map");
+ verify(root);
+ }
}
@Test
- public void testYamlFromInputStreamWithoutRootName() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- YamlNode root = YamlLoader.load(inputStream);
- verify(asMapping(root).childAsMapping("root-map"));
+ public void testYamlFromInputStreamWithoutRootName() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ YamlNode root = YamlLoader.load(inputStream);
+ verify(asMapping(root).childAsMapping("root-map"));
+ }
}
@Test
- public void testYamlExtendedTestFromInputStream() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map-extended.yaml");
- YamlNode root = YamlLoader.load(inputStream, "root-map");
- verify(root);
- verifyExtendedYaml(root);
+ public void testYamlExtendedTestFromInputStream() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map-extended.yaml")) {
+ YamlNode root = YamlLoader.load(inputStream, "root-map");
+ verify(root);
+ verifyExtendedYaml(root);
+ }
}
@Test
- public void testJsonFromInputStream() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.json");
- YamlNode root = YamlLoader.load(inputStream, "root-map");
- verify(root);
+ public void testJsonFromInputStream() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.json")) {
+ YamlNode root = YamlLoader.load(inputStream, "root-map");
+ verify(root);
+ }
}
@Test
- public void testYamlFromReader() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- YamlNode root = YamlLoader.load(reader, "root-map");
- verify(root);
+ public void testYamlFromReader() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ assert inputStream != null;
+ InputStreamReader reader = new InputStreamReader(inputStream);
+ YamlNode root = YamlLoader.load(reader, "root-map");
+ verify(root);
+ }
}
@Test
- public void testYamlFromReaderWithoutRootName() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- YamlNode root = YamlLoader.load(reader);
- verify(asMapping(root).childAsMapping("root-map"));
+ public void testYamlFromReaderWithoutRootName() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ assert inputStream != null;
+ InputStreamReader reader = new InputStreamReader(inputStream);
+ YamlNode root = YamlLoader.load(reader);
+ verify(asMapping(root).childAsMapping("root-map"));
+ }
}
@Test
public void testYamlFromString() throws IOException {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- String yamlString = CharStreams.toString(reader);
- YamlNode root = YamlLoader.load(yamlString, "root-map");
- verify(root);
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ assert inputStream != null;
+ InputStreamReader reader = new InputStreamReader(inputStream);
+ String yamlString = CharStreams.toString(reader);
+ YamlNode root = YamlLoader.load(yamlString, "root-map");
+ verify(root);
+ }
}
@Test
public void testYamlFromStringWithoutRootMap() throws IOException {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- String yamlString = CharStreams.toString(reader);
- YamlNode root = YamlLoader.load(yamlString);
- verify(asMapping(root).childAsMapping("root-map"));
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ assert inputStream != null;
+ InputStreamReader reader = new InputStreamReader(inputStream);
+ String yamlString = CharStreams.toString(reader);
+ YamlNode root = YamlLoader.load(yamlString);
+ verify(asMapping(root).childAsMapping("root-map"));
+ }
}
@Test
- public void testLoadingInvalidYamlFromInputStream() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml");
- expectedException.expect(YamlException.class);
- YamlLoader.load(inputStream);
+ public void testLoadingInvalidYamlFromInputStream() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml")) {
+ expectedException.expect(YamlException.class);
+ YamlLoader.load(inputStream);
+ }
}
@Test
- public void testLoadingInvalidYamlFromInputStreamWithRootName() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml");
- expectedException.expect(YamlException.class);
- YamlLoader.load(inputStream, "root-map");
+ public void testLoadingInvalidYamlFromInputStreamWithRootName() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml")) {
+ expectedException.expect(YamlException.class);
+ YamlLoader.load(inputStream, "root-map");
+ }
}
@Test
- public void testLoadingInvalidYamlFromReader() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- expectedException.expect(YamlException.class);
- YamlLoader.load(reader);
+ public void testLoadingInvalidYamlFromReader() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml")) {
+ assert inputStream != null;
+ try (InputStreamReader reader = new InputStreamReader(inputStream)) {
+ expectedException.expect(YamlException.class);
+ YamlLoader.load(reader);
+ }
+ }
}
@Test
- public void testLoadingInvalidYamlFromReaderWithRootName() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- expectedException.expect(YamlException.class);
- YamlLoader.load(reader, "root-map");
+ public void testLoadingInvalidYamlFromReaderWithRootName() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml")) {
+ assert inputStream != null;
+ try (InputStreamReader reader = new InputStreamReader(inputStream)) {
+ expectedException.expect(YamlException.class);
+ YamlLoader.load(reader, "root-map");
+ }
+ }
}
@Test
public void testLoadingInvalidYamlFromString() throws IOException {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- String yamlString = CharStreams.toString(reader);
- expectedException.expect(YamlException.class);
- YamlLoader.load(yamlString);
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml")) {
+ assert inputStream != null;
+ try (InputStreamReader reader = new InputStreamReader(inputStream)) {
+ String yamlString = CharStreams.toString(reader);
+ expectedException.expect(YamlException.class);
+ YamlLoader.load(yamlString);
+ }
+ }
}
@Test
public void testLoadingInvalidYamlFromStringWithRootName() throws IOException {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- String yamlString = CharStreams.toString(reader);
- expectedException.expect(YamlException.class);
- YamlLoader.load(yamlString, "root-map");
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-invalid.yaml")) {
+ assert inputStream != null;
+ try (InputStreamReader reader = new InputStreamReader(inputStream)) {
+ String yamlString = CharStreams.toString(reader);
+ expectedException.expect(YamlException.class);
+ YamlLoader.load(yamlString, "root-map");
+ }
+ }
}
@Test
- public void testInvalidScalarValueTypeMap() {
+ public void testInvalidScalarValueTypeMap() throws IOException {
YamlMapping rootMap = getYamlRoot();
YamlMapping embeddedMap = rootMap.childAsMapping("embedded-map");
@@ -168,7 +194,7 @@ public void testInvalidScalarValueTypeMap() {
}
@Test
- public void testInvalidScalarValueTypeSeq() {
+ public void testInvalidScalarValueTypeSeq() throws IOException {
YamlMapping rootMap = getYamlRoot();
YamlSequence embeddedList = rootMap
.childAsMapping("embedded-map")
@@ -179,7 +205,7 @@ public void testInvalidScalarValueTypeSeq() {
}
@Test
- public void testInvalidScalarValueTypeHintedMap() {
+ public void testInvalidScalarValueTypeHintedMap() throws IOException {
YamlMapping rootMap = getYamlRoot();
YamlMapping embeddedMap = rootMap.childAsMapping("embedded-map");
@@ -190,7 +216,7 @@ public void testInvalidScalarValueTypeHintedMap() {
}
@Test
- public void testInvalidScalarValueTypeHintedSeq() {
+ public void testInvalidScalarValueTypeHintedSeq() throws IOException {
YamlMapping rootMap = getYamlRoot();
YamlSequence embeddedList = rootMap
.childAsMapping("embedded-map")
@@ -203,22 +229,22 @@ public void testInvalidScalarValueTypeHintedSeq() {
}
@Test
- public void testNotExistingMappingFromMap() {
+ public void testNotExistingMappingFromMap() throws IOException {
assertNull(getYamlRoot().childAsMapping("not-existing"));
}
@Test
- public void testNotExistingSequenceFromMap() {
+ public void testNotExistingSequenceFromMap() throws IOException {
assertNull(getYamlRoot().childAsSequence("not-existing"));
}
@Test
- public void testNotExistingScalarFromMap() {
+ public void testNotExistingScalarFromMap() throws IOException {
assertNull(getYamlRoot().childAsScalar("not-existing"));
}
@Test
- public void testNotExistingMappingFromSeq() {
+ public void testNotExistingMappingFromSeq() throws IOException {
YamlSequence seq = getYamlRoot()
.childAsMapping("embedded-map")
.childAsSequence("embedded-list");
@@ -226,7 +252,7 @@ public void testNotExistingMappingFromSeq() {
}
@Test
- public void testNotExistingSequenceFromSeq() {
+ public void testNotExistingSequenceFromSeq() throws IOException {
YamlSequence seq = getYamlRoot()
.childAsMapping("embedded-map")
.childAsSequence("embedded-list");
@@ -234,7 +260,7 @@ public void testNotExistingSequenceFromSeq() {
}
@Test
- public void testNotExistingScalarFromSeq() {
+ public void testNotExistingScalarFromSeq() throws IOException {
YamlSequence seq = getYamlRoot()
.childAsMapping("embedded-map")
.childAsSequence("embedded-list");
@@ -242,19 +268,20 @@ public void testNotExistingScalarFromSeq() {
}
@Test
- public void testInvalidNodeTypeNotAMapping() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- YamlNode root = YamlLoader.load(inputStream, "root-map");
+ public void testInvalidNodeTypeNotAMapping() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ YamlNode root = YamlLoader.load(inputStream, "root-map");
- YamlMapping embeddedMap = ((YamlMapping) root)
- .childAsMapping("embedded-map");
+ YamlMapping embeddedMap = ((YamlMapping) root)
+ .childAsMapping("embedded-map");
- expectedException.expect(YamlException.class);
- embeddedMap.childAsMapping("embedded-list");
+ expectedException.expect(YamlException.class);
+ embeddedMap.childAsMapping("embedded-list");
+ }
}
@Test
- public void testInvalidNodeTypeNotASeq() {
+ public void testInvalidNodeTypeNotASeq() throws IOException {
YamlMapping rootMap = getYamlRoot();
expectedException.expect(YamlException.class);
@@ -262,7 +289,7 @@ public void testInvalidNodeTypeNotASeq() {
}
@Test
- public void testInvalidNodeTypeNotAScalar() {
+ public void testInvalidNodeTypeNotAScalar() throws IOException {
YamlMapping rootMap = getYamlRoot();
expectedException.expect(YamlException.class);
@@ -270,7 +297,7 @@ public void testInvalidNodeTypeNotAScalar() {
}
@Test
- public void testIterateChildrenMap() {
+ public void testIterateChildrenMap() throws IOException {
YamlMapping embeddedMap = getYamlRoot()
.childAsMapping("embedded-map");
@@ -284,7 +311,7 @@ public void testIterateChildrenMap() {
}
@Test
- public void testIterateChildrenSeq() {
+ public void testIterateChildrenSeq() throws IOException {
YamlSequence embeddedList = getYamlRoot()
.childAsMapping("embedded-map")
.childAsSequence("embedded-list");
@@ -299,43 +326,43 @@ public void testIterateChildrenSeq() {
}
@Test
- public void testParentOfRootIsNull() {
+ public void testParentOfRootIsNull() throws IOException {
assertNull(getYamlRoot().parent());
}
@Test
- public void testParentOfEmbeddedMapIsRoot() {
+ public void testParentOfEmbeddedMapIsRoot() throws IOException {
YamlMapping root = getYamlRoot();
assertSame(root, root.childAsMapping("embedded-map").parent());
}
@Test
- public void testParentOfScalarIntIsEmbeddedMap() {
+ public void testParentOfScalarIntIsEmbeddedMap() throws IOException {
YamlMapping embeddedMap = getYamlRoot().childAsMapping("embedded-map");
assertSame(embeddedMap, embeddedMap.childAsScalar("scalar-int").parent());
}
@Test
- public void testNameOfMap() {
+ public void testNameOfMap() throws IOException {
assertEquals("embedded-map", getYamlRoot().childAsMapping("embedded-map").nodeName());
}
@Test
- public void testNameOfSeq() {
+ public void testNameOfSeq() throws IOException {
assertEquals("embedded-list", getYamlRoot().childAsMapping("embedded-map")
.childAsSequence("embedded-list")
.nodeName());
}
@Test
- public void testNameOfNamedScalar() {
+ public void testNameOfNamedScalar() throws IOException {
assertEquals("scalar-int", getYamlRoot().childAsMapping("embedded-map")
.childAsScalar("scalar-int")
.nodeName());
}
@Test
- public void testNameOfUnnamedScalar() {
+ public void testNameOfUnnamedScalar() throws IOException {
assertSame(YamlNode.UNNAMED_NODE, getYamlRoot().childAsMapping("embedded-map")
.childAsSequence("embedded-list")
.childAsScalar(0)
@@ -344,19 +371,22 @@ public void testNameOfUnnamedScalar() {
@Test
public void testYamlListInRoot() throws IOException {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-seq.yaml");
- InputStreamReader reader = new InputStreamReader(inputStream);
- String yamlString = CharStreams.toString(reader);
- YamlNode root = YamlLoader.load(yamlString);
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-seq.yaml")) {
+ assert inputStream != null;
+ try (InputStreamReader reader = new InputStreamReader(inputStream)) {
+ String yamlString = CharStreams.toString(reader);
+ YamlNode root = YamlLoader.load(yamlString);
- assertTrue(root instanceof YamlSequence);
+ assertTrue(root instanceof YamlSequence);
- YamlSequence rootSeq = asSequence(root);
- assertEquals(42, ((Integer) rootSeq.childAsScalarValue(0)).intValue());
+ YamlSequence rootSeq = asSequence(root);
+ assertEquals(42, ((Integer) rootSeq.childAsScalarValue(0)).intValue());
- YamlMapping map = rootSeq.childAsMapping(1);
- assertEquals(YamlNode.UNNAMED_NODE, map.nodeName());
- assertEquals("embedded-map", map.childAsMapping("embedded-map").nodeName());
+ YamlMapping map = rootSeq.childAsMapping(1);
+ assertEquals(YamlNode.UNNAMED_NODE, map.nodeName());
+ assertEquals("embedded-map", map.childAsMapping("embedded-map").nodeName());
+ }
+ }
}
private void verify(YamlNode root) {
@@ -425,10 +455,11 @@ private void verifyExtendedYaml(YamlNode root) {
multilineStr);
}
- private YamlMapping getYamlRoot() {
- InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml");
- YamlNode root = YamlLoader.load(inputStream, "root-map");
+ private YamlMapping getYamlRoot() throws IOException {
+ try (InputStream inputStream = YamlTest.class.getClassLoader().getResourceAsStream("yaml-test-root-map.yaml")) {
+ YamlNode root = YamlLoader.load(inputStream, "root-map");
- return (YamlMapping) root;
+ return (YamlMapping) root;
+ }
}
}
diff --git a/hazelcast/src/test/java/com/hazelcast/jet/core/HzSerializableProcessorSuppliersTest.java b/hazelcast/src/test/java/com/hazelcast/jet/core/HzSerializableProcessorSuppliersTest.java
index 6791d1c9f358..52895e2198db 100644
--- a/hazelcast/src/test/java/com/hazelcast/jet/core/HzSerializableProcessorSuppliersTest.java
+++ b/hazelcast/src/test/java/com/hazelcast/jet/core/HzSerializableProcessorSuppliersTest.java
@@ -38,7 +38,7 @@ public class HzSerializableProcessorSuppliersTest extends SimpleTestInClusterSup
private final DAG dag = new DAG();
private final URL url = requireNonNull(
getClass().getResource("DataSerializableSuppliers.jar"));
- private final ClassLoader cl = new URLClassLoader(new URL[] {url});
+
@BeforeClass
public static void beforeClass() {
@@ -49,26 +49,32 @@ public static void beforeClass() {
@Test
public void test_metaSupplier() throws Exception {
- ProcessorMetaSupplier metaSupplier =
- ClassLoaderUtil.newInstance(cl, "com.example.DataSerializableSuppliers$MetaSupplier");
- dag.newVertex("v", metaSupplier);
- submitJob();
+ try (URLClassLoader cl = new URLClassLoader(new URL[]{url})) {
+ ProcessorMetaSupplier metaSupplier =
+ ClassLoaderUtil.newInstance(cl, "com.example.DataSerializableSuppliers$MetaSupplier");
+ dag.newVertex("v", metaSupplier);
+ submitJob();
+ }
}
@Test
public void test_pSupplier() throws Exception {
- ProcessorSupplier pSupplier =
- ClassLoaderUtil.newInstance(cl, "com.example.DataSerializableSuppliers$PSupplier");
- dag.newVertex("v", pSupplier);
- submitJob();
+ try (URLClassLoader cl = new URLClassLoader(new URL[]{url})) {
+ ProcessorSupplier pSupplier =
+ ClassLoaderUtil.newInstance(cl, "com.example.DataSerializableSuppliers$PSupplier");
+ dag.newVertex("v", pSupplier);
+ submitJob();
+ }
}
@Test
public void test_simpleSupplier() throws Exception {
- SupplierEx