Search in sources :

Example 6 with AssertionErrorBuilder

use of com.navercorp.pinpoint.test.util.AssertionErrorBuilder in project pinpoint by naver.

the class PluginVerifierExternalAdaptor method verifySpan.

private void verifySpan(final ResolvedExpectedTrace expected, ActualTrace actual) {
    if (!expected.type.equals(actual.getType())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + " InstanceType", expected.type.getSimpleName(), actual.getType().getName());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (!equals(expected.serviceType.getCode(), actual.getServiceType())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".serviceType", expected.serviceType.getCode(), actual.getServiceType());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (!equals(expected.apiId, actual.getApiId())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".apiId", expected.apiId, actual.getApiId());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (!equals(expected.rpc, actual.getRpc())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".rpc", expected.rpc, actual.getRpc());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (!equals(expected.endPoint, actual.getEndPoint())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".endPoint", expected.endPoint, actual.getEndPoint());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (!equals(expected.remoteAddr, actual.getRemoteAddr())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".remoteAddr", expected.remoteAddr, actual.getRemoteAddr());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (!equals(expected.destinationId, actual.getDestinationId())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".destinationId", expected.destinationId, actual.getDestinationId());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (!equals(getAsyncId(expected), actual.getAsyncId())) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".asyncId", expected.localAsyncId, actual.getAsyncId());
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (expected.exception != null) {
        final IntStringValue actualExceptionInfo = actual.getExceptionInfo();
        if (actualExceptionInfo != null) {
            String actualExceptionClassName = this.handler.getTcpDataSender().getString(actualExceptionInfo.getIntValue());
            String actualExceptionMessage = actualExceptionInfo.getStringValue();
            verifyException(expected.exception, actualExceptionClassName, actualExceptionMessage);
        } else {
            AssertionErrorBuilder builder = new AssertionErrorBuilder(expected.type.getSimpleName() + ".exception", expected.exception.getClass().getName(), null);
            builder.throwAssertionError();
        }
    }
    List<Annotation<?>> actualAnnotations = actual.getAnnotations();
    final int expectedLen = ArrayUtils.getLength(expected.annotations);
    final int actualLen = CollectionUtils.nullSafeSize(actualAnnotations);
    if (actualLen != expectedLen) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder("Annotation.length", expectedLen, actualLen);
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    for (int i = 0; i < expectedLen; i++) {
        annotationCompare(i, expected, actual, actualAnnotations.get(i));
    }
}
Also used : AssertionErrorBuilder(com.navercorp.pinpoint.test.util.AssertionErrorBuilder) IntStringValue(com.navercorp.pinpoint.common.util.IntStringValue) ExpectedAnnotation(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation) Annotation(com.navercorp.pinpoint.profiler.context.Annotation)

Example 7 with AssertionErrorBuilder

use of com.navercorp.pinpoint.test.util.AssertionErrorBuilder in project pinpoint by naver.

the class PluginVerifierExternalAdaptor method verifyServerType.

@Override
public void verifyServerType(String serviceTypeName) {
    final DefaultApplicationContext applicationContext = getApplicationContext();
    ServiceType expectedType = findServiceType(serviceTypeName);
    ServiceType actualType = applicationContext.getAgentInformation().getServerType();
    if (!expectedType.equals(actualType)) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder("serverType", expectedType, actualType);
        builder.throwAssertionError();
    }
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) AssertionErrorBuilder(com.navercorp.pinpoint.test.util.AssertionErrorBuilder) ServiceType(com.navercorp.pinpoint.common.trace.ServiceType)

Example 8 with AssertionErrorBuilder

use of com.navercorp.pinpoint.test.util.AssertionErrorBuilder in project pinpoint by naver.

the class PluginVerifierExternalAdaptor method verifyDataType.

private void verifyDataType(int index, DataType expectedValue, Annotation<?> actualAnnotation) {
    DataType annotationValue = (DataType) actualAnnotation.getValue();
    if (!ObjectUtils.equals(expectedValue, annotationValue)) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(String.format("Annotation[%s].value", index), expectedValue, annotationValue);
        builder.throwAssertionError();
    }
}
Also used : AssertionErrorBuilder(com.navercorp.pinpoint.test.util.AssertionErrorBuilder) DataType(com.navercorp.pinpoint.common.util.DataType)

Example 9 with AssertionErrorBuilder

use of com.navercorp.pinpoint.test.util.AssertionErrorBuilder in project pinpoint by naver.

the class PluginVerifierExternalAdaptor method annotationCompare.

private void annotationCompare(int index, ResolvedExpectedTrace expected, ActualTrace actual, Annotation<?> actualAnnotation) {
    final ExpectedAnnotation expect = expected.annotations[index];
    final AnnotationKey expectedAnnotationKey = this.handler.getAnnotationKeyRegistryService().findAnnotationKeyByName(expect.getKeyName());
    if (expectedAnnotationKey.getCode() != actualAnnotation.getKey()) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder(String.format("Annotation[%s].key", index), AnnotationUtils.toString(expectedAnnotationKey, expect), AnnotationUtils.toString(actualAnnotation));
        builder.setComparison(expected, actual);
        builder.throwAssertionError();
    }
    if (expectedAnnotationKey == AnnotationKey.SQL_ID && expect instanceof ExpectedSql) {
        verifySql(index, (ExpectedSql) expect, actualAnnotation);
    } else if (expect.getValue() instanceof DataType) {
        verifyDataType(index, ((DataType) expect.getValue()), actualAnnotation);
    } else {
        Object expectedValue = expect.getValue();
        if (expectedValue == Expectations.anyAnnotationValue()) {
            return;
        }
        if (AnnotationKeyUtils.isCachedArgsKey(expectedAnnotationKey.getCode())) {
            expectedValue = this.handler.getTcpDataSender().getStringId(expectedValue.toString());
        }
        if (!ObjectUtils.equals(expectedValue, actualAnnotation.getValue())) {
            AssertionErrorBuilder builder = new AssertionErrorBuilder(String.format("Annotation[%s].value", index), expectedAnnotationKey.getCode(), AnnotationUtils.toString(actualAnnotation));
            builder.setComparison(expected, actual);
            builder.throwAssertionError();
        }
    }
}
Also used : ExpectedAnnotation(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation) AssertionErrorBuilder(com.navercorp.pinpoint.test.util.AssertionErrorBuilder) ExpectedSql(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedSql) AnnotationKey(com.navercorp.pinpoint.common.trace.AnnotationKey) DataType(com.navercorp.pinpoint.common.util.DataType)

Example 10 with AssertionErrorBuilder

use of com.navercorp.pinpoint.test.util.AssertionErrorBuilder in project pinpoint by naver.

the class PluginVerifierExternalAdaptor method verifyServerInfo.

@Override
public void verifyServerInfo(String serverInfo) {
    String actualName = getServerMetaData().getServerInfo();
    if (!actualName.equals(serverInfo)) {
        AssertionErrorBuilder builder = new AssertionErrorBuilder("serverInfo", serverInfo, actualName);
        builder.throwAssertionError();
    }
}
Also used : AssertionErrorBuilder(com.navercorp.pinpoint.test.util.AssertionErrorBuilder)

Aggregations

AssertionErrorBuilder (com.navercorp.pinpoint.test.util.AssertionErrorBuilder)13 ExpectedAnnotation (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation)2 ExpectedTrace (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedTrace)2 DataType (com.navercorp.pinpoint.common.util.DataType)2 SpanType (com.navercorp.pinpoint.profiler.context.SpanType)2 ServiceInfo (com.navercorp.pinpoint.bootstrap.context.ServiceInfo)1 ExpectedSql (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedSql)1 AnnotationKey (com.navercorp.pinpoint.common.trace.AnnotationKey)1 LoggingInfo (com.navercorp.pinpoint.common.trace.LoggingInfo)1 ServiceType (com.navercorp.pinpoint.common.trace.ServiceType)1 IntStringStringValue (com.navercorp.pinpoint.common.util.IntStringStringValue)1 IntStringValue (com.navercorp.pinpoint.common.util.IntStringValue)1 Annotation (com.navercorp.pinpoint.profiler.context.Annotation)1 TraceRoot (com.navercorp.pinpoint.profiler.context.id.TraceRoot)1 DefaultApplicationContext (com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext)1 ActualTrace (com.navercorp.pinpoint.test.wrapper.ActualTrace)1