Skip to content

Commit

Permalink
[pinpoint-apm#2264] Enhance ExpectedTrace for plugin test module
Browse files Browse the repository at this point in the history
enhance ExpectedTrace for plugin test module
  • Loading branch information
koo-taejin committed Nov 23, 2018
1 parent 24caa7e commit 9ae85b6
Show file tree
Hide file tree
Showing 6 changed files with 514 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public final class Expectations {

private static final Object ANY_ANNOTATION_VALUE = new Object();


private Expectations() {
}

Expand All @@ -34,55 +33,131 @@ public static Object anyAnnotationValue() {
}

public static ExpectedTrace root(String serviceType, Member method, String rpc, String endPoint, String remoteAddr, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.ROOT, serviceType, method, null, null, rpc, endPoint, remoteAddr, null, annotations, null);
ExpectedTrace.Builder rootBuilder = ExpectedTrace.createRootBuilder(serviceType);
rootBuilder.setMethod(method);
rootBuilder.setRpc(rpc);
rootBuilder.setEndPoint(endPoint);
rootBuilder.setRemoteAddr(remoteAddr);
rootBuilder.setAnnotations(annotations);
return rootBuilder.build();
}

public static ExpectedTrace root(String serviceType, Member method, Exception exception, String rpc, String endPoint, String remoteAddr, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.ROOT, serviceType, method, null, exception, rpc, endPoint, remoteAddr, null, annotations, null);
ExpectedTrace.Builder rootBuilder = ExpectedTrace.createRootBuilder(serviceType);
rootBuilder.setMethod(method);
rootBuilder.setException(exception);
rootBuilder.setRpc(rpc);
rootBuilder.setEndPoint(endPoint);
rootBuilder.setRemoteAddr(remoteAddr);
rootBuilder.setAnnotations(annotations);
return rootBuilder.build();
}

public static ExpectedTrace root(String serviceType, String methodDescriptor, String rpc, String endPoint, String remoteAddr, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.ROOT, serviceType, null, methodDescriptor, null, rpc, endPoint, remoteAddr, null, annotations, null);
ExpectedTrace.Builder rootBuilder = ExpectedTrace.createRootBuilder(serviceType);
rootBuilder.setMethodSignature(methodDescriptor);
rootBuilder.setRpc(rpc);
rootBuilder.setEndPoint(endPoint);
rootBuilder.setRemoteAddr(remoteAddr);
rootBuilder.setAnnotations(annotations);
return rootBuilder.build();
}

public static ExpectedTrace root(String serviceType, String methodDescriptor, Exception exception, String rpc, String endPoint, String remoteAddr, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.ROOT, serviceType, null, methodDescriptor, exception, rpc, endPoint, remoteAddr, null, annotations, null);
ExpectedTrace.Builder rootBuilder = ExpectedTrace.createRootBuilder(serviceType);
rootBuilder.setMethodSignature(methodDescriptor);
rootBuilder.setException(exception);
rootBuilder.setRpc(rpc);
rootBuilder.setEndPoint(endPoint);
rootBuilder.setRemoteAddr(remoteAddr);
rootBuilder.setAnnotations(annotations);
return rootBuilder.build();
}

public static ExpectedTrace event(String serviceType, Member method, String rpc, String endPoint, String destinationId, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, method, null, null, rpc, endPoint, null, destinationId, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethod(method);
eventBuilder.setRpc(rpc);
eventBuilder.setEndPoint(endPoint);
eventBuilder.setDestinationId(destinationId);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace event(String serviceType, Member method, Exception exception, String rpc, String endPoint, String destinationId, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, method, null, exception, rpc, endPoint, null, destinationId, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethod(method);
eventBuilder.setException(exception);
eventBuilder.setRpc(rpc);
eventBuilder.setEndPoint(endPoint);
eventBuilder.setDestinationId(destinationId);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace event(String serviceType, Member method, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, method, null, null, null, null, null, null, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethod(method);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace event(String serviceType, Member method, Exception exception, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, method, null, exception, null, null, null, null, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethod(method);
eventBuilder.setException(exception);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace event(String serviceType, String methodDescriptor, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, null, methodDescriptor, null, null, null, null, null, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethodSignature(methodDescriptor);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace event(String serviceType, String methodDescriptor, Exception exception, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, null, methodDescriptor, exception, null, null, null, null, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethodSignature(methodDescriptor);
eventBuilder.setException(exception);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace event(String serviceType, String methodDescriptor, String rpc, String endPoint, String destinationId, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, null, methodDescriptor, null, rpc, endPoint, null, destinationId, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethodSignature(methodDescriptor);
eventBuilder.setRpc(rpc);
eventBuilder.setEndPoint(endPoint);
eventBuilder.setDestinationId(destinationId);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace event(String serviceType, String methodDescriptor, Exception exception, String rpc, String endPoint, String destinationId, ExpectedAnnotation... annotations) {
return new ExpectedTrace(TraceType.EVENT, serviceType, null, methodDescriptor, exception, rpc, endPoint, null, destinationId, annotations, null);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createEventBuilder(serviceType);
eventBuilder.setMethodSignature(methodDescriptor);
eventBuilder.setException(exception);
eventBuilder.setRpc(rpc);
eventBuilder.setEndPoint(endPoint);
eventBuilder.setDestinationId(destinationId);
eventBuilder.setAnnotations(annotations);
return eventBuilder.build();
}

public static ExpectedTrace async(ExpectedTrace initiator, ExpectedTrace... asyncTraces) {
return new ExpectedTrace(initiator.getType(), initiator.getServiceType(), initiator.getMethod(), initiator.getMethodSignature(), initiator.getException(), initiator.getRpc(), initiator.getEndPoint(), initiator.getRemoteAddr(), initiator.getDestinationId(), initiator.getAnnotations(), asyncTraces);
ExpectedTrace.Builder eventBuilder = ExpectedTrace.createBuilder(initiator.getType(), initiator.getServiceType());
eventBuilder.setMethod(initiator.getMethod());
eventBuilder.setMethodSignature(initiator.getMethodSignature());
eventBuilder.setException(initiator.getException());
eventBuilder.setRpc(initiator.getRpc());
eventBuilder.setEndPoint(initiator.getEndPoint());
eventBuilder.setRemoteAddr(initiator.getRemoteAddr());
eventBuilder.setDestinationId(initiator.getDestinationId());
eventBuilder.setAnnotations(initiator.getAnnotations());
eventBuilder.setAsyncTraces(asyncTraces);
return eventBuilder.build();
}

public static ExpectedAnnotation[] annotations(ExpectedAnnotation... annotations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,33 +18,32 @@

/**
* @author Jongho Moon
*
*/
public class ExpectedTrace {
private final TraceType type;
private final String serviceType;
private final Member method;
private final String methodSignature;
private final Exception exception;
private final String rpc;
private final String endPoint;
private final String remoteAddr;
private final String destinationId;
private final ExpectedTraceField rpc;
private final ExpectedTraceField endPoint;
private final ExpectedTraceField remoteAddr;
private final ExpectedTraceField destinationId;
private final ExpectedAnnotation[] annotations;
private final ExpectedTrace[] asyncTraces;
public ExpectedTrace(TraceType type, String serviceType, Member method, String methodSignature, Exception exception, String rpc, String endPoint, String remoteAddr, String destinationId, ExpectedAnnotation[] annotations, ExpectedTrace[] asyncTraces) {
this.type = type;
this.serviceType = serviceType;
this.method = method;
this.methodSignature = methodSignature;
this.exception = exception;
this.rpc = rpc;
this.endPoint = endPoint;
this.remoteAddr = remoteAddr;
this.destinationId = destinationId;
this.annotations = annotations;
this.asyncTraces = asyncTraces;

private ExpectedTrace(Builder builder) {
this.type = builder.type;
this.serviceType = builder.serviceType;
this.method = builder.method;
this.methodSignature = builder.methodSignature;
this.exception = builder.exception;
this.rpc = builder.rpc;
this.endPoint = builder.endPoint;
this.remoteAddr = builder.remoteAddr;
this.destinationId = builder.destinationId;
this.annotations = builder.annotations;
this.asyncTraces = builder.asyncTraces;
}

public TraceType getType() {
Expand All @@ -67,19 +66,19 @@ public Exception getException() {
return exception;
}

public String getRpc() {
public ExpectedTraceField getRpc() {
return rpc;
}

public String getEndPoint() {
public ExpectedTraceField getEndPoint() {
return endPoint;
}

public String getRemoteAddr() {
public ExpectedTraceField getRemoteAddr() {
return remoteAddr;
}

public String getDestinationId() {
public ExpectedTraceField getDestinationId() {
return destinationId;
}

Expand All @@ -90,4 +89,114 @@ public ExpectedAnnotation[] getAnnotations() {
public ExpectedTrace[] getAsyncTraces() {
return asyncTraces;
}


public static Builder createBuilder(TraceType traceType, String serviceType) {
return new Builder(traceType, serviceType);
}

public static Builder createRootBuilder(String serviceType) {
return new Builder(TraceType.ROOT, serviceType);
}

public static Builder createEventBuilder(String serviceType) {
return new Builder(TraceType.EVENT, serviceType);
}

public static class Builder {

private final TraceType type;
private final String serviceType;

private Member method;
private String methodSignature;
private Exception exception;
private ExpectedTraceField rpc = ExpectedTraceField.ALWAYS_TRUE;
private ExpectedTraceField endPoint = ExpectedTraceField.ALWAYS_TRUE;
private ExpectedTraceField remoteAddr = ExpectedTraceField.ALWAYS_TRUE;
private ExpectedTraceField destinationId = ExpectedTraceField.ALWAYS_TRUE;
private ExpectedAnnotation[] annotations;
private ExpectedTrace[] asyncTraces;

public Builder(TraceType type, String serviceType) {
if (type == null) {
throw new NullPointerException("type must not be null");
}
if (serviceType == null) {
throw new NullPointerException("serviceType must not be null");
}
this.type = type;
this.serviceType = serviceType;
}

public void setMethod(Member method) {
this.method = method;
}

public void setMethodSignature(String methodSignature) {
this.methodSignature = methodSignature;
}

public void setException(Exception exception) {
this.exception = exception;
}

public void setRpc(String rpc) {
setRpc(ExpectedTraceField.create(rpc));
}

public void setRpc(ExpectedTraceField rpc) {
if (rpc == null) {
throw new NullPointerException("rpc must not be null");
}
this.rpc = rpc;
}

public void setEndPoint(String endPoint) {
setEndPoint(ExpectedTraceField.create(endPoint));
}

public void setEndPoint(ExpectedTraceField endPoint) {
if (endPoint == null) {
throw new NullPointerException("endPoint must not be null");
}
this.endPoint = endPoint;
}

public void setRemoteAddr(String remoteAddr) {
setRemoteAddr(ExpectedTraceField.create(remoteAddr));
}

public void setRemoteAddr(ExpectedTraceField remoteAddr) {
if (remoteAddr == null) {
throw new NullPointerException("remoteAddr must not be null");
}
this.remoteAddr = remoteAddr;
}

public void setDestinationId(String destinationId) {
setDestinationId(ExpectedTraceField.create(destinationId));
}

public void setDestinationId(ExpectedTraceField destinationId) {
if (destinationId == null) {
throw new NullPointerException("destinationId must not be null");
}
this.destinationId = destinationId;
}

public void setAnnotations(ExpectedAnnotation... annotations) {
this.annotations = annotations;
}

public void setAsyncTraces(ExpectedTrace[] asyncTraces) {
this.asyncTraces = asyncTraces;
}

public ExpectedTrace build() {
return new ExpectedTrace(this);
}

}

}
Loading

0 comments on commit 9ae85b6

Please # to comment.