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);
}
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);
}
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);
}
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);
}
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")));
}
Aggregations