From d62da7981e656be0d1e2eaa27d67212c75584ee0 Mon Sep 17 00:00:00 2001 From: emeroad Date: Tue, 24 Dec 2024 14:09:16 +0900 Subject: [PATCH] [#noissue] Apply @AutoClose # Conflicts: # agent-module/plugins-it/informix-jdbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/informix/InformixConnectionIT.java --- .../cassandra/CassandraDatastaxITBase.java | 10 ++-------- .../dubbo/consumer/DubboConsumerIT.java | 9 +++------ .../dubbo/provider/DubboProviderIT.java | 11 +++-------- .../ElasticsearchIT_6_0_x_IT.java | 10 ++-------- .../ElasticsearchIT_6_4_x_IT.java | 10 ++-------- .../ElasticsearchIT_7_0_x_IT.java | 11 ++--------- .../ElasticsearchIT_7_16_x_IT.java | 10 ++-------- .../google/httpclient/HttpRequestIT.java | 9 ++------- .../it/plugin/hbase/HbaseClientIT.java | 9 +++------ .../it/plugin/httpclient3/HttpClientIT.java | 8 ++------ .../ClosableAsyncHttpClientIT.java | 10 ++++------ .../plugin/httpclient4/HttpClientITBase.java | 8 ++------ .../plugin/httpclient5/HttpClientITBase.java | 8 ++------ .../plugin/ibatis/SqlMapClientTemplateIT.java | 9 +++------ .../plugin/ibatis/SqlMapExecutorTestBase.java | 9 +++------ .../plugin/jdk/http/HttpURLConnectionIT.java | 8 ++------ .../it/plugin/mongodb/MongoDBIT_3_0_x_IT.java | 10 ++-------- .../it/plugin/mongodb/MongoDBIT_3_2_x_IT.java | 10 ++-------- .../it/plugin/mongodb/MongoDBIT_3_4_x_IT.java | 10 ++-------- .../it/plugin/mongodb/MongoDBIT_3_7_x_IT.java | 10 ++-------- .../plugin/mongodb4/MongoDBIT_4_0_x_IT.java | 10 ++-------- .../mongodb4/ReactiveMongoDBIT_4_2_x_IT.java | 10 ++-------- .../plugin/mybatis/DefaultSqlSessionIT.java | 9 +++------ .../mybatis/SqlSessionTemplateITBase.java | 9 +++------ .../it/plugin/jdbc/mysql/MySql_IT_Base.java | 2 +- .../pinpoint/it/plugin/netty/NettyIT.java | 8 ++------ .../NingAsyncHttpClientIT.java | 8 ++------ .../it/plugin/okhttp/OkHttpClient_2_x_IT.java | 10 ++-------- .../OkHttpClient_3_0_0_to_3_3_x_IT.java | 8 ++------ .../okhttp/OkHttpClient_3_4_0_BaseIT.java | 8 ++------ .../plugin/paho/mqtt/PahoMqttV5ClientIT.java | 2 ++ .../postgresql/PostgreSQLConnectionIT.java | 10 +++------- .../spring/SpringAmqpRabbitTestRunner.java | 19 +++++++++---------- .../SpringAmqpRabbit_1_3_3_to_1_4_2_IT.java | 8 ++------ .../SpringAmqpRabbit_1_4_2_to_1_7_0_IT.java | 8 ++------ .../SpringAmqpRabbit_1_7_0_to_1_7_7_IT.java | 8 ++------ .../SpringAmqpRabbit_1_7_7_to_2_0_0_IT.java | 8 ++------ .../SpringAmqpRabbit_2_0_0_to_2_0_3_IT.java | 8 ++------ .../SpringAmqpRabbit_2_0_3_to_2_1_0_IT.java | 8 ++------ .../SpringAmqpRabbit_2_1_x_to_2_x_IT.java | 8 ++------ .../rabbitmq/spring/TestMessageHolder.java | 9 +++++++-- .../spring/receiver/TestReceiver.java | 2 +- .../receiver/TestReceiver_Post_1_6_0.java | 2 +- .../receiver/TestReceiver_Pre_1_6_0.java | 2 +- .../spring/service/TestReceiverService.java | 2 +- .../it/plugin/lettuce/RedisClient_IT.java | 10 ++-------- .../it/plugin/jdbc/r2dbc/SqlBase.java | 4 ++-- .../it/plugin/spring/web/RestTemplateIT.java | 8 ++------ .../it/plugin/thrift/it/EchoTestRunner.java | 17 +++-------------- .../it/plugin/thrift/it/EchoTestRunner.java | 17 +++-------------- .../pinpoint/it/plugin/utils/WebServer.java | 3 +-- .../pluginit/utils/WebServerTest.java | 8 ++------ .../statistics/DefaultBulkUpdaterTest.java | 10 +++------- .../SizeLimitedBulkIncrementerTest.java | 10 +++------- .../receiver/DispatchHandlerTest.java | 9 +++------ .../HbaseApplicationTraceIndexDaoTest.java | 9 +++------ 56 files changed, 134 insertions(+), 346 deletions(-) diff --git a/agent-module/plugins-it/cassandra-it/cassandra-2-it/src/test/java/com/navercorp/pinpoint/it/plugin/cassandra/CassandraDatastaxITBase.java b/agent-module/plugins-it/cassandra-it/cassandra-2-it/src/test/java/com/navercorp/pinpoint/it/plugin/cassandra/CassandraDatastaxITBase.java index 3a76b6ee909b..cdd990433107 100644 --- a/agent-module/plugins-it/cassandra-it/cassandra-2-it/src/test/java/com/navercorp/pinpoint/it/plugin/cassandra/CassandraDatastaxITBase.java +++ b/agent-module/plugins-it/cassandra-it/cassandra-2-it/src/test/java/com/navercorp/pinpoint/it/plugin/cassandra/CassandraDatastaxITBase.java @@ -28,7 +28,7 @@ import com.navercorp.pinpoint.test.plugin.shared.SharedTestBeforeAllResult; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -63,6 +63,7 @@ public abstract class CassandraDatastaxITBase { private static String CASSANDRA_ADDRESS; private static int PORT; + @AutoClose private static Cluster cluster; @@ -87,13 +88,6 @@ public static void setup() { logger.info("setup cluster {}", CASSANDRA_ADDRESS); } - @AfterAll - public static void tearDown() { - if (cluster != null) { - cluster.close(); - } - } - private static Session openSession(Cluster cluster) { return cluster.connect(TEST_KEYSPACE); diff --git a/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/consumer/DubboConsumerIT.java b/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/consumer/DubboConsumerIT.java index fd10ae090f88..24fd88fdcf8c 100644 --- a/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/consumer/DubboConsumerIT.java +++ b/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/consumer/DubboConsumerIT.java @@ -30,7 +30,7 @@ import com.navercorp.pinpoint.test.plugin.ImportPlugin; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PluginTest; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -57,6 +57,8 @@ public class DubboConsumerIT { private AbstractInvoker abstractClusterInvoker; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -65,11 +67,6 @@ public void setUp() { openMocks = MockitoAnnotations.openMocks(this); } - @AfterEach - public void afterEach() throws Exception { - openMocks.close(); - } - @Test public void testConsumer() throws NoSuchMethodException { abstractClusterInvoker = new MockInvoker<>(Demo.class, url); diff --git a/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/provider/DubboProviderIT.java b/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/provider/DubboProviderIT.java index bbe797915ea2..af53a3251eb6 100644 --- a/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/provider/DubboProviderIT.java +++ b/agent-module/plugins-it/dubbo-it/src/test/java/com/navercorp/pinpoint/it/plugin/dubbo/provider/DubboProviderIT.java @@ -29,7 +29,7 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PluginTest; import com.navercorp.pinpoint.test.plugin.TraceObjectManagable; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -56,6 +56,8 @@ public class DubboProviderIT { public static final String META_PARENT_APPLICATION_TYPE = "_DUBBO_PARENT_APPLICATION_TYPE"; public static final String META_FLAGS = "_DUBBO_FLAGS"; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable testcase; @Mock @@ -83,13 +85,6 @@ public void setUp() { when(rpcInvocation.getAttachment(META_FLAGS)).thenReturn("0"); } - @AfterEach - public void tearDown() throws Exception { - if (testcase != null) { - testcase.close(); - } - } - @Test public void testProvider() { AbstractProxyInvoker abstractProxyInvoker = new AbstractProxyInvoker("", String.class, url) { diff --git a/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_0_x_IT.java b/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_0_x_IT.java index 73bc7140fa00..8a3ac7d6ab4e 100644 --- a/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_0_x_IT.java +++ b/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_0_x_IT.java @@ -30,7 +30,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentType; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -47,6 +47,7 @@ @SharedTestLifeCycleClass(ESServer.class) public class ElasticsearchIT_6_0_x_IT extends ElasticsearchITBase { + @AutoClose private RestHighLevelClient restHighLevelClient; @BeforeEach @@ -58,13 +59,6 @@ public void setup() { restHighLevelClient = new RestHighLevelClient(option.build()); } - @AfterEach - public void tearDown() throws IOException { - if (restHighLevelClient != null) { - restHighLevelClient.close(); - } - } - @Test public void testCRUD() throws Exception { diff --git a/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_4_x_IT.java b/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_4_x_IT.java index efa34d2996f4..71abaef34690 100644 --- a/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_4_x_IT.java +++ b/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_6_4_x_IT.java @@ -30,7 +30,7 @@ import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentType; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,6 +46,7 @@ @SharedTestLifeCycleClass(ESServer.class) public class ElasticsearchIT_6_4_x_IT extends ElasticsearchITBase { + @AutoClose private static RestHighLevelClient restHighLevelClient; @BeforeEach @@ -56,13 +57,6 @@ public void setup() { restHighLevelClient = new RestHighLevelClient(option.build()); } - @AfterEach - public void tearDown() throws IOException { - if (restHighLevelClient != null) { - restHighLevelClient.close(); - } - } - @Test public void testCRUD() throws Exception { diff --git a/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_0_x_IT.java b/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_0_x_IT.java index 971ff236b42e..c7f4d42a6233 100644 --- a/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_0_x_IT.java +++ b/agent-module/plugins-it/elasticsearch-it/elasticsearch-6-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_0_x_IT.java @@ -30,7 +30,7 @@ import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentType; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,6 +46,7 @@ @SharedTestLifeCycleClass(ESServer.class) public class ElasticsearchIT_7_0_x_IT extends ElasticsearchITBase { + @AutoClose private static RestHighLevelClient restHighLevelClient; @BeforeEach @@ -58,14 +59,6 @@ public void setup() { restHighLevelClient = new RestHighLevelClient(option.build()); } - @AfterEach - public void tearDown() throws IOException { - if (restHighLevelClient != null) { - restHighLevelClient.close(); - } - } - - @Test public void testHighLevelClient() throws Exception { diff --git a/agent-module/plugins-it/elasticsearch-it/elasticsearch-7-16-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_16_x_IT.java b/agent-module/plugins-it/elasticsearch-it/elasticsearch-7-16-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_16_x_IT.java index b7ac08d919da..206e2a8f0c4a 100644 --- a/agent-module/plugins-it/elasticsearch-it/elasticsearch-7-16-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_16_x_IT.java +++ b/agent-module/plugins-it/elasticsearch-it/elasticsearch-7-16-it/src/test/java/com/navercorp/pinpoint/it/plugin/elasticsearch/ElasticsearchIT_7_16_x_IT.java @@ -33,7 +33,7 @@ import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.xcontent.XContentType; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,6 +50,7 @@ @SuppressWarnings("deprecation") public class ElasticsearchIT_7_16_x_IT extends ElasticsearchITBase { + @AutoClose private RestHighLevelClient restHighLevelClient; @BeforeEach @@ -58,13 +59,6 @@ public void setup() { RestClient.builder(new HttpHost(getEsHost(), getEsPort(), "http"))); } - @AfterEach - public void tearDown() throws IOException { - if (restHighLevelClient != null) { - restHighLevelClient.close(); - } - } - @Test public void testHighLevelClient() throws Exception { diff --git a/agent-module/plugins-it/google-httpclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/google/httpclient/HttpRequestIT.java b/agent-module/plugins-it/google-httpclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/google/httpclient/HttpRequestIT.java index a6b62dee1fbf..d0eaf8a6259c 100644 --- a/agent-module/plugins-it/google-httpclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/google/httpclient/HttpRequestIT.java +++ b/agent-module/plugins-it/google-httpclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/google/httpclient/HttpRequestIT.java @@ -31,7 +31,7 @@ import com.navercorp.pinpoint.test.plugin.Dependency; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PluginTest; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -49,7 +49,7 @@ // google-http-client 1.26.0 does not include repackaged guava @Dependency({"com.google.http-client:google-http-client:[1.40.0,]", "com.google.guava:guava:20.0", PluginITConstants.VERSION, WebServer.VERSION}) public class HttpRequestIT { - + @AutoClose("stop") private static WebServer webServer; @BeforeAll @@ -57,11 +57,6 @@ public static void BeforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void AfterClass() throws Exception { - webServer = WebServer.cleanup(webServer); - } - @Test public void execute() throws Exception { HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport(); diff --git a/agent-module/plugins-it/hbase-it/src/test/java/com/navercorp/pinpoint/it/plugin/hbase/HbaseClientIT.java b/agent-module/plugins-it/hbase-it/src/test/java/com/navercorp/pinpoint/it/plugin/hbase/HbaseClientIT.java index de95af682615..0de9ad45d89f 100644 --- a/agent-module/plugins-it/hbase-it/src/test/java/com/navercorp/pinpoint/it/plugin/hbase/HbaseClientIT.java +++ b/agent-module/plugins-it/hbase-it/src/test/java/com/navercorp/pinpoint/it/plugin/hbase/HbaseClientIT.java @@ -33,7 +33,7 @@ import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -56,6 +56,8 @@ public class HbaseClientIT { private final String tableName = "Table"; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -63,11 +65,6 @@ public void beforeEach() { openMocks = MockitoAnnotations.openMocks(this); } - @AfterEach - public void after() throws Exception { - openMocks.close(); - } - @Test @SuppressWarnings("deprecation") public void testAdmin() throws Exception { diff --git a/agent-module/plugins-it/httpclient-it/httpclient-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient3/HttpClientIT.java b/agent-module/plugins-it/httpclient-it/httpclient-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient3/HttpClientIT.java index 95bc6be511c5..10504a2ca7f8 100644 --- a/agent-module/plugins-it/httpclient-it/httpclient-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient3/HttpClientIT.java +++ b/agent-module/plugins-it/httpclient-it/httpclient-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient3/HttpClientIT.java @@ -30,7 +30,7 @@ import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -45,6 +45,7 @@ public class HttpClientIT { private static final String VERSION = JDBCTestConstants.VERSION; + @AutoClose("stop") public static WebServer webServer; @BeforeAll @@ -52,11 +53,6 @@ public static void beforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void afterClass() throws Exception { - webServer = WebServer.cleanup(webServer); - } - public String getAddress() { return webServer.getCallHttpUrl(); } diff --git a/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/ClosableAsyncHttpClientIT.java b/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/ClosableAsyncHttpClientIT.java index 664b5ae2d8e1..31e832976ae4 100644 --- a/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/ClosableAsyncHttpClientIT.java +++ b/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/ClosableAsyncHttpClientIT.java @@ -32,6 +32,7 @@ import org.apache.http.concurrent.BasicFuture; import org.apache.http.concurrent.FutureCallback; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.apache.http.impl.nio.client.HttpAsyncClients; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; @@ -56,10 +57,9 @@ public class ClosableAsyncHttpClientIT extends HttpClientITBase { @Test public void test() throws Exception { - CloseableHttpAsyncClient httpClient = HttpAsyncClients.custom().useSystemProperties().build(); - httpClient.start(); - - try { + HttpAsyncClientBuilder builder = HttpAsyncClients.custom().useSystemProperties(); + try (CloseableHttpAsyncClient httpClient = builder.build()){ + httpClient.start(); HttpPost httpRequest = new HttpPost(getAddress()); List params = new ArrayList<>(); @@ -72,8 +72,6 @@ public void test() throws Exception { if ((response != null) && (response.getEntity() != null)) { EntityUtils.consume(response.getEntity()); } - } finally { - httpClient.close(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); diff --git a/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/HttpClientITBase.java b/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/HttpClientITBase.java index f7ffe199c249..99e48b1aa445 100644 --- a/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/HttpClientITBase.java +++ b/agent-module/plugins-it/httpclient-it/httpclient-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient4/HttpClientITBase.java @@ -17,10 +17,11 @@ package com.navercorp.pinpoint.it.plugin.httpclient4; import com.navercorp.pinpoint.it.plugin.utils.WebServer; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; public abstract class HttpClientITBase { + @AutoClose("stop") public static WebServer webServer; @BeforeAll @@ -29,11 +30,6 @@ public static void beforeClass() throws Exception { } - @AfterAll - public static void afterClass() throws Exception { - webServer = WebServer.cleanup(webServer); - } - public String getAddress() { return webServer.getCallHttpUrl(); } diff --git a/agent-module/plugins-it/httpclient-it/httpclient-5-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient5/HttpClientITBase.java b/agent-module/plugins-it/httpclient-it/httpclient-5-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient5/HttpClientITBase.java index 27d5d002a3e6..700b6c530424 100644 --- a/agent-module/plugins-it/httpclient-it/httpclient-5-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient5/HttpClientITBase.java +++ b/agent-module/plugins-it/httpclient-it/httpclient-5-it/src/test/java/com/navercorp/pinpoint/it/plugin/httpclient5/HttpClientITBase.java @@ -17,10 +17,11 @@ package com.navercorp.pinpoint.it.plugin.httpclient5; import com.navercorp.pinpoint.it.plugin.utils.WebServer; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; public abstract class HttpClientITBase { + @AutoClose("stop") public static WebServer webServer; @BeforeAll @@ -29,11 +30,6 @@ public static void beforeClass() throws Exception { } - @AfterAll - public static void afterClass() throws Exception { - webServer = WebServer.cleanup(webServer); - } - public String getAddress() { return webServer.getCallHttpUrl(); } diff --git a/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapClientTemplateIT.java b/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapClientTemplateIT.java index 180d06d5f918..d226baa4c1e1 100644 --- a/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapClientTemplateIT.java +++ b/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapClientTemplateIT.java @@ -28,7 +28,7 @@ import com.navercorp.pinpoint.test.plugin.Dependency; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PluginTest; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -71,6 +71,8 @@ public SessionScope beginSessionScope() { private SqlMapClient sqlMapClient; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -80,11 +82,6 @@ public void beforeEach() { this.sqlMapClient = new SqlMapClientImpl(this.mockSqlMapExecutorDelegate); } - @AfterEach - public void afterEach() throws Exception { - openMocks.close(); - } - @Test public void methodCallWithNullSqlIdShouldOnlyTraceMethodName() throws Exception { // Given diff --git a/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapExecutorTestBase.java b/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapExecutorTestBase.java index 97a8ffe2ecd8..54d1f74ea328 100644 --- a/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapExecutorTestBase.java +++ b/agent-module/plugins-it/ibatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/ibatis/SqlMapExecutorTestBase.java @@ -22,7 +22,7 @@ import com.navercorp.pinpoint.bootstrap.plugin.test.Expectations; import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier; import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifierHolder; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -50,6 +50,8 @@ public SessionScope beginSessionScope() { @Mock private SessionScope mockSessionScope; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -58,11 +60,6 @@ public void beforeEach() { when(this.mockSqlMapExecutorDelegate.beginSessionScope()).thenReturn(this.mockSessionScope); } - @AfterEach - public void afterEach() throws Exception { - openMocks.close(); - } - protected final void testAndVerifyInsertWithNullSqlId(SqlMapExecutor executor) throws Exception { executor.insert(null); diff --git a/agent-module/plugins-it/jdk-http-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdk/http/HttpURLConnectionIT.java b/agent-module/plugins-it/jdk-http-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdk/http/HttpURLConnectionIT.java index 735a6f4ade6b..407f8d3482ba 100644 --- a/agent-module/plugins-it/jdk-http-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdk/http/HttpURLConnectionIT.java +++ b/agent-module/plugins-it/jdk-http-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdk/http/HttpURLConnectionIT.java @@ -25,7 +25,7 @@ import com.navercorp.pinpoint.test.plugin.JvmVersion; import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PluginForkedTest; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -48,6 +48,7 @@ @JvmArgument("-Dprofiler.http.record.response.headers=Connection") public class HttpURLConnectionIT { + @AutoClose("stop") private static WebServer webServer; @BeforeAll @@ -55,11 +56,6 @@ public static void BeforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void AfterClass() throws Exception { - webServer = WebServer.cleanup(webServer); - } - @Test public void test() throws Exception { URL url = new URL(webServer.getCallHttpUrl()); diff --git a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_0_x_IT.java b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_0_x_IT.java index 8f1830c703cb..33b768493953 100644 --- a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_0_x_IT.java +++ b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_0_x_IT.java @@ -30,7 +30,7 @@ import com.navercorp.pinpoint.test.plugin.PluginTest; import com.navercorp.pinpoint.test.plugin.shared.SharedDependency; import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -49,6 +49,7 @@ @SharedTestLifeCycleClass(MongodbServer.class) public class MongoDBIT_3_0_x_IT extends MongoDBITBase { + @AutoClose private static com.mongodb.MongoClient mongoClient; private static MongoDatabase database; private static URI uri; @@ -61,13 +62,6 @@ public static void setUpBeforeClass() throws Exception { database = mongoClient.getDatabase("myMongoDbFake").withReadPreference(ReadPreference.secondaryPreferred()).withWriteConcern(WriteConcern.MAJORITY); } - @AfterAll - public static void cleanAfterClass() throws Exception { - if (mongoClient != null) { - mongoClient.close(); - } - } - @Override Class getMongoDatabaseClazz() throws ClassNotFoundException { return Class.forName("com.mongodb.MongoCollectionImpl"); diff --git a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_2_x_IT.java b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_2_x_IT.java index 4e265b80b110..3a1fca40400a 100644 --- a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_2_x_IT.java +++ b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_2_x_IT.java @@ -29,7 +29,7 @@ import com.navercorp.pinpoint.test.plugin.PluginTest; import com.navercorp.pinpoint.test.plugin.shared.SharedDependency; import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -48,6 +48,7 @@ @SharedTestLifeCycleClass(MongodbServer.class) public class MongoDBIT_3_2_x_IT extends MongoDBITBase { + @AutoClose private static com.mongodb.MongoClient mongoClient; private static MongoDatabase database; private static URI uri; @@ -60,13 +61,6 @@ public static void setUpBeforeClass() throws Exception { database = mongoClient.getDatabase("myMongoDbFake").withReadPreference(ReadPreference.secondaryPreferred()).withWriteConcern(WriteConcern.MAJORITY); } - @AfterAll - public static void cleanAfterClass() throws Exception { - if (mongoClient != null) { - mongoClient.close(); - } - } - @Override Class getMongoDatabaseClazz() throws ClassNotFoundException { return Class.forName("com.mongodb.MongoCollectionImpl"); diff --git a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_4_x_IT.java b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_4_x_IT.java index 1cab9808e01b..db33193f2597 100644 --- a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_4_x_IT.java +++ b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_4_x_IT.java @@ -29,7 +29,7 @@ import com.navercorp.pinpoint.test.plugin.PluginTest; import com.navercorp.pinpoint.test.plugin.shared.SharedDependency; import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -48,6 +48,7 @@ @SharedTestLifeCycleClass(MongodbServer.class) public class MongoDBIT_3_4_x_IT extends MongoDBITBase { + @AutoClose private static com.mongodb.MongoClient mongoClient; private static MongoDatabase database; private static URI uri; @@ -60,13 +61,6 @@ public static void setUpBeforeClass() throws Exception { database = mongoClient.getDatabase("myMongoDbFake").withReadPreference(ReadPreference.secondaryPreferred()).withWriteConcern(WriteConcern.MAJORITY); } - @AfterAll - public static void cleanAfterClass() throws Exception { - if (mongoClient != null) { - mongoClient.close(); - } - } - @Override Class getMongoDatabaseClazz() throws ClassNotFoundException { return Class.forName("com.mongodb.MongoCollectionImpl"); diff --git a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_7_x_IT.java b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_7_x_IT.java index 0b2b93e3d63f..62821716957b 100644 --- a/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_7_x_IT.java +++ b/agent-module/plugins-it/mongodb-it/mongodb-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb/MongoDBIT_3_7_x_IT.java @@ -31,7 +31,7 @@ import com.navercorp.pinpoint.test.plugin.PluginTest; import com.navercorp.pinpoint.test.plugin.shared.SharedDependency; import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -49,6 +49,7 @@ @SharedDependency({PluginITConstants.VERSION, JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MONGODB}) @SharedTestLifeCycleClass(MongodbServer.class) public class MongoDBIT_3_7_x_IT extends MongoDBITBase { + @AutoClose private static MongoClient mongoClient; private static MongoDatabase database; private static URI uri; @@ -61,13 +62,6 @@ public static void setUpBeforeClass() throws Exception { database = mongoClient.getDatabase("myMongoDbFake").withReadPreference(ReadPreference.secondaryPreferred()).withWriteConcern(WriteConcern.MAJORITY); } - @AfterAll - public static void cleanAfterClass() throws Exception { - if (mongoClient != null) { - mongoClient.close(); - } - } - @Override Class getMongoDatabaseClazz() throws ClassNotFoundException { return Class.forName("com.mongodb.client.internal.MongoCollectionImpl"); diff --git a/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/MongoDBIT_4_0_x_IT.java b/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/MongoDBIT_4_0_x_IT.java index aa48c786837b..6858ace5301c 100644 --- a/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/MongoDBIT_4_0_x_IT.java +++ b/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/MongoDBIT_4_0_x_IT.java @@ -32,7 +32,7 @@ import com.navercorp.pinpoint.test.plugin.PluginTest; import com.navercorp.pinpoint.test.plugin.shared.SharedDependency; import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -48,6 +48,7 @@ @SharedDependency({PluginITConstants.VERSION, JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MONGODB}) @SharedTestLifeCycleClass(MongodbServer.class) public class MongoDBIT_4_0_x_IT extends MongoDBITBase { + @AutoClose private static MongoClient mongoClient; private static MongoDatabase database; private static URI uri; @@ -60,13 +61,6 @@ public static void setUpBeforeClass() throws Exception { database = mongoClient.getDatabase("myMongoDbFake").withReadPreference(ReadPreference.secondaryPreferred()).withWriteConcern(WriteConcern.MAJORITY); } - @AfterAll - public static void cleanAfterClass() throws Exception { - if (mongoClient != null) { - mongoClient.close(); - } - } - @Override Class getMongoDatabaseClazz() throws ClassNotFoundException { return Class.forName("com.mongodb.client.internal.MongoCollectionImpl"); diff --git a/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/ReactiveMongoDBIT_4_2_x_IT.java b/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/ReactiveMongoDBIT_4_2_x_IT.java index 8efdbd58eec2..a589e196bc35 100644 --- a/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/ReactiveMongoDBIT_4_2_x_IT.java +++ b/agent-module/plugins-it/mongodb-it/mongodb-4-it/src/test/java/com/navercorp/pinpoint/it/plugin/mongodb4/ReactiveMongoDBIT_4_2_x_IT.java @@ -33,7 +33,7 @@ import com.navercorp.pinpoint.test.plugin.PluginTest; import com.navercorp.pinpoint.test.plugin.shared.SharedDependency; import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycleClass; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -50,6 +50,7 @@ @SharedDependency({PluginITConstants.VERSION, JDBCTestConstants.VERSION, TestcontainersOption.TEST_CONTAINER, TestcontainersOption.MONGODB}) @SharedTestLifeCycleClass(MongodbServer.class) public class ReactiveMongoDBIT_4_2_x_IT extends MongoDBITBase { + @AutoClose private static MongoClient mongoClient; private static MongoDatabase database; private static URI uri; @@ -62,13 +63,6 @@ public static void setUpBeforeClass() throws Exception { database = mongoClient.getDatabase("myMongoDbFake").withReadPreference(ReadPreference.secondaryPreferred()).withWriteConcern(WriteConcern.MAJORITY); } - @AfterAll - public static void cleanAfterClass() throws Exception { - if (mongoClient != null) { - mongoClient.close(); - } - } - @Override Class getMongoDatabaseClazz() throws ClassNotFoundException { return Class.forName("com.mongodb.reactivestreams.client.internal.MongoCollectionImpl"); diff --git a/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/DefaultSqlSessionIT.java b/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/DefaultSqlSessionIT.java index 43da28937295..db21b7a8fa5a 100644 --- a/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/DefaultSqlSessionIT.java +++ b/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/DefaultSqlSessionIT.java @@ -27,7 +27,7 @@ import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.defaults.DefaultSqlSession; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -60,6 +60,8 @@ public class DefaultSqlSessionIT extends SqlSessionTestBase { @Mock private Executor executor; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -69,11 +71,6 @@ public void setUp() { when(this.configuration.getMappedStatement(anyString())).thenReturn(mappedStatement); } - @AfterEach - public void afterEach() throws Exception { - openMocks.close(); - } - @Override protected SqlSession getSqlSession() { return new DefaultSqlSession(this.configuration, this.executor, false); diff --git a/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/SqlSessionTemplateITBase.java b/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/SqlSessionTemplateITBase.java index e4a59a10b88f..b684c59a0f9f 100644 --- a/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/SqlSessionTemplateITBase.java +++ b/agent-module/plugins-it/mybatis-it/src/test/java/com/navercorp/pinpoint/it/plugin/mybatis/SqlSessionTemplateITBase.java @@ -22,7 +22,7 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.transaction.TransactionFactory; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -51,6 +51,8 @@ public class SqlSessionTemplateITBase extends SqlSessionTestBase { private SqlSessionTemplate sqlSessionTemplate; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -66,11 +68,6 @@ public void setUp() throws Exception { this.sqlSessionTemplate = new SqlSessionTemplate(this.sqlSessionFactory, EXECUTOR_TYPE); } - @AfterEach - public void afterEach() throws Exception { - openMocks.close(); - } - @Override protected SqlSession getSqlSession() { return this.sqlSessionTemplate; diff --git a/agent-module/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/mysql/MySql_IT_Base.java b/agent-module/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/mysql/MySql_IT_Base.java index 07e705c1077b..966e2d523941 100644 --- a/agent-module/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/mysql/MySql_IT_Base.java +++ b/agent-module/plugins-it/mysql-jdbc-driver-plugin-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/mysql/MySql_IT_Base.java @@ -58,7 +58,7 @@ public void before() throws Exception { } @AfterEach - public void after() throws Exception { + public void after() { DriverManagerUtils.deregisterDriver(); } diff --git a/agent-module/plugins-it/netty-it/src/test/java/com/navercorp/pinpoint/it/plugin/netty/NettyIT.java b/agent-module/plugins-it/netty-it/src/test/java/com/navercorp/pinpoint/it/plugin/netty/NettyIT.java index ce3480952c59..d236ddde63f9 100644 --- a/agent-module/plugins-it/netty-it/src/test/java/com/navercorp/pinpoint/it/plugin/netty/NettyIT.java +++ b/agent-module/plugins-it/netty-it/src/test/java/com/navercorp/pinpoint/it/plugin/netty/NettyIT.java @@ -41,7 +41,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpVersion; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -57,6 +57,7 @@ @PinpointConfig("pinpoint-netty-plugin-test.config") public class NettyIT { + @AutoClose("stop") private static WebServer webServer; @BeforeAll @@ -64,11 +65,6 @@ public static void BeforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void AfterClass() { - webServer = WebServer.cleanup(webServer); - } - @Test public void listenerTest() throws Exception { final CountDownLatch awaitLatch = new CountDownLatch(1); diff --git a/agent-module/plugins-it/ning-asyncclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java b/agent-module/plugins-it/ning-asyncclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java index 584dfb551ae9..d269794b7aa5 100644 --- a/agent-module/plugins-it/ning-asyncclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java +++ b/agent-module/plugins-it/ning-asyncclient-it/src/test/java/com/navercorp/pinpoint/it/plugin/ning/asynchttpclient/NingAsyncHttpClientIT.java @@ -29,7 +29,7 @@ import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.Request; import com.ning.http.client.Response; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -48,6 +48,7 @@ @ImportPlugin({"com.navercorp.pinpoint:pinpoint-ning-asynchttpclient-plugin"}) public class NingAsyncHttpClientIT { + @AutoClose("stop") private static WebServer webServer; @BeforeAll @@ -55,11 +56,6 @@ public static void BeforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void AfterClass() { - webServer = WebServer.cleanup(webServer); - } - @Test public void test() throws Exception { AsyncHttpClient client = new AsyncHttpClient(); diff --git a/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_2_x_IT.java b/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_2_x_IT.java index 9c9900e096c9..36480d03bc59 100644 --- a/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_2_x_IT.java +++ b/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_2_x_IT.java @@ -33,8 +33,8 @@ import com.squareup.okhttp.Request; import com.squareup.okhttp.Response; import com.squareup.okhttp.internal.http.HttpEngine; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -61,20 +61,14 @@ public class OkHttpClient_2_x_IT { static final String OK_HTTP_CLIENT = "OK_HTTP_CLIENT"; static final String OK_HTTP_CLIENT_INTERNAL = "OK_HTTP_CLIENT_INTERNAL"; + @AutoClose("stop") private static WebServer webServer; - @BeforeAll public static void BeforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - - @AfterAll - public static void AfterClass() { - webServer = WebServer.cleanup(webServer); - } - @Test public void execute() throws Exception { Request request = new Request.Builder().url(webServer.getCallHttpUrl()).build(); diff --git a/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_0_0_to_3_3_x_IT.java b/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_0_0_to_3_3_x_IT.java index 7958463a3953..efdcde400418 100644 --- a/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_0_0_to_3_3_x_IT.java +++ b/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_0_0_to_3_3_x_IT.java @@ -29,7 +29,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -54,6 +54,7 @@ public class OkHttpClient_3_0_0_to_3_3_x_IT { static final String OK_HTTP_CLIENT = "OK_HTTP_CLIENT"; static final String OK_HTTP_CLIENT_INTERNAL = "OK_HTTP_CLIENT_INTERNAL"; + @AutoClose("stop") private static WebServer webServer; @@ -63,11 +64,6 @@ public static void BeforeClass() throws Exception { } - @AfterAll - public static void AfterClass() { - webServer = WebServer.cleanup(webServer); - } - @Test public void execute() throws Exception { Request request = new Request.Builder().url(webServer.getCallHttpUrl()).build(); diff --git a/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_4_0_BaseIT.java b/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_4_0_BaseIT.java index a8a1ab6947c7..b6cb7d8d356c 100644 --- a/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_4_0_BaseIT.java +++ b/agent-module/plugins-it/okhttp-it/src/test/java/com/navercorp/pinpoint/it/plugin/okhttp/OkHttpClient_3_4_0_BaseIT.java @@ -24,7 +24,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -43,6 +43,7 @@ public abstract class OkHttpClient_3_4_0_BaseIT { static final String OK_HTTP_CLIENT = "OK_HTTP_CLIENT"; static final String OK_HTTP_CLIENT_INTERNAL = "OK_HTTP_CLIENT_INTERNAL"; + @AutoClose("stop") private static WebServer webServer; @BeforeAll @@ -50,11 +51,6 @@ public static void BeforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void AfterClass() { - webServer = WebServer.cleanup(webServer); - } - @Test public void execute() throws Exception { Request request = new Request.Builder().url(webServer.getCallHttpUrl()).build(); diff --git a/agent-module/plugins-it/paho-mqtt-it/src/test/java/com/navercorp/pinpoint/it/plugin/paho/mqtt/PahoMqttV5ClientIT.java b/agent-module/plugins-it/paho-mqtt-it/src/test/java/com/navercorp/pinpoint/it/plugin/paho/mqtt/PahoMqttV5ClientIT.java index c12929372301..27341c544a7b 100644 --- a/agent-module/plugins-it/paho-mqtt-it/src/test/java/com/navercorp/pinpoint/it/plugin/paho/mqtt/PahoMqttV5ClientIT.java +++ b/agent-module/plugins-it/paho-mqtt-it/src/test/java/com/navercorp/pinpoint/it/plugin/paho/mqtt/PahoMqttV5ClientIT.java @@ -89,6 +89,8 @@ private static void subscribe() throws MqttException { @AfterAll public static void after() throws MqttException { mqttClient.disconnect(); + + container.stop(); } @Test diff --git a/agent-module/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/postgresql/PostgreSQLConnectionIT.java b/agent-module/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/postgresql/PostgreSQLConnectionIT.java index 47127117f93e..79b1323cd542 100644 --- a/agent-module/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/postgresql/PostgreSQLConnectionIT.java +++ b/agent-module/plugins-it/postgresql-jdbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/postgresql/PostgreSQLConnectionIT.java @@ -32,10 +32,10 @@ import com.navercorp.pinpoint.test.plugin.PluginTest; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -65,6 +65,7 @@ public class PostgreSQLConnectionIT { private static final Logger logger = LogManager.getLogger(PostgreSQLConnectionIT.class); + @AutoClose("stop") public static JdbcDatabaseContainer container = PostgreSQLContainerFactory.newContainer(logger.getName()); private static final JDBCDriverClass driverClass = new PostgreSql_9_4_1207_JDBCDriverClass(); @@ -75,11 +76,6 @@ public static void beforeClass() { container.start(); } - @AfterAll - public static void afterClass() { - container.stop(); - } - @BeforeEach public void before() throws Exception { Driver driver = driverClass.newDriver(); @@ -88,7 +84,7 @@ public void before() throws Exception { @AfterEach - public void deregisterDriver() throws Exception { + public void deregisterDriver() { DriverManagerUtils.deregisterDriver(); } diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbitTestRunner.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbitTestRunner.java index 41d1077a3c62..23f92a85a9f0 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbitTestRunner.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbitTestRunner.java @@ -21,11 +21,13 @@ import com.navercorp.pinpoint.it.plugin.rabbitmq.util.RabbitMQTestConstants; import org.junit.jupiter.api.Assertions; import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.testcontainers.shaded.com.google.common.util.concurrent.Uninterruptibles; import test.pinpoint.plugin.rabbitmq.MessageConverter; import test.pinpoint.plugin.rabbitmq.spring.TestMessageHolder; import test.pinpoint.plugin.rabbitmq.spring.service.TestReceiverService; import test.pinpoint.plugin.rabbitmq.spring.service.TestSenderService; +import java.time.Duration; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -56,11 +58,11 @@ public String getRemoteAddress() { return remoteAddress; } - public PluginTestVerifier runPush(int expectedTraceCount) throws InterruptedException { + public PluginTestVerifier runPush(int expectedTraceCount) { final String message = "hello rabbit mq"; testSenderService.sendMessage(RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PUSH, message); - Assertions.assertEquals(testMessageHolder.getMessage(10, TimeUnit.SECONDS), message); + Assertions.assertEquals(message, testMessageHolder.getMessage(10, TimeUnit.SECONDS)); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); // Wait till all traces are recorded (consumer traces are recorded from another thread) @@ -72,7 +74,7 @@ public PluginTestVerifier runPull(int expectedTraceCount) throws InterruptedExce final String message = "hello rabbit mq!"; testSenderService.sendMessage(RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PULL, message); - Assertions.assertEquals(testReceiverService.receiveMessage(MessageConverter.FOR_TEST), message); + Assertions.assertEquals(message, testReceiverService.receiveMessage(MessageConverter.FOR_TEST)); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); // Wait till all traces are recorded (consumer traces are recorded from another thread) @@ -84,7 +86,7 @@ public PluginTestVerifier runPull(int expectedTraceCount, long timeoutMs) throws final String message = "hello rabbit mq!"; testSenderService.sendMessage(RabbitMQTestConstants.EXCHANGE, RabbitMQTestConstants.ROUTING_KEY_PULL, message); - Assertions.assertEquals(testReceiverService.receiveMessage(MessageConverter.FOR_TEST, timeoutMs), message); + Assertions.assertEquals(message, testReceiverService.receiveMessage(MessageConverter.FOR_TEST, timeoutMs)); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); // Wait till all traces are recorded (consumer traces are recorded from another thread) @@ -92,12 +94,9 @@ public PluginTestVerifier runPull(int expectedTraceCount, long timeoutMs) throws return verifier; } - private static void awaitAndVerifyTraceCount(PluginTestVerifier verifier, int expectedTraceCount, long maxWaitMs) throws InterruptedException { + private static void awaitAndVerifyTraceCount(PluginTestVerifier verifier, int expectedTraceCount, long maxWaitMs) { final long waitIntervalMs = 100L; - long maxWaitTime = maxWaitMs; - if (maxWaitMs < waitIntervalMs) { - maxWaitTime = waitIntervalMs; - } + long maxWaitTime = Math.max(maxWaitMs, waitIntervalMs); long startTime = System.currentTimeMillis(); try { while (System.currentTimeMillis() - startTime < maxWaitTime) { @@ -106,7 +105,7 @@ private static void awaitAndVerifyTraceCount(PluginTestVerifier verifier, int ex return; } catch (AssertionError e) { // ignore and retry - Thread.sleep(waitIntervalMs); + Uninterruptibles.sleepUninterruptibly(Duration.ofMillis(waitIntervalMs)); } } verifier.verifyTraceCount(expectedTraceCount); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_3_3_to_1_4_2_IT.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_3_3_to_1_4_2_IT.java index 85db6d23043a..029a8a28bc5d 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_3_3_to_1_4_2_IT.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_3_3_to_1_4_2_IT.java @@ -37,7 +37,7 @@ import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.impl.AMQCommand; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -62,6 +62,7 @@ @SharedTestLifeCycleClass(TestBrokerServer.class) public class SpringAmqpRabbit_1_3_3_to_1_4_2_IT extends SpringAmqpRabbitITBase { + @AutoClose private static final TestApplicationContext CONTEXT = new TestApplicationContext(); private final SpringAmqpRabbitTestRunner testRunner = new SpringAmqpRabbitTestRunner(CONTEXT); @@ -74,11 +75,6 @@ public static void setUpBeforeClass() throws Exception { ReceiverConfig_Pre_1_6_0.class); } - @AfterAll - public static void tearDownAfterClass() { - CONTEXT.close(); - } - @Test public void testPush() throws Exception { final String remoteAddress = testRunner.getRemoteAddress(); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_4_2_to_1_7_0_IT.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_4_2_to_1_7_0_IT.java index eb38fd51ba42..e803711e788a 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_4_2_to_1_7_0_IT.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_4_2_to_1_7_0_IT.java @@ -37,7 +37,7 @@ import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.impl.AMQCommand; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -63,6 +63,7 @@ @SharedTestLifeCycleClass(TestBrokerServer.class) public class SpringAmqpRabbit_1_4_2_to_1_7_0_IT extends SpringAmqpRabbitITBase { + @AutoClose private static final TestApplicationContext CONTEXT = new TestApplicationContext(); private final SpringAmqpRabbitTestRunner testRunner = new SpringAmqpRabbitTestRunner(CONTEXT); @@ -75,11 +76,6 @@ public static void setUpBeforeClass() throws Exception { ReceiverConfig_Pre_1_6_0.class); } - @AfterAll - public static void tearDownAfterClass() { - CONTEXT.close(); - } - @Test public void testPush() throws Exception { final String remoteAddress = testRunner.getRemoteAddress(); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_0_to_1_7_7_IT.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_0_to_1_7_7_IT.java index 639b9337272f..81f3f1dd95b7 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_0_to_1_7_7_IT.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_0_to_1_7_7_IT.java @@ -37,7 +37,7 @@ import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.impl.AMQCommand; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -62,6 +62,7 @@ @SharedTestLifeCycleClass(TestBrokerServer.class) public class SpringAmqpRabbit_1_7_0_to_1_7_7_IT extends SpringAmqpRabbitITBase { + @AutoClose private static final TestApplicationContext CONTEXT = new TestApplicationContext(); private final SpringAmqpRabbitTestRunner testRunner = new SpringAmqpRabbitTestRunner(CONTEXT); @@ -74,11 +75,6 @@ public static void setUpBeforeClass() throws Exception { ReceiverConfig_Post_1_6_0.class); } - @AfterAll - public static void tearDownAfterClass() { - CONTEXT.close(); - } - @Test public void testPush() throws Exception { final String remoteAddress = testRunner.getRemoteAddress(); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_7_to_2_0_0_IT.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_7_to_2_0_0_IT.java index 4900d0451043..935d82283502 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_7_to_2_0_0_IT.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_1_7_7_to_2_0_0_IT.java @@ -37,7 +37,7 @@ import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.impl.AMQCommand; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -65,6 +65,7 @@ @SharedTestLifeCycleClass(TestBrokerServer.class) public class SpringAmqpRabbit_1_7_7_to_2_0_0_IT extends SpringAmqpRabbitITBase { + @AutoClose private static final TestApplicationContext CONTEXT = new TestApplicationContext(); private final SpringAmqpRabbitTestRunner testRunner = new SpringAmqpRabbitTestRunner(CONTEXT); @@ -77,11 +78,6 @@ public static void setUpBeforeClass() throws Exception { ReceiverConfig_Post_1_6_0.class); } - @AfterAll - public static void tearDownAfterClass() { - CONTEXT.close(); - } - @Test public void testPush() throws Exception { final String remoteAddress = testRunner.getRemoteAddress(); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_0_to_2_0_3_IT.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_0_to_2_0_3_IT.java index 837e664c2d5a..0b12ae8549a5 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_0_to_2_0_3_IT.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_0_to_2_0_3_IT.java @@ -38,7 +38,7 @@ import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.impl.AMQCommand; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -72,6 +72,7 @@ @SharedTestLifeCycleClass(TestBrokerServer.class) public class SpringAmqpRabbit_2_0_0_to_2_0_3_IT extends SpringAmqpRabbitITBase { + @AutoClose private static final TestApplicationContext CONTEXT = new TestApplicationContext(); private final SpringAmqpRabbitTestRunner testRunner = new SpringAmqpRabbitTestRunner(CONTEXT); @@ -84,11 +85,6 @@ public static void setUpBeforeClass() throws Exception { ReceiverConfig_Post_1_6_0.class); } - @AfterAll - public static void tearDownAfterClass() { - CONTEXT.close(); - } - @Test public void testPush() throws Exception { final String remoteAddress = testRunner.getRemoteAddress(); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_3_to_2_1_0_IT.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_3_to_2_1_0_IT.java index 8a2167809d3d..0067a0dcef87 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_3_to_2_1_0_IT.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_0_3_to_2_1_0_IT.java @@ -38,7 +38,7 @@ import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.impl.AMQCommand; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -71,6 +71,7 @@ @SharedTestLifeCycleClass(TestBrokerServer.class) public class SpringAmqpRabbit_2_0_3_to_2_1_0_IT extends SpringAmqpRabbitITBase { + @AutoClose private static final TestApplicationContext CONTEXT = new TestApplicationContext(); private final SpringAmqpRabbitTestRunner testRunner = new SpringAmqpRabbitTestRunner(CONTEXT); @@ -83,11 +84,6 @@ public static void setUpBeforeClass() throws Exception { ReceiverConfig_Post_1_6_0.class); } - @AfterAll - public static void tearDownAfterClass() { - CONTEXT.close(); - } - @Test public void testPush() throws Exception { final String remoteAddress = testRunner.getRemoteAddress(); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_1_x_to_2_x_IT.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_1_x_to_2_x_IT.java index 0ba0cf011073..05454e21b593 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_1_x_to_2_x_IT.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/com/navercorp/pinpoint/it/plugin/rabbitmq/spring/SpringAmqpRabbit_2_1_x_to_2_x_IT.java @@ -38,7 +38,7 @@ import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.impl.AMQCommand; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.amqp.core.Message; @@ -70,6 +70,7 @@ @SharedTestLifeCycleClass(TestBrokerServer.class) public class SpringAmqpRabbit_2_1_x_to_2_x_IT extends SpringAmqpRabbitITBase { + @AutoClose private static final TestApplicationContext CONTEXT = new TestApplicationContext(); private final SpringAmqpRabbitTestRunner testRunner = new SpringAmqpRabbitTestRunner(CONTEXT); @@ -82,11 +83,6 @@ public static void setUpBeforeClass() throws Exception { ReceiverConfig_Post_1_6_0.class); } - @AfterAll - public static void tearDownAfterClass() { - CONTEXT.close(); - } - @Test public void testPush() throws Exception { final String remoteAddress = testRunner.getRemoteAddress(); diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/TestMessageHolder.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/TestMessageHolder.java index 088a885a42e8..c48776dc9685 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/TestMessageHolder.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/TestMessageHolder.java @@ -31,7 +31,12 @@ public void addMessage(String message) { messages.add(message); } - public String getMessage(long timeoutMs, TimeUnit unit) throws InterruptedException { - return messages.poll(timeoutMs, unit); + public String getMessage(long timeoutMs, TimeUnit unit) { + try { + return messages.poll(timeoutMs, unit); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return null; + } } } diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver.java index 48d948377cdc..d0d218468e47 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver.java @@ -25,5 +25,5 @@ public interface TestReceiver { T receiveMessage(String queueName, MessageConverter messageConverter); - T receiveMessage(String queueName, MessageConverter messageConverter, long timeoutMs) throws InterruptedException; + T receiveMessage(String queueName, MessageConverter messageConverter, long timeoutMs); } diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Post_1_6_0.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Post_1_6_0.java index ed242468b5d6..fffafab7024d 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Post_1_6_0.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Post_1_6_0.java @@ -40,7 +40,7 @@ public T receiveMessage(String queueName, MessageConverter messageConvert } @Override - public T receiveMessage(String queueName, MessageConverter messageConverter, long timeoutMs) throws InterruptedException { + public T receiveMessage(String queueName, MessageConverter messageConverter, long timeoutMs) { Message message = rabbitTemplate.receive(queueName, timeoutMs); return convertMessage(messageConverter, message); } diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Pre_1_6_0.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Pre_1_6_0.java index ada53c7d101c..a18ebc1fe5bc 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Pre_1_6_0.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/receiver/TestReceiver_Pre_1_6_0.java @@ -44,7 +44,7 @@ public T receiveMessage(String queueName, MessageConverter messageConvert } @Override - public T receiveMessage(String queueName, MessageConverter messageConverter, long timeoutMs) throws InterruptedException { + public T receiveMessage(String queueName, MessageConverter messageConverter, long timeoutMs) { // RabbitTemplate.receive with timeout is only available from 1.6.0+ // We could instead utilize RabbitTemplate.setReceiveTimeout, but it's just the same thing as above for // trace verification purposes. diff --git a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/service/TestReceiverService.java b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/service/TestReceiverService.java index 9991c9056437..d9c0f5581411 100644 --- a/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/service/TestReceiverService.java +++ b/agent-module/plugins-it/rabbitmq-it/src/test/java/test/pinpoint/plugin/rabbitmq/spring/service/TestReceiverService.java @@ -49,7 +49,7 @@ public T receiveMessage(MessageConverter messageConverter) { return message; } - public T receiveMessage(MessageConverter messageConverter, long timeoutMs) throws InterruptedException { + public T receiveMessage(MessageConverter messageConverter, long timeoutMs) { T message = testReceiver.receiveMessage(RabbitMQTestConstants.QUEUE_PULL, messageConverter, timeoutMs); if (message == null) { return null; diff --git a/agent-module/plugins-it/redis-lettuce-it/src/test/java/com/navercorp/pinpoint/it/plugin/lettuce/RedisClient_IT.java b/agent-module/plugins-it/redis-lettuce-it/src/test/java/com/navercorp/pinpoint/it/plugin/lettuce/RedisClient_IT.java index 539746ba7738..ce04424091e7 100644 --- a/agent-module/plugins-it/redis-lettuce-it/src/test/java/com/navercorp/pinpoint/it/plugin/lettuce/RedisClient_IT.java +++ b/agent-module/plugins-it/redis-lettuce-it/src/test/java/com/navercorp/pinpoint/it/plugin/lettuce/RedisClient_IT.java @@ -36,7 +36,7 @@ import io.lettuce.core.api.sync.RedisCommands; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -58,6 +58,7 @@ public class RedisClient_IT { private static String host; private static int port; + @AutoClose private static RedisClient redisClient; @SharedTestBeforeAllResult @@ -74,13 +75,6 @@ public static void beforeClass() { redisClient = RedisClient.create(url); } - @AfterAll - public static void afterClass() { - if (redisClient != null) { - redisClient.shutdown(); - } - } - @Test public void basic() throws Exception { StatefulRedisConnection connection = redisClient.connect(); diff --git a/agent-module/plugins-it/spring-data-r2dbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/r2dbc/SqlBase.java b/agent-module/plugins-it/spring-data-r2dbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/r2dbc/SqlBase.java index f29e0d905a25..038eef43f573 100644 --- a/agent-module/plugins-it/spring-data-r2dbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/r2dbc/SqlBase.java +++ b/agent-module/plugins-it/spring-data-r2dbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/r2dbc/SqlBase.java @@ -43,11 +43,11 @@ public static DriverProperties getDriverProperties() { } @BeforeEach - public void registerDriver() throws Exception { + public void registerDriver() { } @AfterEach - public void tearDown() throws Exception { + public void tearDown() { } static class JdbcUrlSplitter { diff --git a/agent-module/plugins-it/spring-it/spring-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/spring/web/RestTemplateIT.java b/agent-module/plugins-it/spring-it/spring-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/spring/web/RestTemplateIT.java index 13422d4be01f..9397244b7528 100644 --- a/agent-module/plugins-it/spring-it/spring-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/spring/web/RestTemplateIT.java +++ b/agent-module/plugins-it/spring-it/spring-3-it/src/test/java/com/navercorp/pinpoint/it/plugin/spring/web/RestTemplateIT.java @@ -26,7 +26,7 @@ import com.navercorp.pinpoint.test.plugin.PinpointAgent; import com.navercorp.pinpoint.test.plugin.PinpointConfig; import com.navercorp.pinpoint.test.plugin.PluginTest; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.http.client.AbstractClientHttpRequest; @@ -49,6 +49,7 @@ @ImportPlugin({"com.navercorp.pinpoint:pinpoint-resttemplate-plugin"}) public class RestTemplateIT { + @AutoClose("stop") public static WebServer webServer; @BeforeAll @@ -56,11 +57,6 @@ public static void beforeClass() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void afterClass() throws Exception { - webServer = WebServer.cleanup(webServer); - } - public String getAddress() { return webServer.getCallHttpUrl(); } diff --git a/agent-module/plugins-it/thrift-it/thrift-0-10-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java b/agent-module/plugins-it/thrift-it/thrift-0-10-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java index 114dbd4b601d..5f966d4ed88a 100644 --- a/agent-module/plugins-it/thrift-it/thrift-0-10-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java +++ b/agent-module/plugins-it/thrift-it/thrift-0-10-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java @@ -22,8 +22,7 @@ import com.navercorp.pinpoint.it.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.it.plugin.thrift.common.server.EchoTestServer; import org.apache.thrift.transport.TTransportException; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -35,8 +34,10 @@ */ public abstract class EchoTestRunner { + @AutoClose("shutdown") private static ExecutorService SERVER_EXECUTOR; + @AutoClose("stop") private T echoServer; PluginTestVerifier verifier; @@ -53,18 +54,6 @@ public void setUp() throws TTransportException { this.echoServer.start(SERVER_EXECUTOR); } - @AfterEach - public void tearDown() { - if (this.echoServer != null) { - this.echoServer.stop(); - } - } - - @AfterAll - public static void tearDownAfterClass() { - SERVER_EXECUTOR.shutdown(); - } - protected T getServer() { return echoServer; } diff --git a/agent-module/plugins-it/thrift-it/thrift-0-14-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java b/agent-module/plugins-it/thrift-it/thrift-0-14-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java index 114dbd4b601d..5f966d4ed88a 100644 --- a/agent-module/plugins-it/thrift-it/thrift-0-14-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java +++ b/agent-module/plugins-it/thrift-it/thrift-0-14-it/src/test/java/com/navercorp/pinpoint/it/plugin/thrift/it/EchoTestRunner.java @@ -22,8 +22,7 @@ import com.navercorp.pinpoint.it.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.it.plugin.thrift.common.server.EchoTestServer; import org.apache.thrift.transport.TTransportException; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -35,8 +34,10 @@ */ public abstract class EchoTestRunner { + @AutoClose("shutdown") private static ExecutorService SERVER_EXECUTOR; + @AutoClose("stop") private T echoServer; PluginTestVerifier verifier; @@ -53,18 +54,6 @@ public void setUp() throws TTransportException { this.echoServer.start(SERVER_EXECUTOR); } - @AfterEach - public void tearDown() { - if (this.echoServer != null) { - this.echoServer.stop(); - } - } - - @AfterAll - public static void tearDownAfterClass() { - SERVER_EXECUTOR.shutdown(); - } - protected T getServer() { return echoServer; } diff --git a/agent-module/plugins-test-module/plugins-it-utils/src/main/java/com/navercorp/pinpoint/it/plugin/utils/WebServer.java b/agent-module/plugins-test-module/plugins-it-utils/src/main/java/com/navercorp/pinpoint/it/plugin/utils/WebServer.java index 90def7066a97..bbfd07022fb3 100644 --- a/agent-module/plugins-test-module/plugins-it-utils/src/main/java/com/navercorp/pinpoint/it/plugin/utils/WebServer.java +++ b/agent-module/plugins-test-module/plugins-it-utils/src/main/java/com/navercorp/pinpoint/it/plugin/utils/WebServer.java @@ -45,8 +45,7 @@ public static WebServer cleanup(WebServer webServer) { @Override public Response serve(IHTTPSession session) { Map> parameters = session.getParameters(); - Response response = newFixedLengthResponse(parameters.toString()); - return response; + return newFixedLengthResponse(parameters.toString()); } diff --git a/agent-module/plugins-test-module/plugins-it-utils/src/test/java/com/navercorp/pinpoint/pluginit/utils/WebServerTest.java b/agent-module/plugins-test-module/plugins-it-utils/src/test/java/com/navercorp/pinpoint/pluginit/utils/WebServerTest.java index 0fa002ce339c..085eda9b30b1 100644 --- a/agent-module/plugins-test-module/plugins-it-utils/src/test/java/com/navercorp/pinpoint/pluginit/utils/WebServerTest.java +++ b/agent-module/plugins-test-module/plugins-it-utils/src/test/java/com/navercorp/pinpoint/pluginit/utils/WebServerTest.java @@ -19,7 +19,7 @@ import com.navercorp.pinpoint.common.util.IOUtils; import com.navercorp.pinpoint.it.plugin.utils.WebServer; import fi.iki.elonen.NanoHTTPD; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -38,6 +38,7 @@ */ public class WebServerTest { + @AutoClose("stop") private static WebServer webServer; @BeforeAll @@ -45,11 +46,6 @@ public static void newTestWebServer() throws Exception { webServer = WebServer.newTestWebServer(); } - @AfterAll - public static void cleanup() { - WebServer.cleanup(webServer); - } - @Test public void testGetHostAndPort() { assertThat(webServer.getHostAndPort()).startsWith("localhost:"); diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/DefaultBulkUpdaterTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/DefaultBulkUpdaterTest.java index 2ebb915a0941..c26c6c232e0d 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/DefaultBulkUpdaterTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/DefaultBulkUpdaterTest.java @@ -16,18 +16,18 @@ package com.navercorp.pinpoint.collector.dao.hbase.statistics; -import com.navercorp.pinpoint.collector.monitor.dao.hbase.BulkOperationReporter; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.Flusher; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.Incrementer; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.TestData; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.TestDataSet; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.TestVerifier; +import com.navercorp.pinpoint.collector.monitor.dao.hbase.BulkOperationReporter; import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; import org.apache.commons.collections4.ListUtils; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Increment; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -53,17 +53,13 @@ public class DefaultBulkUpdaterTest { private static final byte[] CF = Bytes.toBytes("CF"); + @AutoClose private static final BulkIncrementerFactory bulkIncrementerFactory = new BulkIncrementerFactory(); private final BulkOperationReporter reporter = new BulkOperationReporter(); private final BulkIncrementer bulkIncrementer = bulkIncrementerFactory.wrap( new DefaultBulkIncrementer(new RowKeyMerge(CF)), Integer.MAX_VALUE, reporter); - @AfterAll - public static void afterClass() { - bulkIncrementerFactory.close(); - } - @Mock private RowKeyDistributorByHashPrefix rowKeyDistributor; diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/SizeLimitedBulkIncrementerTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/SizeLimitedBulkIncrementerTest.java index 055778b2f682..8c86d0a05998 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/SizeLimitedBulkIncrementerTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/dao/hbase/statistics/SizeLimitedBulkIncrementerTest.java @@ -16,19 +16,19 @@ package com.navercorp.pinpoint.collector.dao.hbase.statistics; -import com.navercorp.pinpoint.collector.monitor.dao.hbase.BulkOperationReporter; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.Flusher; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.Incrementer; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.TestData; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.TestDataSet; import com.navercorp.pinpoint.collector.dao.hbase.statistics.BulkIncrementerTestClazz.TestVerifier; +import com.navercorp.pinpoint.collector.monitor.dao.hbase.BulkOperationReporter; import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix; import org.apache.commons.collections4.ListUtils; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Increment; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -57,17 +57,13 @@ public class SizeLimitedBulkIncrementerTest { private final int bulkLimitSize = 1000; + @AutoClose private static final BulkIncrementerFactory bulkIncrementerFactory = new BulkIncrementerFactory(); private final BulkOperationReporter reporter = new BulkOperationReporter(); private final BulkIncrementer bulkIncrementer = bulkIncrementerFactory.wrap( new DefaultBulkIncrementer(new RowKeyMerge(CF)), 1000, reporter); - @AfterAll - public static void afterClass() { - bulkIncrementerFactory.close(); - } - @Mock private RowKeyDistributorByHashPrefix rowKeyDistributor; diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DispatchHandlerTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DispatchHandlerTest.java index f967ced09e06..2ec1a2dcaf89 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DispatchHandlerTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/DispatchHandlerTest.java @@ -23,8 +23,8 @@ import com.navercorp.pinpoint.io.request.ServerResponse; import com.navercorp.pinpoint.thrift.dto.TResult; import org.apache.thrift.TBase; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -48,6 +48,8 @@ public class DispatchHandlerTest { @Mock private AcceptedTimeService acceptedTimeService; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -55,11 +57,6 @@ public void beforeEach() { openMocks = MockitoAnnotations.openMocks(this); } - @AfterEach - public void afterEach() throws Exception { - openMocks.close(); - } - @Test public void throwExceptionTest1() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { diff --git a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoTest.java b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoTest.java index 9d3fe9c444aa..8a9f7b4a93a1 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDaoTest.java @@ -33,8 +33,8 @@ import com.sematext.hbase.wd.AbstractRowKeyDistributor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Scan; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -71,6 +71,8 @@ public class HbaseApplicationTraceIndexDaoTest { private ApplicationTraceIndexDao applicationTraceIndexDao; + @AutoClose + @SuppressWarnings("unused") private AutoCloseable openMocks; @BeforeEach @@ -80,11 +82,6 @@ public void beforeEach() { this.applicationTraceIndexDao = new HbaseApplicationTraceIndexDao(scatterChartProperties, hbaseOperations, tableNameProvider, traceIndexMapper, traceIndexScatterMapper, traceIdRowKeyDistributor); } - @AfterEach - public void afterEach() throws Exception { - openMocks.close(); - } - @Test public void scanTraceIndexExceptionTest() { assertThrows(IllegalArgumentException.class, () -> {