Search in sources :

Example 86 with PluginTestVerifier

use of com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier in project pinpoint by naver.

the class HttpURLConnectionIT method test.

@Test
public void test() throws Exception {
    URL url = new URL("http://www.naver.com");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.getHeaderFields();
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Class<?> targetClass = Class.forName("sun.net.www.protocol.http.HttpURLConnection");
    Method getInputStream = targetClass.getMethod("getInputStream");
    verifier.verifyTraceCount(1);
    verifier.verifyTrace(event("JDK_HTTPURLCONNECTOR", getInputStream, null, null, "www.naver.com", annotation("http.url", "http://www.naver.com")));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) URL(java.net.URL) Test(org.junit.Test)

Example 87 with PluginTestVerifier

use of com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier in project pinpoint by naver.

the class HttpURLConnectionIT method testConnectTwice.

@Test
public void testConnectTwice() throws Exception {
    URL url = new URL("http://www.naver.com");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.connect();
    connection.getInputStream();
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Class<?> targetClass = Class.forName("sun.net.www.protocol.http.HttpURLConnection");
    Method connect = targetClass.getMethod("connect");
    verifier.verifyTraceCount(1);
    verifier.verifyTrace(event("JDK_HTTPURLCONNECTOR", connect, null, null, "www.naver.com", annotation("http.url", "http://www.naver.com")));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) URL(java.net.URL) Test(org.junit.Test)

Example 88 with PluginTestVerifier

use of com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier in project pinpoint by naver.

the class HttpURLConnectionIT method testConnecting.

@Test
public void testConnecting() throws Exception {
    URL url = new URL("http://no.such.url");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    try {
        connection.connect();
    } catch (UnknownHostException e) {
    // ignore
    }
    try {
        connection.connect();
    } catch (UnknownHostException e) {
    // ignore
    }
    Field field = null;
    try {
        field = connection.getClass().getDeclaredField("connecting");
    } catch (NoSuchFieldException ignored) {
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Class<?> targetClass = Class.forName("sun.net.www.protocol.http.HttpURLConnection");
    Method getInputStream = targetClass.getMethod("connect");
    verifier.verifyTrace(event("JDK_HTTPURLCONNECTOR", getInputStream, null, null, "no.such.url", annotation("http.url", "http://no.such.url")));
    if (field == null) {
        // JDK 6, 7
        verifier.verifyTrace(event("JDK_HTTPURLCONNECTOR", getInputStream, null, null, "no.such.url", annotation("http.url", "http://no.such.url")));
    }
    verifier.verifyTraceCount(0);
}
Also used : Field(java.lang.reflect.Field) HttpURLConnection(java.net.HttpURLConnection) UnknownHostException(java.net.UnknownHostException) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) URL(java.net.URL) Test(org.junit.Test)

Example 89 with PluginTestVerifier

use of com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier in project pinpoint by naver.

the class ActiveMQClientITBase method verifyConsumerPullEvent.

/**
     * Verifies spans and span events for when {@link ActiveMQMessageConsumer} receives the message and enqueues it to
     * the {@link org.apache.activemq.MessageDispatchChannel MessageDispatchChannel}. The client then invokes any of
     * {@link ActiveMQMessageConsumer#receive() receive()}, {@link ActiveMQMessageConsumer#receive(long) receive(long)},
     * or {@link ActiveMQMessageConsumer#receiveNoWait() receiveNotWait()} to retrieve the message. (trace count : 4)
     *
     * @param destination the destination from which the consumer is receiving the message
     * @param expectedMessage the message the consumer is expected to receive
     * @throws Exception
     */
private void verifyConsumerPullEvent(ActiveMQDestination destination, MessageConsumer consumer, Message expectedMessage) throws Exception {
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Class<?> messageConsumerClass = Class.forName("org.apache.activemq.ActiveMQMessageConsumer");
    Method receiveWithTimeout = messageConsumerClass.getDeclaredMethod("receive", long.class);
    URI consumerBrokerUri = new URI(getConsumerBrokerUrl());
    ExpectedTrace consumerDispatchTrace = root(// serviceType
    ACTIVEMQ_CLIENT, // method
    "ActiveMQ Consumer Invocation", // rpc
    destination.getQualifiedName(), // endPoint (collected but there's no easy way to retrieve local address)
    null, consumerBrokerUri.getHost() + ":" + consumerBrokerUri.getPort());
    ExpectedTrace consumerReceiveTrace = event(// serviceType
    ACTIVEMQ_CLIENT_INTERNAL, // method
    receiveWithTimeout, annotation("activemq.message", getMessageAsString(expectedMessage)));
    Class<?> messageDispatchChannel = getMessageDispatchChannelClass(consumer);
    if (messageDispatchChannel != null) {
        Method enqueue = messageDispatchChannel.getDeclaredMethod("enqueue", MessageDispatch.class);
        Method dequeueWithTimeout = messageDispatchChannel.getDeclaredMethod("dequeue", long.class);
        // Consumer dispatches and enqueues the message to dispatch channel automatically
        verifier.verifyDiscreteTrace(consumerDispatchTrace, event(ACTIVEMQ_CLIENT_INTERNAL, enqueue));
        // Client receives the message by dequeueing it from the dispatch channel
        verifier.verifyDiscreteTrace(consumerReceiveTrace, event(ACTIVEMQ_CLIENT_INTERNAL, dequeueWithTimeout));
    } else {
        // Consumer dispatches and enqueues the message to dispatch channel automatically
        verifier.verifyDiscreteTrace(consumerDispatchTrace);
        // Client receives the message by dequeueing it from the dispatch channel
        verifier.verifyDiscreteTrace(consumerReceiveTrace);
    }
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) URI(java.net.URI)

Example 90 with PluginTestVerifier

use of com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier in project pinpoint by naver.

the class ActiveMQClientITBase method verifyProducerSendEvent.

/**
     * Verifies traced span event for when {@link org.apache.activemq.ActiveMQMessageProducer ActiveMQMessageProducer}
     * sends the message. (trace count : 1)
     *
     * @param destination the destination to which the producer is sending the message
     * @throws Exception
     */
private void verifyProducerSendEvent(ActiveMQDestination destination) throws Exception {
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Class<?> messageProducerClass = Class.forName("org.apache.activemq.ActiveMQMessageProducer");
    Method send = messageProducerClass.getDeclaredMethod("send", Destination.class, Message.class, int.class, int.class, long.class);
    URI producerBrokerUri = new URI(getProducerBrokerUrl());
    verifier.verifyDiscreteTrace(event(// serviceType
    ACTIVEMQ_CLIENT, // method
    send, // rpc
    null, // endPoint
    producerBrokerUri.getHost() + ":" + producerBrokerUri.getPort(), // destinationId
    destination.getPhysicalName(), annotation("message.queue.url", destination.getQualifiedName()), annotation("activemq.broker.address", producerBrokerUri.getHost() + ":" + producerBrokerUri.getPort())));
}
Also used : Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) URI(java.net.URI)

Aggregations

PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)101 Method (java.lang.reflect.Method)80 Test (org.junit.Test)80 SqlSession (org.apache.ibatis.session.SqlSession)8 SqlMapClientTemplate (org.springframework.orm.ibatis.SqlMapClientTemplate)8 IOException (java.io.IOException)5 RpcException (com.alibaba.dubbo.rpc.RpcException)4 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)3 Gson (com.google.gson.Gson)3 ExpectedTrace (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace)3 HttpURLConnection (java.net.HttpURLConnection)3 URI (java.net.URI)3 URL (java.net.URL)3 FailoverClusterInvoker (com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker)2 AbstractProxyInvoker (com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)2 GenericUrl (com.google.api.client.http.GenericUrl)2 HttpRequest (com.google.api.client.http.HttpRequest)2 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)2