Search in sources :

Example 1 with ExpectedAnnotation

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

the class SyncEchoTestClient method verifyTraces.

@Override
public void verifyTraces(PluginTestVerifier verifier, String expectedMessage) throws Exception {
    final InetSocketAddress actualServerAddress = this.environment.getServerAddress();
    // SpanEvent - TServiceClient.sendBase
    Method sendBase = TServiceClient.class.getDeclaredMethod("sendBase", String.class, TBase.class);
    // refer to com.navercorp.pinpoint.plugin.thrift.ThriftUtils#getClientServiceName
    ExpectedAnnotation thriftUrl = Expectations.annotation("thrift.url", actualServerAddress.getHostName() + ":" + actualServerAddress.getPort() + "/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(// ServiceType
    "THRIFT_CLIENT", // Method
    sendBase, // rpc
    null, // endPoint
    null, // destinationId
    actualServerAddress.getHostName() + ":" + actualServerAddress.getPort(), // Annotation("thrift.url")
    thriftUrl, // Annotation("thrift.args")
    thriftArgs), event(// ServiceType
    "THRIFT_CLIENT_INTERNAL", // Method
    receiveBase, // Annotation("thrift.result")
    thriftResult));
}
Also used : ExpectedAnnotation(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation) InetSocketAddress(java.net.InetSocketAddress) Method(java.lang.reflect.Method)

Example 2 with ExpectedAnnotation

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

the class AsyncEchoTestClient method verifyTraces.

@Override
public void verifyTraces(PluginTestVerifier verifier, String expectedMessage) throws Exception {
    final InetSocketAddress actualServerAddress = this.environment.getServerAddress();
    // ********** Asynchronous Traces
    // SpanEvent - Asynchronous Invocation
    ExpectedTrace asyncInvocationTrace = event("ASYNC", "Asynchronous Invocation");
    // SpanEvent - TAsyncMethodCall.cleanUpAndFireCallback
    Method cleanUpAndFireCallback = TAsyncMethodCall.class.getDeclaredMethod("cleanUpAndFireCallback", SelectionKey.class);
    ExpectedTrace cleanUpAndFireCallbackTrace = event("THRIFT_CLIENT_INTERNAL", cleanUpAndFireCallback);
    // SpanEvent - TServiceClient.receiveBase
    Method receiveBase = TServiceClient.class.getDeclaredMethod("receiveBase", TBase.class, String.class);
    ExpectedAnnotation thriftResult = Expectations.annotation("thrift.result", "echo_result(success:" + expectedMessage + ")");
    ExpectedTrace receiveBaseTrace = event(// ServiceType
    "THRIFT_CLIENT_INTERNAL", // Method
    receiveBase, // Annotation("thrift.result")
    thriftResult);
    // ********** Root trace for Asynchronous traces
    // SpanEvent - TAsyncClientManager.call
    Method call = TAsyncClientManager.class.getDeclaredMethod("call", TAsyncMethodCall.class);
    ExpectedAnnotation thriftUrl = Expectations.annotation("thrift.url", actualServerAddress.getHostName() + ":" + actualServerAddress.getPort() + "/com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo_call");
    ExpectedTrace callTrace = event(// ServiceType
    "THRIFT_CLIENT", // Method
    call, // rpc
    null, // endPoint
    null, // destinationId
    actualServerAddress.getHostName() + ":" + actualServerAddress.getPort(), // Annotation("thrift.url")
    thriftUrl);
    verifier.verifyTrace(async(callTrace, asyncInvocationTrace, cleanUpAndFireCallbackTrace, receiveBaseTrace));
}
Also used : ExpectedTrace(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace) ExpectedAnnotation(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation) InetSocketAddress(java.net.InetSocketAddress) Method(java.lang.reflect.Method)

Example 3 with ExpectedAnnotation

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

the class PluginTestAgent method verifySpan.

private void verifySpan(ResolvedExpectedTrace expected, ActualTrace actual) {
    if (!expected.type.equals(actual.getType())) {
        throw new AssertionError("Expected an instance of " + expected.type.getSimpleName() + " but was " + actual.getType().getName() + ". expected: " + expected + ", was: " + actual);
    }
    if (!equals(expected.serviceType.getCode(), actual.getServiceType())) {
        throw new AssertionError("Expected a " + expected.type.getSimpleName() + " with serviceType[" + expected.serviceType.getCode() + "] but was [" + actual.getServiceType() + "]. expected: " + expected + ", was: " + actual);
    }
    if (!equals(expected.apiId, actual.getApiId())) {
        throw new AssertionError("Expected a " + expected.type.getSimpleName() + " with apiId[" + expected.apiId + "] but was [" + actual.getApiId() + "]. expected: " + expected + ", was: " + actual);
    }
    if (!equals(expected.rpc, actual.getRpc())) {
        throw new AssertionError("Expected a " + expected.type.getSimpleName() + " with rpc[" + expected.rpc + "] but was [" + actual.getRpc() + "]. expected: " + expected + ", was: " + actual);
    }
    if (!equals(expected.endPoint, actual.getEndPoint())) {
        throw new AssertionError("Expected a " + expected.type.getSimpleName() + " with endPoint[" + expected.endPoint + "] but was [" + actual.getEndPoint() + "]. expected: " + expected + ", was: " + actual);
    }
    if (!equals(expected.remoteAddr, actual.getRemoteAddr())) {
        throw new AssertionError("Expected a " + expected.type.getSimpleName() + " with remoteAddr[" + expected.remoteAddr + "] but was [" + actual.getRemoteAddr() + "]. expected: " + expected + ", was: " + actual);
    }
    if (!equals(expected.destinationId, actual.getDestinationId())) {
        throw new AssertionError("Expected a " + expected.type.getSimpleName() + " with destinationId[" + expected.destinationId + "] but was [" + actual.getDestinationId() + "]. expected: " + expected + ", was: " + actual);
    }
    if (!equals(expected.asyncId, actual.getAsyncId())) {
        throw new AssertionError("Expected a " + expected.type.getSimpleName() + " with asyncId[" + expected.asyncId + "] but was [" + actual.getAsyncId() + "]. expected: " + expected + ", was: " + actual);
    }
    List<TAnnotation> actualAnnotations = actual.getAnnotations();
    int len = expected.annotations == null ? 0 : expected.annotations.length;
    int actualLen = actualAnnotations == null ? 0 : actualAnnotations.size();
    if (actualLen != len) {
        throw new AssertionError("Expected [" + len + "] annotations but was [" + actualLen + "], expected: " + expected + ", was: " + actual);
    }
    for (int i = 0; i < len; i++) {
        ExpectedAnnotation expect = expected.annotations[i];
        AnnotationKey expectedAnnotationKey = annotationKeyRegistryService.findAnnotationKeyByName(expect.getKeyName());
        TAnnotation actualAnnotation = actualAnnotations.get(i);
        if (expectedAnnotationKey.getCode() != actualAnnotation.getKey()) {
            throw new AssertionError("Expected " + i + "th annotation [" + expectedAnnotationKey.getCode() + "=" + expect.getValue() + "] but was [" + toString(actualAnnotation) + "], expected: " + expected + ", was: " + actual);
        }
        if (expectedAnnotationKey == AnnotationKey.SQL_ID && expect instanceof ExpectedSql) {
            verifySql((ExpectedSql) expect, actualAnnotation);
        } else {
            Object expectedValue = expect.getValue();
            if (expectedValue == Expectations.anyAnnotationValue()) {
                continue;
            }
            if (AnnotationKeyUtils.isCachedArgsKey(expectedAnnotationKey.getCode())) {
                expectedValue = getTestTcpDataSender().getStringId(expectedValue.toString());
            }
            if (!Objects.equal(expectedValue, actualAnnotation.getValue().getFieldValue())) {
                throw new AssertionError("Expected " + i + "th annotation [" + expectedAnnotationKey.getCode() + "=" + expect.getValue() + "] but was [" + toString(actualAnnotation) + "], expected: " + expected + ", was: " + actual);
            }
        }
    }
}
Also used : ExpectedAnnotation(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation) ExpectedSql(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedSql) AnnotationKey(com.navercorp.pinpoint.common.trace.AnnotationKey) TAnnotation(com.navercorp.pinpoint.thrift.dto.TAnnotation)

Aggregations

ExpectedAnnotation (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation)3 Method (java.lang.reflect.Method)2 InetSocketAddress (java.net.InetSocketAddress)2 ExpectedSql (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedSql)1 ExpectedTrace (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace)1 AnnotationKey (com.navercorp.pinpoint.common.trace.AnnotationKey)1 TAnnotation (com.navercorp.pinpoint.thrift.dto.TAnnotation)1