diff --git a/plugins-it/thrift-it/pom.xml b/plugins-it/thrift-it/pom.xml index 886d4736808f..11bb06150069 100644 --- a/plugins-it/thrift-it/pom.xml +++ b/plugins-it/thrift-it/pom.xml @@ -37,7 +37,6 @@ org.apache.thrift libthrift - 0.12.0 test diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/AsyncEchoTestClient.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/AsyncEchoTestClient.java index 90dcdf13370f..9c6ee80e3ff2 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/AsyncEchoTestClient.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/AsyncEchoTestClient.java @@ -52,7 +52,7 @@ public class AsyncEchoTestClient implements EchoTestClient { private final EchoService.AsyncClient asyncClient; private final TAsyncClientManager asyncClientManager = new TAsyncClientManager(); - private AsyncEchoTestClient(TestEnvironment environment) throws IOException { + private AsyncEchoTestClient(TestEnvironment environment) throws Exception { this.environment = environment; this.transport = new TNonblockingSocket(this.environment.getServerIp(), this.environment.getPort()); this.asyncClient = new EchoService.AsyncClient(this.environment.getProtocolFactory(), this.asyncClientManager, this.transport); @@ -168,7 +168,7 @@ public void onError(Exception exception) { } public static class Client extends AsyncEchoTestClient { - public Client(TestEnvironment environment) throws IOException { + public Client(TestEnvironment environment) throws Exception { super(environment); } } diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/SyncEchoTestClient.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/SyncEchoTestClient.java index 8f9734da0dc1..8e256016bbcb 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/SyncEchoTestClient.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/SyncEchoTestClient.java @@ -27,7 +27,6 @@ import org.apache.thrift.TException; import org.apache.thrift.TServiceClient; import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TFramedTransport; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportException; @@ -106,8 +105,8 @@ public Client(TestEnvironment environment) throws TTransportException { } public static class ClientForNonblockingServer extends SyncEchoTestClient { - public ClientForNonblockingServer(TestEnvironment environment) throws TTransportException { - super(environment, new TFramedTransport(new TSocket(environment.getServerIp(), environment.getPort()))); + public ClientForNonblockingServer(TestEnvironment environment) throws Exception { + super(environment, TTransportInstanceCreator.create(SyncEchoTestClient014.class.getClassLoader(), "org.apache.thrift.transport.TFramedTransport", new TSocket(environment.getServerIp(), environment.getPort()))); } } } diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/SyncEchoTestClient014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/SyncEchoTestClient014.java new file mode 100644 index 000000000000..0a00e35c4218 --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/SyncEchoTestClient014.java @@ -0,0 +1,111 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.common.client; + +import com.navercorp.pinpoint.bootstrap.plugin.test.Expectations; +import com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation; +import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier; +import com.navercorp.pinpoint.bootstrap.plugin.util.SocketAddressUtils; +import com.navercorp.pinpoint.common.plugin.util.HostAndPort; +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.dto.EchoService; +import org.apache.thrift.TBase; +import org.apache.thrift.TException; +import org.apache.thrift.TServiceClient; +import org.apache.thrift.protocol.TProtocol; +import org.apache.thrift.transport.TSocket; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; + +import java.lang.reflect.Method; +import java.net.InetSocketAddress; + +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.event; + +/** + * @author HyunGil Jeong + */ +public abstract class SyncEchoTestClient014 implements EchoTestClient { + + private final TestEnvironment environment; + private final TTransport transport; + + private SyncEchoTestClient014(TestEnvironment environment, TTransport transport) throws TTransportException { + this.environment = environment; + this.transport = transport; + this.transport.open(); + } + + @Override + public final String echo(String message) throws TException { + TProtocol protocol = this.environment.getProtocolFactory().getProtocol(transport); + EchoService.Client client = new EchoService.Client(protocol); + return client.echo(message); + } + + @Override + public void verifyTraces(PluginTestVerifier verifier, String expectedMessage) throws Exception { + // refer to TServiceClientSendBaseInterceptor.getRemoteAddress(...) + final InetSocketAddress socketAddress = this.environment.getServerAddress(); + final String hostName = SocketAddressUtils.getHostNameFirst(socketAddress); + final String remoteAddress = HostAndPort.toHostAndPortString(hostName, socketAddress.getPort()); + + // SpanEvent - TServiceClient.sendBase + Method sendBase = TServiceClient.class.getDeclaredMethod("sendBase", String.class, TBase.class); + + ExpectedAnnotation thriftUrl = Expectations.annotation("thrift.url", + remoteAddress + "/com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo"); + ExpectedAnnotation thriftArgs = Expectations.annotation("thrift.args", + "echo_args(message:" + expectedMessage + ")"); + + // SpanEvent - TServiceClient.receiveBase + Method receiveBase = TServiceClient.class.getDeclaredMethod("receiveBase", TBase.class, String.class); + ExpectedAnnotation thriftResult = Expectations.annotation("thrift.result", "echo_result(success:" + + expectedMessage + ")"); + + verifier.verifyDiscreteTrace(event("THRIFT_CLIENT", // ServiceType + sendBase, // Method + null, // rpc + null, // endPoint + remoteAddress, // destinationId + thriftUrl, // Annotation("thrift.url") + thriftArgs), // Annotation("thrift.args") + event("THRIFT_CLIENT_INTERNAL", // ServiceType + receiveBase, // Method + thriftResult // Annotation("thrift.result") + )); + } + + @Override + public void close() { + if (this.transport.isOpen()) { + this.transport.close(); + } + } + + public static class Client extends SyncEchoTestClient014 { + public Client(TestEnvironment environment) throws TTransportException { + super(environment, new TSocket(environment.getServerIp(), environment.getPort())); + } + } + + public static class ClientForNonblockingServer extends SyncEchoTestClient014 { + public ClientForNonblockingServer(TestEnvironment environment) throws Exception { + super(environment, TTransportInstanceCreator.create(SyncEchoTestClient014.class.getClassLoader(), "org.apache.thrift.transport.layered.TFramedTransport", new TSocket(environment.getServerIp(), environment.getPort()))); + } + } +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/TTransportInstanceCreator.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/TTransportInstanceCreator.java new file mode 100644 index 000000000000..7395aa48273a --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/client/TTransportInstanceCreator.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.common.client; + +import org.apache.thrift.transport.TTransport; + +import java.lang.reflect.Constructor; + +public class TTransportInstanceCreator { + + public static TTransport create(ClassLoader classLoader, String className, TTransport transport) throws Exception { + Class clazz = classLoader.loadClass(className); + Constructor constructor = clazz.getConstructor(TTransport.class); + return (TTransport) constructor.newInstance(transport); + } +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/AsyncEchoTestServer.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/AsyncEchoTestServer.java index bb3a9900afdd..532f48c5825d 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/AsyncEchoTestServer.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/AsyncEchoTestServer.java @@ -89,12 +89,12 @@ public static AsyncEchoTestServer threadedSelectorServe .outputProtocolFactory(environment.getProtocolFactory())); return new AsyncEchoTestServer(server, environment) { @Override - public SyncEchoTestClient getSynchronousClient() throws TTransportException { + public SyncEchoTestClient getSynchronousClient() throws Exception { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; @@ -108,12 +108,12 @@ public static AsyncEchoTestServer nonblockingServer(final Te .outputProtocolFactory(environment.getProtocolFactory())); return new AsyncEchoTestServer(server, environment) { @Override - public SyncEchoTestClient getSynchronousClient() throws TTransportException { + public SyncEchoTestClient getSynchronousClient() throws Exception { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; @@ -127,12 +127,12 @@ public static AsyncEchoTestServer halfSyncHalfAsyncServer(final Tes .outputProtocolFactory(environment.getProtocolFactory())); return new AsyncEchoTestServer(server, environment) { @Override - public SyncEchoTestClient getSynchronousClient() throws TTransportException { + public SyncEchoTestClient getSynchronousClient() throws Exception { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/AsyncEchoTestServer014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/AsyncEchoTestServer014.java new file mode 100644 index 000000000000..a71fbe7d6f45 --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/AsyncEchoTestServer014.java @@ -0,0 +1,142 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.common.server; + +import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier; +import com.navercorp.pinpoint.bootstrap.plugin.util.SocketAddressUtils; +import com.navercorp.pinpoint.common.plugin.util.HostAndPort; +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient014; +import com.navercorp.pinpoint.plugin.thrift.dto.EchoService; +import org.apache.thrift.TException; +import org.apache.thrift.TProcessor; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.server.AbstractNonblockingServer; +import org.apache.thrift.server.THsHaServer; +import org.apache.thrift.server.TNonblockingServer; +import org.apache.thrift.server.TThreadedSelectorServer; +import org.apache.thrift.transport.TNonblockingServerSocket; +import org.apache.thrift.transport.TTransportException; + +import java.lang.reflect.Method; +import java.net.InetSocketAddress; + +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.annotation; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.event; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.root; + +/** + * @author HyunGil Jeong + */ +public abstract class AsyncEchoTestServer014 extends ThriftEchoTestServer { + + protected AsyncEchoTestServer014(T server, TestEnvironment environment) { + super(server, environment); + } + + @Override + public void verifyServerTraces(PluginTestVerifier verifier) throws Exception { + final InetSocketAddress socketAddress = super.environment.getServerAddress(); + final String address = SocketAddressUtils.getAddressFirst(socketAddress); + verifier.verifyTraceCount(2); + // Method process = TBaseAsyncProcessor.class.getDeclaredMethod("process", AsyncFrameBuffer.class); + Method process = TBinaryProtocol.class.getDeclaredMethod("readMessageEnd"); + // RootSpan + verifier.verifyTrace(root("THRIFT_SERVER", // ServiceType, + "Thrift Server Invocation", // Method + "com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo", // rpc + HostAndPort.toHostAndPortString(address, socketAddress.getPort()), // endPoint + address // remoteAddress + )); + // SpanEvent - TBaseAsyncProcessor.process + verifier.verifyTrace(event("THRIFT_SERVER_INTERNAL", process, annotation("thrift.url", "com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo"))); + } + + public static class AsyncEchoTestServerFactory { + + private static TProcessor getAsyncProcessor() { + return new EchoService.AsyncProcessor(new EchoService.AsyncIface() { + @Override + public void echo(String message, AsyncMethodCallback resultHandler) throws TException { + resultHandler.onComplete(message); + } + }); + } + + public static AsyncEchoTestServer014 threadedSelectorServer( + final TestEnvironment environment) throws TTransportException { + TThreadedSelectorServer server = new TThreadedSelectorServer(new TThreadedSelectorServer.Args( + new TNonblockingServerSocket(environment.getPort())).processor(getAsyncProcessor()) + .inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new AsyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.ClientForNonblockingServer(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + + public static AsyncEchoTestServer014 nonblockingServer(final TestEnvironment environment) + throws TTransportException { + TNonblockingServer server = new TNonblockingServer(new TNonblockingServer.Args( + new TNonblockingServerSocket(environment.getPort())).processor(getAsyncProcessor()) + .inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new AsyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.ClientForNonblockingServer(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + + public static AsyncEchoTestServer014 halfSyncHalfAsyncServer(final TestEnvironment environment) + throws TTransportException { + THsHaServer server = new THsHaServer(new THsHaServer.Args(new TNonblockingServerSocket( + environment.getPort())).processor(getAsyncProcessor()) + .inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new AsyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.ClientForNonblockingServer(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + } + +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/SyncEchoTestServer.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/SyncEchoTestServer.java index 6dac1335be50..1fcc171f7e85 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/SyncEchoTestServer.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/SyncEchoTestServer.java @@ -96,7 +96,7 @@ public SyncEchoTestClient getSynchronousClient() throws TTransportException { } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; @@ -115,7 +115,7 @@ public SyncEchoTestClient getSynchronousClient() throws TTransportException { } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; @@ -129,12 +129,12 @@ public static SyncEchoTestServer threadedSelectorServer .outputProtocolFactory(environment.getProtocolFactory())); return new SyncEchoTestServer(server, environment) { @Override - public SyncEchoTestClient getSynchronousClient() throws TTransportException { + public SyncEchoTestClient getSynchronousClient() throws Exception { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; @@ -148,12 +148,12 @@ public static SyncEchoTestServer nonblockingServer(final Tes .outputProtocolFactory(environment.getProtocolFactory())); return new SyncEchoTestServer(server, environment) { @Override - public SyncEchoTestClient getSynchronousClient() throws TTransportException { + public SyncEchoTestClient getSynchronousClient() throws Exception { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; @@ -167,12 +167,12 @@ public static SyncEchoTestServer halfSyncHalfAsyncServer(final Test .outputProtocolFactory(environment.getProtocolFactory())); return new SyncEchoTestServer(server, environment) { @Override - public SyncEchoTestClient getSynchronousClient() throws TTransportException { + public SyncEchoTestClient getSynchronousClient() throws Exception { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override - public AsyncEchoTestClient getAsynchronousClient() throws IOException { + public AsyncEchoTestClient getAsynchronousClient() throws Exception { return new AsyncEchoTestClient.Client(environment); } }; diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/SyncEchoTestServer014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/SyncEchoTestServer014.java new file mode 100644 index 000000000000..f561c9a1b4cc --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/SyncEchoTestServer014.java @@ -0,0 +1,181 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.common.server; + +import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier; +import com.navercorp.pinpoint.bootstrap.plugin.util.SocketAddressUtils; +import com.navercorp.pinpoint.common.plugin.util.HostAndPort; +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient014; +import com.navercorp.pinpoint.plugin.thrift.dto.EchoService; +import org.apache.thrift.TException; +import org.apache.thrift.TProcessor; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.server.THsHaServer; +import org.apache.thrift.server.TNonblockingServer; +import org.apache.thrift.server.TServer; +import org.apache.thrift.server.TSimpleServer; +import org.apache.thrift.server.TThreadPoolServer; +import org.apache.thrift.server.TThreadedSelectorServer; +import org.apache.thrift.transport.TNonblockingServerSocket; +import org.apache.thrift.transport.TServerSocket; +import org.apache.thrift.transport.TTransportException; + +import java.lang.reflect.Method; +import java.net.InetSocketAddress; + +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.annotation; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.event; +import static com.navercorp.pinpoint.bootstrap.plugin.test.Expectations.root; + +/** + * @author HyunGil Jeong + */ +public abstract class SyncEchoTestServer014 extends ThriftEchoTestServer { + + protected SyncEchoTestServer014(T server, TestEnvironment environment) { + super(server, environment); + } + + @Override + public void verifyServerTraces(PluginTestVerifier verifier) throws Exception { + final InetSocketAddress socketAddress = super.environment.getServerAddress(); + final String address = SocketAddressUtils.getAddressFirst(socketAddress); + verifier.verifyTraceCount(2); + Method process = TBinaryProtocol.class.getDeclaredMethod("readMessageEnd"); + verifier.verifyTrace( + // RootSpan - Thrift Server Invocation + // refer to TBaseProcessorProcessInterceptor.finalizeSpan(...) + root("THRIFT_SERVER", // ServiceType, + "Thrift Server Invocation", // Method + "com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo", // rpc + HostAndPort.toHostAndPortString(address, socketAddress.getPort()), // endPoint + address), // remoteAddress + // SpanEvent - TBaseProcessor.process + event("THRIFT_SERVER_INTERNAL", process, annotation("thrift.url", "com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo"))); + } + + public static class SyncEchoTestServerFactory { + + private static TProcessor getProcessor() { + return new EchoService.Processor(new EchoService.Iface() { + @Override + public String echo(String message) throws TException { + return message; + } + }); + } + + public static SyncEchoTestServer014 simpleServer(final TestEnvironment environment) + throws TTransportException { + TSimpleServer server = new TSimpleServer(new TSimpleServer.Args(new TServerSocket(environment.getPort())) + .processor(getProcessor()).inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new SyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.Client(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + + public static SyncEchoTestServer014 threadedPoolServer(final TestEnvironment environment) + throws TTransportException { + TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(new TServerSocket( + environment.getPort())).processor(getProcessor()) + .inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new SyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.Client(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + + public static SyncEchoTestServer014 threadedSelectorServer( + final TestEnvironment environment) throws TTransportException { + TThreadedSelectorServer server = new TThreadedSelectorServer(new TThreadedSelectorServer.Args( + new TNonblockingServerSocket(environment.getPort())).processor(getProcessor()) + .inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new SyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.ClientForNonblockingServer(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + + public static SyncEchoTestServer014 nonblockingServer(final TestEnvironment environment) + throws TTransportException { + TNonblockingServer server = new TNonblockingServer(new TNonblockingServer.Args( + new TNonblockingServerSocket(environment.getPort())).processor(getProcessor()) + .inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new SyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.ClientForNonblockingServer(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + + public static SyncEchoTestServer014 halfSyncHalfAsyncServer(final TestEnvironment environment) + throws TTransportException { + THsHaServer server = new THsHaServer(new THsHaServer.Args(new TNonblockingServerSocket( + environment.getPort())).processor(getProcessor()) + .inputProtocolFactory(environment.getProtocolFactory()) + .outputProtocolFactory(environment.getProtocolFactory())); + return new SyncEchoTestServer014(server, environment) { + @Override + public EchoTestClient getSynchronousClient() throws Exception { + return new SyncEchoTestClient014.ClientForNonblockingServer(environment); + } + + @Override + public EchoTestClient getAsynchronousClient() throws Exception { + return new AsyncEchoTestClient.Client(environment); + } + }; + } + } + +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/ThriftEchoTestServer.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/ThriftEchoTestServer.java index d5d63bd8496f..df573792ec5f 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/ThriftEchoTestServer.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/common/server/ThriftEchoTestServer.java @@ -19,6 +19,7 @@ import com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier; import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.server.ServerContext; @@ -88,9 +89,9 @@ public void verifyTraces(PluginTestVerifier verifier) throws Exception { protected abstract void verifyServerTraces(PluginTestVerifier verifier) throws Exception; - public abstract SyncEchoTestClient getSynchronousClient() throws TTransportException; + public abstract EchoTestClient getSynchronousClient() throws Exception; - public abstract AsyncEchoTestClient getAsynchronousClient() throws IOException; + public abstract EchoTestClient getAsynchronousClient() throws Exception; private class WaitToServeHandler implements TServerEventHandler { diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/EchoTestRunner.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/EchoTestRunner.java index 0863134e5c4e..cb0116d2fc0f 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/EchoTestRunner.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/EchoTestRunner.java @@ -89,5 +89,4 @@ private void verifyTraces(EchoTestClient echoClient, String expectedMessage) thr this.echoServer.verifyTraces(this.verifier); this.verifier.verifyTraceCount(0); } - } diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/ThriftVersion.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/ThriftVersion.java index 198e98bc63fd..20beb560525c 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/ThriftVersion.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/ThriftVersion.java @@ -4,6 +4,8 @@ * Thrift 0.13.0 does not work with JDK8 */ public class ThriftVersion { - public static final String VERSION_0_09 = "org.apache.thrift:libthrift:[0.9.1,0.12.0],[0.14.0,)"; - public static final String VERSION_0_10 = "org.apache.thrift:libthrift:[0.10.0,0.12.0],[0.14.0,)"; + public static final String VERSION_0_09 = "org.apache.thrift:libthrift:[0.9.1,0.12.0]"; + public static final String VERSION_0_10 = "org.apache.thrift:libthrift:[0.10.0,0.12.0]"; + public static final String VERSION_0_16 = "org.apache.thrift:libthrift:[0.10.0,0.12.0],[0.14.0,)"; + public static final String VERSION_14_16 = "org.apache.thrift:libthrift:[0.14.0,)"; } diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java index 9ba6cf92653e..d2cbfece662d 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java @@ -18,9 +18,7 @@ import static org.junit.Assert.assertEquals; - -import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; -import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; import com.navercorp.pinpoint.pluginit.utils.AgentPath; @@ -62,7 +60,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); @@ -73,7 +71,7 @@ public void testAsynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final AsyncEchoTestClient client = getServer().getAsynchronousClient(); + final EchoTestClient client = getServer().getAsynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT_014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT_014.java new file mode 100644 index 000000000000..965c9359feb0 --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT_014.java @@ -0,0 +1,79 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.it.asynchronous; + +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.server.AsyncEchoTestServer014.AsyncEchoTestServerFactory; +import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; +import com.navercorp.pinpoint.plugin.thrift.it.EchoTestRunner; +import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; +import com.navercorp.pinpoint.pluginit.utils.AgentPath; +import com.navercorp.pinpoint.test.plugin.Dependency; +import com.navercorp.pinpoint.test.plugin.ImportPlugin; +import com.navercorp.pinpoint.test.plugin.PinpointAgent; +import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import org.apache.thrift.server.THsHaServer; +import org.apache.thrift.transport.TTransportException; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + *

Integration test for THsHaServer with asynchronous processor.

+ * + *

Tests against libthrift 0.9.2+ due to THRIFT-2274
+ * Tests against libthrift 0.10.0+ (0.9.x -> 0.10.x introduces breaking change to generated thrift code)

+ * + * @author HyunGil Jeong + */ +@RunWith(PinpointPluginTestSuite.class) +@PinpointAgent(AgentPath.PATH) +@Dependency({ ThriftVersion.VERSION_14_16, + "org.slf4j:slf4j-simple:1.6.6", "org.slf4j:log4j-over-slf4j:1.6.6", "org.slf4j:slf4j-api:1.6.6" }) +@ImportPlugin({"com.navercorp.pinpoint:pinpoint-thrift-plugin"}) +public class ThriftHalfSyncHalfAsyncServerAsyncIT_014 extends EchoTestRunner> { + + @Override + protected ThriftEchoTestServer createEchoServer(TestEnvironment environment) throws TTransportException { + return AsyncEchoTestServerFactory.halfSyncHalfAsyncServer(environment); + } + + @Test + public void testSynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getSynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + + @Test + public void testAsynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getAsynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java index 371d5053646b..bc1b21696b08 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java @@ -18,8 +18,7 @@ import static org.junit.Assert.assertEquals; -import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; -import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; import com.navercorp.pinpoint.pluginit.utils.AgentPath; @@ -62,7 +61,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); @@ -73,7 +72,7 @@ public void testAsynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final AsyncEchoTestClient client = getServer().getAsynchronousClient(); + final EchoTestClient client = getServer().getAsynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT014.java new file mode 100644 index 000000000000..b981f0b82763 --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT014.java @@ -0,0 +1,81 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.it.asynchronous; + +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; + +import com.navercorp.pinpoint.plugin.thrift.common.server.AsyncEchoTestServer014; +import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; +import com.navercorp.pinpoint.plugin.thrift.it.EchoTestRunner; +import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; +import com.navercorp.pinpoint.pluginit.utils.AgentPath; +import com.navercorp.pinpoint.test.plugin.Dependency; +import com.navercorp.pinpoint.test.plugin.ImportPlugin; +import com.navercorp.pinpoint.test.plugin.PinpointAgent; +import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import org.apache.thrift.server.TNonblockingServer; +import org.apache.thrift.transport.TTransportException; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + *

Integration test for TNonblockingServer with asynchronous processor.

+ * + *

Tests against libthrift 0.9.2+ due to THRIFT-2274
+ * Tests against libthrift 0.10.0+ (0.9.x -> 0.10.x introduces breaking change to generated thrift code)

+ * + * @author HyunGil Jeong + */ +@RunWith(PinpointPluginTestSuite.class) +@PinpointAgent(AgentPath.PATH) +@Dependency({ ThriftVersion.VERSION_14_16, + "org.slf4j:slf4j-simple:1.6.6", "org.slf4j:log4j-over-slf4j:1.6.6", "org.slf4j:slf4j-api:1.6.6" }) +@ImportPlugin({"com.navercorp.pinpoint:pinpoint-thrift-plugin"}) +public class ThriftNonblockingServerAsyncIT014 extends EchoTestRunner> { + + @Override + protected ThriftEchoTestServer createEchoServer(TestEnvironment environment) + throws TTransportException { + return AsyncEchoTestServer014.AsyncEchoTestServerFactory.nonblockingServer(environment); + } + + @Test + public void testSynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getSynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + + @Test + public void testAsynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getAsynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java index ade20a63a4a9..f85a15a324ed 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java @@ -18,9 +18,7 @@ import static org.junit.Assert.assertEquals; - -import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; -import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; import com.navercorp.pinpoint.pluginit.utils.AgentPath; @@ -63,7 +61,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); @@ -74,7 +72,7 @@ public void testAsynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final AsyncEchoTestClient client = getServer().getAsynchronousClient(); + final EchoTestClient client = getServer().getAsynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT014.java new file mode 100644 index 000000000000..544dff2dc471 --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT014.java @@ -0,0 +1,81 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.it.asynchronous; + +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; + +import com.navercorp.pinpoint.plugin.thrift.common.server.AsyncEchoTestServer014; +import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; +import com.navercorp.pinpoint.plugin.thrift.it.EchoTestRunner; +import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; +import com.navercorp.pinpoint.pluginit.utils.AgentPath; +import com.navercorp.pinpoint.test.plugin.Dependency; +import com.navercorp.pinpoint.test.plugin.ImportPlugin; +import com.navercorp.pinpoint.test.plugin.PinpointAgent; +import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import org.apache.thrift.server.TThreadedSelectorServer; +import org.apache.thrift.transport.TTransportException; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + *

Integration test for TThreadedSelectorServer with asynchronous processor.

+ * + *

Tests against libthrift 0.9.2+ due to THRIFT-2274
+ * Tests against libthrift 0.10.0+ (0.9.x -> 0.10.x introduces breaking change to generated thrift code)

+ * + * @author HyunGil Jeong + */ +@RunWith(PinpointPluginTestSuite.class) +@PinpointAgent(AgentPath.PATH) +@Dependency({ ThriftVersion.VERSION_14_16, + "org.slf4j:slf4j-simple:1.6.6", "org.slf4j:log4j-over-slf4j:1.6.6", "org.slf4j:slf4j-api:1.6.6" }) +@ImportPlugin({"com.navercorp.pinpoint:pinpoint-thrift-plugin"}) +public class ThriftThreadedSelectorServerAsyncIT014 extends EchoTestRunner> { + + @Override + protected ThriftEchoTestServer createEchoServer(TestEnvironment environment) + throws TTransportException { + return AsyncEchoTestServer014.AsyncEchoTestServerFactory.threadedSelectorServer(environment); + } + + @Test + public void testSynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getSynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + + @Test + public void testAsynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getAsynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java index ce41236dee5b..4a3adbc06e1c 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java @@ -20,6 +20,7 @@ import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; @@ -62,7 +63,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); @@ -73,7 +74,7 @@ public void testAsynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final AsyncEchoTestClient client = getServer().getAsynchronousClient(); + final EchoTestClient client = getServer().getAsynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT014.java new file mode 100644 index 000000000000..ea893b938f2c --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT014.java @@ -0,0 +1,80 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.it.synchronous; + +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; + +import com.navercorp.pinpoint.plugin.thrift.common.server.SyncEchoTestServer014; +import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; +import com.navercorp.pinpoint.plugin.thrift.it.EchoTestRunner; +import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; +import com.navercorp.pinpoint.pluginit.utils.AgentPath; +import com.navercorp.pinpoint.test.plugin.Dependency; +import com.navercorp.pinpoint.test.plugin.ImportPlugin; +import com.navercorp.pinpoint.test.plugin.PinpointAgent; +import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import org.apache.thrift.server.THsHaServer; +import org.apache.thrift.transport.TTransportException; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + *

Integration test for THsHaServer with synchronous processor.

+ * + *

Tests against libthrift 0.9.2+ due to THRIFT-2274
+ * Tests against libthrift 0.10.0+ (0.9.x -> 0.10.x introduces breaking change to generated thrift code)

+ * + * @author HyunGil Jeong + */ +@RunWith(PinpointPluginTestSuite.class) +@PinpointAgent(AgentPath.PATH) +@Dependency({ ThriftVersion.VERSION_14_16, + "org.slf4j:slf4j-simple:1.6.6", "org.slf4j:log4j-over-slf4j:1.6.6", "org.slf4j:slf4j-api:1.6.6" }) +@ImportPlugin({"com.navercorp.pinpoint:pinpoint-thrift-plugin"}) +public class ThriftHalfSyncHalfAsyncServerIT014 extends EchoTestRunner> { + + @Override + protected ThriftEchoTestServer createEchoServer(TestEnvironment environment) throws TTransportException { + return SyncEchoTestServer014.SyncEchoTestServerFactory.halfSyncHalfAsyncServer(environment); + } + + @Test + public void testSynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getSynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + + @Test + public void testAsynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getAsynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java index 52b717aa3afd..42e1036cae2f 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; @@ -62,7 +63,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); @@ -73,7 +74,7 @@ public void testAsynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final AsyncEchoTestClient client = getServer().getAsynchronousClient(); + final EchoTestClient client = getServer().getAsynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT014.java new file mode 100644 index 000000000000..dd30834e180e --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT014.java @@ -0,0 +1,80 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.it.synchronous; + +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.server.SyncEchoTestServer014; +import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; +import com.navercorp.pinpoint.plugin.thrift.it.EchoTestRunner; +import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; +import com.navercorp.pinpoint.pluginit.utils.AgentPath; +import com.navercorp.pinpoint.test.plugin.Dependency; +import com.navercorp.pinpoint.test.plugin.ImportPlugin; +import com.navercorp.pinpoint.test.plugin.PinpointAgent; +import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import org.apache.thrift.server.TNonblockingServer; +import org.apache.thrift.transport.TTransportException; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + *

Integration test for TNonblockingServer with synchronous processor.

+ * + *

Tests against libthrift 0.9.2+ due to THRIFT-2274 + * Tests against libthrift 0.10.0+ (0.9.x -> 0.10.x introduces breaking change to generated thrift code)

+ * + * @author HyunGil Jeong + */ +@RunWith(PinpointPluginTestSuite.class) +@PinpointAgent(AgentPath.PATH) +@Dependency({ ThriftVersion.VERSION_14_16, + "org.slf4j:slf4j-simple:1.6.6", "org.slf4j:log4j-over-slf4j:1.6.6", "org.slf4j:slf4j-api:1.6.6" }) +@ImportPlugin({"com.navercorp.pinpoint:pinpoint-thrift-plugin"}) +public class ThriftNonblockingServerIT014 extends EchoTestRunner> { + + @Override + protected ThriftEchoTestServer createEchoServer(TestEnvironment environment) + throws TTransportException { + return SyncEchoTestServer014.SyncEchoTestServerFactory.nonblockingServer(environment); + } + + @Test + public void testSynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getSynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + + @Test + public void testAsynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getAsynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + +} diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java index 81c6dd408dbd..e7f2aba27895 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java @@ -18,6 +18,7 @@ import static org.junit.Assert.*; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; @@ -59,7 +60,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java index 0662f2dd0eb4..bdf41075273f 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; @@ -60,7 +61,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java index 643df181eb02..cb9eb118c117 100644 --- a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import com.navercorp.pinpoint.plugin.thrift.common.client.AsyncEchoTestClient; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.client.SyncEchoTestClient; import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; @@ -62,7 +63,7 @@ public void testSynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final SyncEchoTestClient client = getServer().getSynchronousClient(); + final EchoTestClient client = getServer().getSynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); @@ -73,7 +74,7 @@ public void testAsynchronousRpcCall() throws Exception { // Given final String expectedMessage = "TEST_MESSAGE"; // When - final AsyncEchoTestClient client = getServer().getAsynchronousClient(); + final EchoTestClient client = getServer().getAsynchronousClient(); final String result = invokeAndVerify(client, expectedMessage); // Then assertEquals(expectedMessage, result); diff --git a/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT014.java b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT014.java new file mode 100644 index 000000000000..1619ef803bf3 --- /dev/null +++ b/plugins-it/thrift-it/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT014.java @@ -0,0 +1,81 @@ +/* + * Copyright 2022 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.plugin.thrift.it.synchronous; + +import com.navercorp.pinpoint.plugin.thrift.common.TestEnvironment; +import com.navercorp.pinpoint.plugin.thrift.common.client.EchoTestClient; + +import com.navercorp.pinpoint.plugin.thrift.common.server.SyncEchoTestServer014; +import com.navercorp.pinpoint.plugin.thrift.common.server.ThriftEchoTestServer; +import com.navercorp.pinpoint.plugin.thrift.it.EchoTestRunner; +import com.navercorp.pinpoint.plugin.thrift.it.ThriftVersion; +import com.navercorp.pinpoint.pluginit.utils.AgentPath; +import com.navercorp.pinpoint.test.plugin.Dependency; +import com.navercorp.pinpoint.test.plugin.ImportPlugin; +import com.navercorp.pinpoint.test.plugin.PinpointAgent; +import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; +import org.apache.thrift.server.TThreadedSelectorServer; +import org.apache.thrift.transport.TTransportException; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +/** + *

Integration test for TThreadedSelectorServer with synchronous processor.

+ * + *

Tests against libthrift 0.9.2+ due to THRIFT-2274 + * Tests against libthrift 0.10.0+ (0.9.x -> 0.10.x introduces breaking change to generated thrift code)

+ * + * @author HyunGil Jeong + */ +@RunWith(PinpointPluginTestSuite.class) +@PinpointAgent(AgentPath.PATH) +@Dependency({ ThriftVersion.VERSION_14_16, + "org.slf4j:slf4j-simple:1.6.6", "org.slf4j:log4j-over-slf4j:1.6.6", "org.slf4j:slf4j-api:1.6.6" }) +@ImportPlugin({"com.navercorp.pinpoint:pinpoint-thrift-plugin"}) +public class ThriftThreadedSelectorServerIT014 extends EchoTestRunner> { + + @Override + protected ThriftEchoTestServer createEchoServer(TestEnvironment environment) + throws TTransportException { + return SyncEchoTestServer014.SyncEchoTestServerFactory.threadedSelectorServer(environment); + } + + @Test + public void testSynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getSynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + + @Test + public void testAsynchronousRpcCall() throws Exception { + // Given + final String expectedMessage = "TEST_MESSAGE"; + // When + final EchoTestClient client = getServer().getAsynchronousClient(); + final String result = invokeAndVerify(client, expectedMessage); + // Then + assertEquals(expectedMessage, result); + } + +} diff --git a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java index b9344dd13bd7..d9d7bde84952 100644 --- a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java +++ b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftPlugin.java @@ -49,6 +49,7 @@ import com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadMessageEndInterceptor; import com.navercorp.pinpoint.plugin.thrift.interceptor.tprotocol.server.TProtocolReadTTypeInterceptor; import com.navercorp.pinpoint.plugin.thrift.interceptor.transport.TNonblockingSocketConstructInterceptor; +import com.navercorp.pinpoint.plugin.thrift.interceptor.transport.TSocketConstructInterceptor; import java.security.ProtectionDomain; import java.util.List; @@ -303,28 +304,37 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, Strin } // Common - private void addInterceptorsForRetrievingSocketAddresses() { // injector TTranports // TSocket(Socket), TSocket(String, int, int) - addTTransportEditor("org.apache.thrift.transport.TSocket", - "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.TSocketConstructInterceptor", new String[]{"java.net.Socket"}, new String[]{ - "java.lang.String", "int", "int"}); + transformTemplate.transform("org.apache.thrift.transport.TSocket", TSocketTransform.class); // wrapper TTransports // TFramedTransport(TTransport), TFramedTransport(TTransport, int) addTTransportEditor("org.apache.thrift.transport.TFramedTransport", "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.wrapper.TFramedTransportConstructInterceptor", - new String[]{"org.apache.thrift.transport.TTransport"}, new String[]{"org.apache.thrift.transport.TTransport", "int"}); + new String[]{"org.apache.thrift.transport.TTransport"}, + new String[]{"org.apache.thrift.transport.TTransport", "int"}); + // 0.14 + addTTransportEditor("org.apache.thrift.transport.layered.TFramedTransport", + "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.wrapper.TFramedTransportConstructInterceptor", + new String[]{"org.apache.thrift.transport.TTransport", "int"}); + // TFastFramedTransport(TTransport, int, int) addTTransportEditor("org.apache.thrift.transport.TFastFramedTransport", - "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.wrapper.TFastFramedTransportConstructInterceptor", new String[]{ - "org.apache.thrift.transport.TTransport", "int", "int"}); + "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.wrapper.TFastFramedTransportConstructInterceptor", + new String[]{"org.apache.thrift.transport.TTransport", "int", "int"}); + // 0.14 + addTTransportEditor("org.apache.thrift.transport.layered.TFastFramedTransport", + "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.wrapper.TFastFramedTransportConstructInterceptor", + new String[]{"org.apache.thrift.transport.TTransport", "int", "int"}); + // TSaslClientTransport(TTransport), TSaslClientTransport(SaslClient, TTransport) addTTransportEditor("org.apache.thrift.transport.TSaslClientTransport", "com.navercorp.pinpoint.plugin.thrift.interceptor.transport.wrapper.TSaslTransportConstructInterceptor", - new String[]{"org.apache.thrift.transport.TTransport"}, new String[]{"javax.security.sasl.SaslClient", - "org.apache.thrift.transport.TTransport"}); + new String[]{"org.apache.thrift.transport.TTransport"}, + new String[]{"javax.security.sasl.SaslClient", "org.apache.thrift.transport.TTransport"}, + new String[]{"java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.util.Map", "javax.security.auth.callback.CallbackHandler", "org.apache.thrift.transport.TTransport"}); // TMemoryInputTransport - simply add socket field addTTransportEditor("org.apache.thrift.transport.TMemoryInputTransport"); @@ -337,8 +347,34 @@ private void addInterceptorsForRetrievingSocketAddresses() { addFrameBufferEditor(); } - // Common - transports + public static class TSocketTransform implements TransformCallback { + + @Override + public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class classBeingRedefined, + ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException { + final InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer); + target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET); + final InstrumentMethod constructorMethod1 = target.getConstructor("java.net.Socket"); + if (constructorMethod1 != null) { + constructorMethod1.addInterceptor(TSocketConstructInterceptor.class); + } + + // 0.14 or later + InstrumentMethod constructorMethod2 = target.getConstructor("org.apache.thrift.TConfiguration", "java.lang.String", "int", "int"); + if (constructorMethod2 == null) { + // old + constructorMethod2 = target.getConstructor("java.lang.String", "int", "int"); + } + if (constructorMethod2 != null) { + constructorMethod2.addInterceptor(TSocketConstructInterceptor.class); + } + + return target.toBytecode(); + } + } + + // Common - transports private void addTTransportEditor(String tTransportFqcn) { final String targetClassName = tTransportFqcn; transformTemplate.transform(targetClassName, TTransportTransform.class); @@ -412,15 +448,19 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, Strin target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET); target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET_ADDRESS); - // TNonblockingSocket(SocketChannel, int, SocketAddress) - final InstrumentMethod constructor = target.getConstructor("java.nio.channels.SocketChannel", "int", "java.net.SocketAddress"); + // 0.14 or later + InstrumentMethod constructor = target.getConstructor("org.apache.thrift.TConfiguration", "java.nio.channels.SocketChannel", "int", "java.net.SocketAddress"); + if (constructor == null) { + // old + // TNonblockingSocket(SocketChannel, int, SocketAddress) + constructor = target.getConstructor("java.nio.channels.SocketChannel", "int", "java.net.SocketAddress"); + } if (constructor != null) { constructor.addInterceptor(TNonblockingSocketConstructInterceptor.class); } return target.toBytecode(); } - } private void addFrameBufferEditor() { diff --git a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/transport/TNonblockingSocketConstructInterceptor.java b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/transport/TNonblockingSocketConstructInterceptor.java index a0e5968f9fe4..461b61bef6a9 100644 --- a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/transport/TNonblockingSocketConstructInterceptor.java +++ b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/transport/TNonblockingSocketConstructInterceptor.java @@ -19,6 +19,7 @@ import java.net.Socket; import java.net.SocketAddress; +import com.navercorp.pinpoint.common.util.ArrayArgumentUtils; import com.navercorp.pinpoint.common.util.ArrayUtils; import org.apache.thrift.transport.TNonblockingSocket; @@ -46,36 +47,34 @@ public void after(Object target, Object[] args, Object result, Throwable throwab if (isDebug) { logger.afterInterceptor(target, args, result, throwable); } - if (validate(target, args)) { - Socket socket = ((TNonblockingSocket)target).getSocketChannel().socket(); - ((SocketFieldAccessor)target)._$PINPOINT$_setSocket(socket); - if (args[2] instanceof SocketAddress) { - SocketAddress socketAddress = (SocketAddress)args[2]; - ((SocketAddressFieldAccessor)target)._$PINPOINT$_setSocketAddress(socketAddress); + if (validate(target)) { + final Socket socket = ((TNonblockingSocket) target).getSocketChannel().socket(); + ((SocketFieldAccessor) target)._$PINPOINT$_setSocket(socket); + + SocketAddress socketAddress = ArrayArgumentUtils.getArgument(args, 2, SocketAddress.class); + if (socketAddress == null) { + socketAddress = ArrayArgumentUtils.getArgument(args, 3, SocketAddress.class); + } + if (socketAddress == null) { + logger.info("Unexpected arguments. arg[2] or arg[3] is a SocketAddress class. args={}", args); + return; } + ((SocketAddressFieldAccessor) target)._$PINPOINT$_setSocketAddress(socketAddress); } } - private boolean validate(Object target, Object[] args) { + private boolean validate(Object target) { if (!(target instanceof TNonblockingSocket)) { return false; } - if (ArrayUtils.getLength(args) != 3) { - return false; - } if (!(target instanceof SocketFieldAccessor)) { - if (isDebug) { - logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName()); - } + logger.info("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName()); return false; } if (!(target instanceof SocketAddressFieldAccessor)) { - if (isDebug) { - logger.debug("Invalid target object. Need field accessor({}).", SocketAddressFieldAccessor.class.getName()); - } + logger.info("Invalid target object. Need field accessor({}).", SocketAddressFieldAccessor.class.getName()); return false; } return true; } - }