This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit ecdd337f01dad400c7df75785b619e3cf5ce082a Author: Yang, Bo <[email protected]> AuthorDate: Fri Jan 5 18:30:50 2018 +0800 SCB-172 fix integration test for upgradeing to zipkin2 Use V2 http api to fetch tracing data. Use containsInAnyOrder for comparing results because json data doesn't ensure order on marshaling/unmarshaling, and we don't care the order here. --- integration-tests/pom.xml | 7 +++++- integration-tests/test-common/pom.xml | 4 +++ .../servicecomb/tests/tracing/TracingTestBase.java | 29 ++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 3d021ac..e9f3d4f 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -55,9 +55,14 @@ <type>test-jar</type> </dependency> <dependency> + <groupId>io.zipkin.zipkin2</groupId> + <artifactId>zipkin</artifactId> + <version>2.4.2</version> + </dependency> + <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-junit</artifactId> - <version>1.24.0</version> + <version>2.4.2</version> <scope>test</scope> </dependency> <dependency> diff --git a/integration-tests/test-common/pom.xml b/integration-tests/test-common/pom.xml index 9161ca8..47ca056 100644 --- a/integration-tests/test-common/pom.xml +++ b/integration-tests/test-common/pom.xml @@ -51,6 +51,10 @@ <artifactId>zipkin-junit</artifactId> </dependency> <dependency> + <groupId>io.zipkin.zipkin2</groupId> + <artifactId>zipkin</artifactId> + </dependency> + <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <scope>test</scope> diff --git a/integration-tests/test-common/src/test/java/io/servicecomb/tests/tracing/TracingTestBase.java b/integration-tests/test-common/src/test/java/io/servicecomb/tests/tracing/TracingTestBase.java index 52b511d..a5350cd 100644 --- a/integration-tests/test-common/src/test/java/io/servicecomb/tests/tracing/TracingTestBase.java +++ b/integration-tests/test-common/src/test/java/io/servicecomb/tests/tracing/TracingTestBase.java @@ -19,7 +19,7 @@ package io.servicecomb.tests.tracing; import static io.servicecomb.foundation.common.base.ServiceCombConstants.CONFIG_TRACING_COLLECTOR_ADDRESS; import static io.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl.LOCAL_REGISTRY_FILE_KEY; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.springframework.http.HttpStatus.OK; @@ -28,6 +28,7 @@ import java.lang.invoke.MethodHandles; import java.net.URL; import java.util.Collection; import java.util.List; +import java.util.ArrayList; import java.util.stream.Collectors; import org.junit.BeforeClass; @@ -39,8 +40,8 @@ import org.springframework.web.client.RestTemplate; import io.servicecomb.tests.EmbeddedAppender; import io.servicecomb.tests.Log4jConfig; -import zipkin.Codec; -import zipkin.Span; +import zipkin2.codec.SpanBytesDecoder; +import zipkin2.Span; import zipkin.junit.ZipkinRule; public class TracingTestBase { @@ -74,27 +75,33 @@ public class TracingTestBase { .map(this::extractIds) .collect(Collectors.toList()); - String url = zipkin.httpUrl() + "/api/v1/trace/{traceId}"; + String url = zipkin.httpUrl() + "/api/v2/trace/{traceId}"; + log.info("rest url:" + url); ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class, traceId(loggedIds)); assertThat(responseEntity.getStatusCode(), is(OK)); String body = responseEntity.getBody(); log.info("Received trace json: {}", body); - List<Span> spans = Codec.JSON.readSpans(body.getBytes()); + List<Span> spans = new ArrayList<Span>(); + SpanBytesDecoder.JSON_V2.decodeList(body.getBytes(), spans); List<String> tracedValues = tracedValues(spans); tracedValues.forEach(value -> log.info("Received value {}", value)); - assertThat(tracedValues, contains(values)); + log.info("values: " + String.join(",",values)); + assertThat(tracedValues, containsInAnyOrder(values)); } private List<String> tracedValues(List<Span> spans) { return spans.stream() - .filter(span -> span.binaryAnnotations != null) - .map(span -> span.binaryAnnotations) + .filter(span -> span.tags() != null) + .map(span -> span.tags().entrySet()) .flatMap(Collection::stream) - .filter(span -> "call.path".equals(span.key) || "http.path".equals(span.key) || "http.status_code".equals(span.key)) - .filter(span -> span.value != null) - .map(annotation -> new String(annotation.value)) + .filter(span -> "call.path".equals(span.getKey()) || "http.path".equals(span.getKey()) || "http.status_code" + .equals + (span + .getKey())) + .filter(span -> span.getValue() != null) + .map(annotation -> new String(annotation.getValue())) .distinct() .collect(Collectors.toList()); } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
