Search in sources :

Example 6 with AnnotationKey

use of com.navercorp.pinpoint.common.trace.AnnotationKey in project pinpoint by naver.

the class DefaultAnnotationKeyRegistryService method buildAnnotationKeyRegistry.

private AnnotationKeyRegistry buildAnnotationKeyRegistry() {
    AnnotationKeyRegistry.Builder builder = new AnnotationKeyRegistry.Builder();
    StaticFieldLookUp<AnnotationKey> staticFieldLookUp = new StaticFieldLookUp<AnnotationKey>(AnnotationKey.class, AnnotationKey.class);
    List<AnnotationKey> lookup = staticFieldLookUp.lookup();
    for (AnnotationKey serviceType : lookup) {
        if (logger.isInfoEnabled()) {
            logger.info("add Default AnnotationKey:" + serviceType);
        }
        builder.addAnnotationKey(serviceType);
    }
    final List<AnnotationKey> types = typeLoaderService.getAnnotationKeys();
    for (AnnotationKey type : types) {
        if (logger.isInfoEnabled()) {
            logger.info("add Plugin AnnotationKey:" + type);
        }
        builder.addAnnotationKey(type);
    }
    return builder.build();
}
Also used : StaticFieldLookUp(com.navercorp.pinpoint.common.util.StaticFieldLookUp) AnnotationKey(com.navercorp.pinpoint.common.trace.AnnotationKey) AnnotationKeyRegistry(com.navercorp.pinpoint.common.trace.AnnotationKeyRegistry)

Example 7 with AnnotationKey

use of com.navercorp.pinpoint.common.trace.AnnotationKey in project pinpoint by naver.

the class AnnotationKeyTest method getCode.

@Test
public void getCode() {
    TraceMetadataLoaderService typeLoaderService = new DefaultTraceMetadataLoaderService();
    AnnotationKeyRegistryService annotationKeyRegistryService = new DefaultAnnotationKeyRegistryService(typeLoaderService, StdoutCommonLoggerFactory.INSTANCE);
    AnnotationKey annotationKey = annotationKeyRegistryService.findAnnotationKey(AnnotationKey.API.getCode());
    Assert.assertEquals(annotationKey, AnnotationKey.API);
}
Also used : DefaultTraceMetadataLoaderService(com.navercorp.pinpoint.common.service.DefaultTraceMetadataLoaderService) TraceMetadataLoaderService(com.navercorp.pinpoint.common.service.TraceMetadataLoaderService) DefaultTraceMetadataLoaderService(com.navercorp.pinpoint.common.service.DefaultTraceMetadataLoaderService) DefaultAnnotationKeyRegistryService(com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService) AnnotationKeyRegistryService(com.navercorp.pinpoint.common.service.AnnotationKeyRegistryService) AnnotationKey(com.navercorp.pinpoint.common.trace.AnnotationKey) DefaultAnnotationKeyRegistryService(com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService) Test(org.junit.Test)

Example 8 with AnnotationKey

use of com.navercorp.pinpoint.common.trace.AnnotationKey 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

AnnotationKey (com.navercorp.pinpoint.common.trace.AnnotationKey)8 Test (org.junit.Test)4 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)2 AnnotationKeyRegistryService (com.navercorp.pinpoint.common.service.AnnotationKeyRegistryService)2 DefaultAnnotationKeyRegistryService (com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService)2 TraceMetadataLoader (com.navercorp.pinpoint.common.trace.TraceMetadataLoader)2 TraceMetadataProvider (com.navercorp.pinpoint.common.trace.TraceMetadataProvider)2 ExpectedAnnotation (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation)1 ExpectedSql (com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedSql)1 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)1 DefaultTraceMetadataLoaderService (com.navercorp.pinpoint.common.service.DefaultTraceMetadataLoaderService)1 TraceMetadataLoaderService (com.navercorp.pinpoint.common.service.TraceMetadataLoaderService)1 AnnotationKeyRegistry (com.navercorp.pinpoint.common.trace.AnnotationKeyRegistry)1 ApiDescription (com.navercorp.pinpoint.common.util.ApiDescription)1 StaticFieldLookUp (com.navercorp.pinpoint.common.util.StaticFieldLookUp)1 TAnnotation (com.navercorp.pinpoint.thrift.dto.TAnnotation)1 ArrayList (java.util.ArrayList)1