Search in sources :

Example 41 with PluginTestVerifier

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

the class JsonLibJSONArrayIT method jsonToArrayTest.

@SuppressWarnings("deprecation")
@Test
public void jsonToArrayTest() throws Exception {
    Method fromObject = JSONArray.class.getMethod("fromObject", Object.class);
    Method toArray = JSONArray.class.getMethod("toArray", JSONArray.class);
    Method toList = JSONArray.class.getMethod("toList", JSONArray.class);
    // JSONArray.toCollection() is added in json-lib 2.2. so check toCollection in JSONArray
    Method toCollection = null;
    try {
        toCollection = JSONArray.class.getMethod("toCollection", JSONArray.class);
    } catch (NoSuchMethodException ignored) {
    }
    String json = "[{'string':'JSON'}]";
    JSONArray jsonArray = JSONArray.fromObject(json);
    // JSONArray.toArray() of json-lib 2.0 and below have different return type. so we invoke it by reflection to avoid NoSuchMethodError
    toArray.invoke(null, jsonArray);
    JSONArray.toList(jsonArray);
    if (toCollection != null) {
        JSONArray.toCollection(jsonArray);
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(event(SERVICE_TYPE, fromObject, annotation(ANNOTATION_KEY, json.length())));
    verifier.verifyTrace(event(SERVICE_TYPE, toArray));
    verifier.verifyTrace(event(SERVICE_TYPE, toList));
    if (toCollection != null) {
        verifier.verifyTrace(event(SERVICE_TYPE, toCollection));
    }
    verifier.verifyTraceCount(0);
}
Also used : JSONArray(net.sf.json.JSONArray) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 42 with PluginTestVerifier

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

the class ObjectMapperIT method testWriteValue.

@Test
public void testWriteValue() throws Exception {
    __POJO pojo = new __POJO();
    pojo.setName("Jackson");
    String jsonStr = mapper.writeValueAsString(pojo);
    byte[] jsonByte = mapper.writeValueAsBytes(pojo);
    ObjectWriter writer = mapper.writer();
    writer.writeValueAsString(pojo);
    writer.writeValueAsBytes(pojo);
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Method mapperWriteValueAsString = ObjectMapper.class.getMethod("writeValueAsString", Object.class);
    Method mapperWriteValueAsBytes = ObjectMapper.class.getMethod("writeValueAsBytes", Object.class);
    Method writerWriteValueAsString = ObjectWriter.class.getMethod("writeValueAsString", Object.class);
    Method writerWriteValueAsBytes = ObjectWriter.class.getMethod("writeValueAsBytes", Object.class);
    verifier.verifyTrace(event(SERVICE_TYPE, mapperWriteValueAsString, annotation(ANNOTATION_KEY, jsonStr.length())));
    verifier.verifyTrace(event(SERVICE_TYPE, mapperWriteValueAsBytes, annotation(ANNOTATION_KEY, jsonByte.length)));
    verifier.verifyTrace(event(SERVICE_TYPE, writerWriteValueAsString, annotation(ANNOTATION_KEY, jsonStr.length())));
    verifier.verifyTrace(event(SERVICE_TYPE, writerWriteValueAsBytes, annotation(ANNOTATION_KEY, jsonByte.length)));
    verifier.verifyTraceCount(0);
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 43 with PluginTestVerifier

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

the class ObjectMapperIT method testConstructor.

@Test
public void testConstructor() throws Exception {
    ObjectMapper mapper1 = new ObjectMapper();
    ObjectMapper mapper2 = new ObjectMapper(new JsonFactory());
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Constructor<?> omConstructor = ObjectMapper.class.getConstructor(JsonFactory.class, DefaultSerializerProvider.class, DefaultDeserializationContext.class);
    Constructor<?> omConstructor1 = ObjectMapper.class.getConstructor();
    Constructor<?> omConstructor2 = ObjectMapper.class.getConstructor(JsonFactory.class);
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor1));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor));
    verifier.verifyTrace(event(SERVICE_TYPE, omConstructor2));
    verifier.verifyTraceCount(0);
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 44 with PluginTestVerifier

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

the class ObjectMapper_1_x_IT method testReadValue.

@Test
public void testReadValue() throws Exception {
    String jsonString = "{\"name\" : \"Jackson\"}";
    byte[] jsonBytes = jsonString.getBytes("UTF-8");
    Method mapperReadValueString = getMethod(ObjectMapper.class, "readValue", String.class, Class.class);
    Method mapperReadValueBytes = getMethod(ObjectMapper.class, "readValue", byte[].class, Class.class);
    Method mapperReader = getMethod(ObjectMapper.class, "reader", Class.class);
    Class<?> readerClass = null;
    Method readerReadValueString = null;
    Method readerReadValueBytes = null;
    try {
        readerClass = Class.forName("org.codehaus.jackson.map.ObjectReader");
        readerReadValueString = getMethod(readerClass, "readValue", String.class);
        readerReadValueBytes = getMethod(readerClass, "readValue", byte[].class);
    } catch (ClassNotFoundException ignored) {
    }
    Object foo = mapper.readValue(jsonString, __POJO.class);
    foo = mapperReadValueBytes == null ? null : mapperReadValueBytes.invoke(mapper, jsonBytes, __POJO.class);
    if (mapperReader != null) {
        Object reader = mapperReader.invoke(mapper, __POJO.class);
        foo = readerReadValueString == null ? null : readerReadValueString.invoke(reader, jsonString);
        foo = readerReadValueBytes == null ? null : readerReadValueBytes.invoke(reader, jsonBytes);
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(event(SERVICE_TYPE, mapperReadValueString, Expectations.annotation(ANNOTATION_KEY, jsonString.length())));
    if (mapperReadValueBytes != null) {
        verifier.verifyTrace(event(SERVICE_TYPE, mapperReadValueBytes, Expectations.annotation(ANNOTATION_KEY, jsonBytes.length)));
    }
    if (readerReadValueString != null) {
        verifier.verifyTrace(event(SERVICE_TYPE, readerReadValueString, Expectations.annotation(ANNOTATION_KEY, jsonString.length())));
    }
    if (readerReadValueBytes != null) {
        verifier.verifyTrace(event(SERVICE_TYPE, readerReadValueBytes, Expectations.annotation(ANNOTATION_KEY, jsonBytes.length)));
    }
    verifier.verifyTraceCount(0);
}
Also used : Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 45 with PluginTestVerifier

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

the class HttpRequestIT method executeAsync.

@Test
public void executeAsync() throws Exception {
    HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
    HttpRequestFactory requestFactory = NET_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest request) {
        }
    });
    GenericUrl url = new GenericUrl("http://google.com");
    HttpRequest request = null;
    HttpResponse response = null;
    try {
        request = requestFactory.buildGetRequest(url);
        response = request.executeAsync().get();
        response.disconnect();
    } catch (IOException ignored) {
    } finally {
        if (response != null) {
            response.disconnect();
        }
    }
    Method executeAsyncMethod = HttpRequest.class.getDeclaredMethod("executeAsync", Executor.class);
    Method callMethod = Callable.class.getDeclaredMethod("call");
    Method executeMethod = HttpRequest.class.getDeclaredMethod("execute");
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    // async
    verifier.verifyTrace(Expectations.async(Expectations.event("GOOGLE_HTTP_CLIENT_INTERNAL", executeAsyncMethod), Expectations.event("ASYNC", "Asynchronous Invocation")));
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) Method(java.lang.reflect.Method) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

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