Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] Fix deprecated API #11732

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.pinpoint.test.plugin.cassandra;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.DockerClientFactory;
Expand All @@ -27,6 +27,7 @@

public class CassandraTest {

@AutoClose
private static CassandraContainer container;

@BeforeAll
Expand All @@ -38,23 +39,15 @@ public static void beforeClass() {

container.getLocalDatacenter();
InetSocketAddress contactPoint = container.getContactPoint();
final int port = contactPoint.getPort();
System.out.println("##host=" + container.getHost());
System.out.println("##port=" + port);
System.out.println("##contactPoint=" + contactPoint);
System.out.println("##LocalDatacenter=" + container.getLocalDatacenter());
System.out.println("##user=" + container.getUsername());
System.out.println("##password=" + container.getPassword());
}

@AfterAll
public static void afterClass() {
if (container != null) {
container.stop();
}
}

@Test
public void test() throws Exception {
System.out.println("TEST");
public void test() {
System.out.println("TEST " + container.getContactPoint());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,40 @@
package com.pinpoint.test.plugin.cassandra;


import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.cassandra.CassandraContainer;

import java.net.InetSocketAddress;


public class CassandraTest {

private static CassandraContainer<?> container;
@AutoClose
private static CassandraContainer container;

@BeforeAll
public static void beforeClass() {
Assumptions.assumeTrue(DockerClientFactory.instance().isDockerAvailable(), "Docker not enabled");


container = new CassandraContainer<>("cassandra:3.11.6");
container = new CassandraContainer("cassandra:3.11.6");
container.start();

container.getLocalDatacenter();
final Integer port = container.getMappedPort(CassandraContainer.CQL_PORT);
System.out.println("##host=" + container.getHost());
System.out.println("##port=" + port.toString());
InetSocketAddress contactPoint = container.getContactPoint();
System.out.println("##contactPoint=" + contactPoint);
System.out.println("##LocalDatacenter=" + container.getLocalDatacenter());
System.out.println("##user=" + container.getUsername());
System.out.println("##password=" + container.getPassword());
}

@AfterAll
public static void afterClass() {
if (container != null) {
container.stop();
}
}

@Test
public void test() throws Exception {
System.out.println("TEST");
public void test() {
System.out.println("TEST " + container.getContactPoint());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void run() {
verifyConsumerConsumeEvent(verifier, testQueue, consumerSession);

// Separate transaction for the consumer's request to receive the message
verifier.verifyTrace(root(STAND_ALONE, "Entry Point Process", null, null, null, null));
verifier.verifyTrace(root(STAND_ALONE, "Entry Point Process", null, null, null));
Method receiveMessageMethod = MessageReceiver.class.getDeclaredMethod("receiveMessage", long.class);
verifier.verifyTrace(event(INTERNAL_METHOD, receiveMessageMethod));
Method receiveMethod = ActiveMQMessageConsumer.class.getDeclaredMethod("receive", long.class);
Expand Down Expand Up @@ -293,7 +293,7 @@ public void run() {
Method printMessageMethod = MessagePrinter.class.getDeclaredMethod("printMessage", Message.class);
for (int i = 0; i < 2; ++i) {
verifier.verifyDiscreteTrace(
root(STAND_ALONE, "Entry Point Process", null, null, null, null),
root(STAND_ALONE, "Entry Point Process", null, null, null),
event(INTERNAL_METHOD, receiveMessageMethod),
event(ACTIVEMQ_CLIENT_INTERNAL, receiveMethod, annotation("activemq.message", getMessageAsString(expectedTextMessage))),
event(INTERNAL_METHOD, printMessageMethod));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void run() {
verifyConsumerConsumeEvent(verifier, testQueue, consumerSession);

// Separate transaction for the consumer's request to receive the message
verifier.verifyTrace(root(STAND_ALONE, "Entry Point Process", null, null, null, null));
verifier.verifyTrace(root(STAND_ALONE, "Entry Point Process", null, null, null));
Method receiveMessageMethod = MessageReceiver.class.getDeclaredMethod("receiveMessage", long.class);
verifier.verifyTrace(event(INTERNAL_METHOD, receiveMessageMethod));
Method receiveMethod = ActiveMQMessageConsumer.class.getDeclaredMethod("receive", long.class);
Expand Down Expand Up @@ -288,7 +288,7 @@ public void run() {
Method printMessageMethod = MessagePrinter.class.getDeclaredMethod("printMessage", Message.class);
for (int i = 0; i < 2; ++i) {
verifier.verifyDiscreteTrace(
root(STAND_ALONE, "Entry Point Process", null, null, null, null),
root(STAND_ALONE, "Entry Point Process", null, null, null),
event(INTERNAL_METHOD, receiveMessageMethod),
event(ACTIVEMQ_CLIENT_INTERNAL, receiveMethod, annotation("activemq.message", getMessageAsString(expectedTextMessage))),
event(INTERNAL_METHOD, printMessageMethod));
Expand Down Expand Up @@ -475,15 +475,15 @@ protected final void assertNoConsumerError(Exception consumerException) {
}

protected final void assertNoConsumerError(CompletableFuture<Message> consumerException) {
Exception exception = null;
Throwable exception = null;
try {
TextMessage message = (TextMessage) consumerException.get(1000, TimeUnit.MILLISECONDS);
System.out.println("Received message : " + message.getText());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
exception = e;
} catch (Throwable th) {
exception = (Exception) th;
exception = th;
}
Assertions.assertNull(exception, "Failed with exception : " + exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Properties beforeAll() {
cassandra.start();

InetSocketAddress contactPoint = cassandra.getContactPoint();
try (Cluster cluster = newCluster("127.0.0.1", contactPoint.getPort())) {
try (Cluster cluster = newCluster(contactPoint.getHostName(), contactPoint.getPort())) {
init(cluster);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void setup(
this.jdbcApi = jdbcApi;

try {
Driver driver = jdbcDriverClass.getDriver().newInstance();
Driver driver = jdbcDriverClass.getDriver().getConstructor().newInstance();
DriverManager.registerDriver(driver);
} catch (Exception e) {
throw new RuntimeException("driver register error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@ public void testFromV1_6() throws Exception {
}

private JsonElement getParseElements() {
return new JsonParser().parse(json);
return JsonParser.parseString(json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void after() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
public void testAdmin() throws Exception {

doReturn(new Configuration()).when(connection).getConfiguration();
Expand All @@ -92,6 +93,7 @@ public void testAdmin() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
public void testTable() throws Exception {

Configuration configuration = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PluginTest;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.core5.concurrent.FutureCallback;
Expand All @@ -47,7 +47,7 @@ public void test() throws Exception {
httpClient.start();

try {
SimpleHttpRequest request = SimpleHttpRequests.get(getAddress());
SimpleHttpRequest request = SimpleRequestBuilder.get().setUri(getAddress()).build();
Future<SimpleHttpResponse> future = httpClient.execute(request, new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(SimpleHttpResponse simpleHttpResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.time.Duration;
import java.util.Collections;
import java.util.Iterator;
import java.util.Properties;
Expand Down Expand Up @@ -91,14 +92,14 @@ private void shutdown() {
@Override
public void run() {
consumer.subscribe(Collections.singleton(TOPIC));
consumer.poll(0);
consumer.poll(Duration.ZERO);
consumer.seekToBeginning(Collections.singleton(new TopicPartition(TOPIC, PARTITION)));
TestConsumerRecordEntryPoint entryPoint = new TestConsumerRecordEntryPoint();

try {
while (true) {
ConsumerRecords<String, String> records = consumer.poll(1000L);
if(records != null && records.count() > 0) {
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(1000));
if (records != null && records.count() > 0) {
Iterator<ConsumerRecord<String, String>> iterator = records.iterator();
if (!iterator.hasNext()) {
continue;
Expand All @@ -109,7 +110,7 @@ public void run() {
entryPoint.consumeRecord(records);
} else if (traceType.equals(TRACE_TYPE_RECORD)) {
offsetStore.setOffset(firstRecord.offset());
records.forEach(record -> entryPoint.consumeRecord(record));
records.forEach(entryPoint::consumeRecord);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.time.Duration;
import java.util.Collections;
import java.util.Iterator;
import java.util.Properties;
Expand Down Expand Up @@ -89,16 +90,15 @@ private void shutdown() {
}

@Override
@SuppressWarnings("deprecation")
public void run() {
consumer.subscribe(Collections.singleton(TOPIC));
consumer.poll(0);
consumer.poll(Duration.ZERO);
consumer.seekToBeginning(Collections.singleton(new TopicPartition(TOPIC, PARTITION)));
TestConsumerRecordEntryPoint entryPoint = new TestConsumerRecordEntryPoint();

try {
while (true) {
ConsumerRecords<String, String> records = consumer.poll(1000L);
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(1000));
if (records != null && records.count() > 0) {
Iterator<ConsumerRecord<String, String>> iterator = records.iterator();
if (!iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) {
// verifier.verifyTrace(event("NETTY_HTTP", "io.netty.handler.codec.http.HttpObjectEncoder.encode(io.netty.channel.ChannelHandlerContext, java.lang.Object, java.util.List)", annotation("http.url", "/")));
} finally {
channel.close().sync();
workerGroup.shutdown();
workerGroup.shutdownGracefully().sync();
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
// verifier.verifyTrace(event("NETTY_HTTP", "io.netty.handler.codec.http.HttpObjectEncoder.encode(io.netty.channel.ChannelHandlerContext, java.lang.Object, java.util.List)", annotation("http.url", "/")));
} finally {
channel.close().sync();
workerGroup.shutdown();
workerGroup.shutdownGracefully().sync();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected static DriverProperties createDriverProperties() {

@BeforeEach
public void registerDriver() throws Exception {
Driver driver = driverClass.getDriver().newInstance();
Driver driver = driverClass.getDriver().getConstructor().newInstance();
DriverManager.registerDriver(driver);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setup(String dbType, String executeQuery, DriverProperties driverPro

try {
JDBCDriverClass jdbcDriverClass = getJDBCDriverClass();
Driver driver = jdbcDriverClass.getDriver().newInstance();
Driver driver = jdbcDriverClass.getDriver().getConstructor().newInstance();
DriverManager.registerDriver(driver);
} catch (Exception e) {
throw new RuntimeException("driver register error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import com.navercorp.pinpoint.bootstrap.plugin.request.util.EntityExtractor;
import com.navercorp.pinpoint.bootstrap.util.FixedByteArrayOutputStream;
import com.navercorp.pinpoint.common.util.StringUtils;
import org.apache.commons.httpclient.HttpConstants;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;

import java.nio.charset.StandardCharsets;

/**
* @author Woonduk Kang(emeroad)
*/
Expand All @@ -49,7 +50,7 @@
try {
String entityValue;
String charSet = entityEnclosingMethod.getRequestCharSet();
charSet = StringUtils.defaultIfEmpty(charSet, HttpConstants.DEFAULT_CONTENT_CHARSET);
charSet = StringUtils.defaultIfEmpty(charSet, StandardCharsets.ISO_8859_1.name());

Check warning on line 53 in agent-module/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClient3EntityExtractor.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClient3EntityExtractor.java#L53

Added line #L53 was not covered by tests

if (entity instanceof ByteArrayRequestEntity || entity instanceof StringRequestEntity) {
entityValue = entityUtilsToString(entity, charSet);
Expand All @@ -72,12 +73,10 @@
entity.writeRequest(outStream);
final String entityValue = outStream.toString(charSet);
if (entity.getContentLength() > MAX_READ_SIZE) {
StringBuilder sb = new StringBuilder();
sb.append(entityValue);
sb.append(" (HTTP entity is large. length: ");
sb.append(entity.getContentLength());
sb.append(" )");
return sb.toString();
return entityValue +

Check warning on line 76 in agent-module/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClient3EntityExtractor.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClient3EntityExtractor.java#L76

Added line #L76 was not covered by tests
" (HTTP entity is large. length: " +
entity.getContentLength() +

Check warning on line 78 in agent-module/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClient3EntityExtractor.java

View check run for this annotation

Codecov / codecov/patch

agent-module/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/HttpClient3EntityExtractor.java#L78

Added line #L78 was not covered by tests
" )";
}

return entityValue;
Expand Down
Loading