Skip to content

Commit

Permalink
[#noissue] Apply @autoclose
Browse files Browse the repository at this point in the history
# Conflicts:
#	agent-module/plugins-it/informix-jdbc-it/src/test/java/com/navercorp/pinpoint/it/plugin/jdbc/informix/InformixConnectionIT.java
  • Loading branch information
emeroad committed Dec 29, 2024
1 parent c1deb41 commit d62da79
Show file tree
Hide file tree
Showing 56 changed files with 134 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +63,7 @@ public abstract class CassandraDatastaxITBase {
private static String CASSANDRA_ADDRESS;

private static int PORT;
@AutoClose
private static Cluster cluster;


Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,6 +57,8 @@ public class DubboConsumerIT {

private AbstractInvoker abstractClusterInvoker;

@AutoClose
@SuppressWarnings("unused")
private AutoCloseable openMocks;

@BeforeEach
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -47,6 +47,7 @@
@SharedTestLifeCycleClass(ESServer.class)
public class ElasticsearchIT_6_0_x_IT extends ElasticsearchITBase {

@AutoClose
private RestHighLevelClient restHighLevelClient;

@BeforeEach
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -46,6 +46,7 @@
@SharedTestLifeCycleClass(ESServer.class)
public class ElasticsearchIT_6_4_x_IT extends ElasticsearchITBase {

@AutoClose
private static RestHighLevelClient restHighLevelClient;

@BeforeEach
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -46,6 +46,7 @@
@SharedTestLifeCycleClass(ESServer.class)
public class ElasticsearchIT_7_0_x_IT extends ElasticsearchITBase {

@AutoClose
private static RestHighLevelClient restHighLevelClient;

@BeforeEach
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -50,6 +50,7 @@
@SuppressWarnings("deprecation")
public class ElasticsearchIT_7_16_x_IT extends ElasticsearchITBase {

@AutoClose
private RestHighLevelClient restHighLevelClient;

@BeforeEach
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -49,19 +49,14 @@
// 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
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,18 +56,15 @@ public class HbaseClientIT {

private final String tableName = "Table";

@AutoClose
@SuppressWarnings("unused")
private AutoCloseable openMocks;

@BeforeEach
public void beforeEach() {
openMocks = MockitoAnnotations.openMocks(this);
}

@AfterEach
public void after() throws Exception {
openMocks.close();
}

@Test
@SuppressWarnings("deprecation")
public void testAdmin() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,18 +45,14 @@ public class HttpClientIT {

private static final String VERSION = JDBCTestConstants.VERSION;

@AutoClose("stop")
public static WebServer webServer;

@BeforeAll
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<NameValuePair> params = new ArrayList<>();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit d62da79

Please # to comment.