This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new c13381d Added Brave tracing test cases for Microprofile Rest client
c13381d is described below
commit c13381d891b56fe5a2b56f6f9f6f6b2cc8a10d5d
Author: reta <[email protected]>
AuthorDate: Wed Apr 10 20:15:05 2019 -0400
Added Brave tracing test cases for Microprofile Rest client
---
systests/microprofile/client/tracing/pom.xml | 162 ++++++++++++++++++
.../microprofile/rest/client/tracing/Book.java | 52 ++++++
.../rest/client/tracing/BookRestClient.java | 34 ++++
.../rest/client/tracing/BookStore.java | 59 +++++++
.../client/tracing/brave/BraveTracingTest.java | 190 +++++++++++++++++++++
.../client/tracing/brave/TestSpanReporter.java | 43 +++++
systests/microprofile/pom.xml | 1 +
7 files changed, 541 insertions(+)
diff --git a/systests/microprofile/client/tracing/pom.xml
b/systests/microprofile/client/tracing/pom.xml
new file mode 100644
index 0000000..46a7ded
--- /dev/null
+++ b/systests/microprofile/client/tracing/pom.xml
@@ -0,0 +1,162 @@
+<?xml version="1.0"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>cxf-microprofile-tck</artifactId>
+ <groupId>org.apache.cxf.systests</groupId>
+ <version>3.3.2-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.cxf.systests</groupId>
+ <artifactId>cxf-systests-microprofile-tracing</artifactId>
+ <name>Apache CXF MicroProfile Tracing integration Sys Tests</name>
+ <description>Apache CXF System Tests - verifying MicroProfile Rest Client
integration with Tracing</description>
+ <url>http://cxf.apache.org</url>
+ <properties>
+
<cxf.module.name>org.apache.cxf.systests.microprofile.tracing</cxf.module.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.microprofile.rest.client</groupId>
+ <artifactId>microprofile-rest-client-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.config</groupId>
+ <artifactId>geronimo-config-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-mp-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-integration-tracing-brave</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-plus</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>apache-jsp</artifactId>
+ <version>${cxf.jetty.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.glassfish</groupId>
+ <artifactId>javax.el</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.ow2.asm</groupId>
+ <artifactId>asm-commons</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-testutils</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-testutils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <classifier>keys</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-hc</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git
a/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/Book.java
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/Book.java
new file mode 100644
index 0000000..aae3832
--- /dev/null
+++
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/Book.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.microprofile.rest.client.tracing;
+
+public class Book {
+ private String title;
+ private String id;
+
+ public Book() {
+ }
+
+ public Book(String id) {
+ this.id = id;
+ }
+
+ public Book(String title, String id) {
+ this.title = title;
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public void setId(String i) {
+ id = i;
+ }
+
+ public String getId() {
+ return id;
+ }
+}
diff --git
a/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/BookRestClient.java
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/BookRestClient.java
new file mode 100644
index 0000000..0627079
--- /dev/null
+++
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/BookRestClient.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.microprofile.rest.client.tracing;
+
+import java.util.Collection;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/bookstore")
+@Produces(MediaType.APPLICATION_JSON)
+public interface BookRestClient {
+ @GET
+ @Path("/books")
+ Collection<Book> getBooks();
+}
diff --git
a/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/BookStore.java
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/BookStore.java
new file mode 100644
index 0000000..e3d8143
--- /dev/null
+++
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/BookStore.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.microprofile.rest.client.tracing;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.tracing.TracerContext;
+
+@Path("/bookstore/")
+public class BookStore<T extends Closeable> {
+ @Context private TracerContext tracer;
+
+ @GET
+ @Path("/books")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Collection< Book > getBooks() throws IOException {
+ try (T span = tracer.startSpan("Get Books")) {
+ return Arrays.asList(
+ new Book("Apache CXF in Action", UUID.randomUUID().toString()),
+ new Book("Mastering Apache CXF", UUID.randomUUID().toString())
+ );
+ }
+ }
+
+ @GET
+ @Path("/book/{id}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Book getBook(@PathParam("id") final String id) {
+ tracer.annotate("book-id", id);
+ return new Book("Apache CXF in Action", id);
+ }
+}
diff --git
a/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/brave/BraveTracingTest.java
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/brave/BraveTracingTest.java
new file mode 100644
index 0000000..68ca0a9
--- /dev/null
+++
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/brave/BraveTracingTest.java
@@ -0,0 +1,190 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.microprofile.rest.client.tracing.brave;
+
+import java.net.URI;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
+import brave.ScopedSpan;
+import brave.Tracing;
+import brave.sampler.Sampler;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.systest.microprofile.rest.client.tracing.BookRestClient;
+import org.apache.cxf.systest.microprofile.rest.client.tracing.BookStore;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.tracing.brave.TraceScope;
+import org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider;
+import org.apache.cxf.tracing.brave.jaxrs.BraveFeature;
+import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit;
+import org.eclipse.microprofile.rest.client.RestClientBuilder;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+import static org.junit.Assert.assertTrue;
+
+public class BraveTracingTest extends AbstractBusClientServerTestBase {
+ public static final String PORT = allocatePort(BraveTracingTest.class);
+
+ private Tracing brave;
+ private BraveClientProvider braveClientProvider;
+
+ @Ignore
+ public static class Server extends AbstractBusTestServerBase {
+ protected void run() {
+ final Tracing brave = Tracing
+ .newBuilder()
+ .spanReporter(new TestSpanReporter())
+ .sampler(Sampler.ALWAYS_SAMPLE)
+ .build();
+
+ final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setResourceClasses(BookStore.class);
+ sf.setResourceProvider(BookStore.class, new
SingletonResourceProvider(new BookStore<TraceScope>()));
+ sf.setAddress("http://localhost:" + PORT);
+ sf.setProvider(new JacksonJsonProvider());
+ sf.setProvider(new BraveFeature(brave));
+ sf.create();
+ }
+ }
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ //keep out of process due to stack traces testing failures
+ assertTrue("server did not launch correctly",
launchServer(Server.class, true));
+ createStaticBus();
+ }
+
+ @Before
+ public void setUp() {
+ TestSpanReporter.clear();
+
+ brave = Tracing
+ .newBuilder()
+ .spanReporter(new TestSpanReporter())
+ .sampler(Sampler.ALWAYS_SAMPLE)
+ .build();
+
+ braveClientProvider = new BraveClientProvider(brave);
+ }
+
+ @Test
+ public void testThatNewSpanIsCreatedWhenNotProvided() {
+ final BookRestClient client = createRestClient();
+ assertThat(client.getBooks(), hasSize(2));
+
+ assertThat(TestSpanReporter.getAllSpans().size(),
+ equalTo(3));
+ assertThat(TestSpanReporter.getAllSpans().get(0).name(),
+ equalTo("get books"));
+ assertThat(TestSpanReporter.getAllSpans().get(1).name(),
+ equalTo("get /bookstore/books"));
+ assertThat(TestSpanReporter.getAllSpans().get(2).name(),
+ equalTo("get http://localhost:" + PORT + "/bookstore/books"));
+ }
+
+ @Test
+ public void testThatNewSpanIsCreatedWhenNotProvidedWithAsyncConduit() {
+ final BookRestClient client = createAsyncRestClient();
+ assertThat(client.getBooks(), hasSize(2));
+
+ assertThat(TestSpanReporter.getAllSpans().size(),
+ equalTo(3));
+ assertThat(TestSpanReporter.getAllSpans().get(0).name(),
+ equalTo("get books"));
+ assertThat(TestSpanReporter.getAllSpans().get(1).name(),
+ equalTo("get /bookstore/books"));
+ assertThat(TestSpanReporter.getAllSpans().get(2).name(),
+ equalTo("get http://localhost:" + PORT + "/bookstore/books"));
+ }
+
+ @Test
+ public void testThatNewInnerSpanIsCreated() {
+ final ScopedSpan span = brave.tracer().startScopedSpan("calling book
service");
+
+ try {
+ final BookRestClient client = createRestClient();
+ assertThat(client.getBooks(), hasSize(2));
+ } finally {
+ span.finish();
+ }
+
+ assertThat(TestSpanReporter.getAllSpans().size(),
+ equalTo(4));
+ assertThat(TestSpanReporter.getAllSpans().get(0).name(),
+ equalTo("get books"));
+ assertThat(TestSpanReporter.getAllSpans().get(1).name(),
+ equalTo("get /bookstore/books"));
+ assertThat(TestSpanReporter.getAllSpans().get(2).name(),
+ equalTo("get http://localhost:" + PORT + "/bookstore/books"));
+ assertThat(TestSpanReporter.getAllSpans().get(3).name(),
+ equalTo("calling book service"));
+ }
+
+ @Test
+ public void testThatNewInnerSpanIsCreatedWithAsyncConduit() {
+ final ScopedSpan span = brave.tracer().startScopedSpan("calling book
service");
+
+ try {
+ final BookRestClient client = createAsyncRestClient();
+ assertThat(client.getBooks(), hasSize(2));
+ } finally {
+ span.finish();
+ }
+
+ assertThat(TestSpanReporter.getAllSpans().size(),
+ equalTo(4));
+ assertThat(TestSpanReporter.getAllSpans().get(0).name(),
+ equalTo("get books"));
+ assertThat(TestSpanReporter.getAllSpans().get(1).name(),
+ equalTo("get /bookstore/books"));
+ assertThat(TestSpanReporter.getAllSpans().get(2).name(),
+ equalTo("get http://localhost:" + PORT + "/bookstore/books"));
+ assertThat(TestSpanReporter.getAllSpans().get(3).name(),
+ equalTo("calling book service"));
+ }
+
+ private BookRestClient createAsyncRestClient() {
+ return createRestClientBuilder()
+ .property(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE)
+ .build(BookRestClient.class);
+ }
+
+ private BookRestClient createRestClient() {
+ return createRestClientBuilder()
+ .build(BookRestClient.class);
+ }
+
+ private RestClientBuilder createRestClientBuilder() {
+ return RestClientBuilder.newBuilder()
+ .baseUri(URI.create("http://localhost:" + PORT))
+ .register(JacksonJsonProvider.class)
+ .register(braveClientProvider);
+ }
+}
diff --git
a/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/brave/TestSpanReporter.java
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/brave/TestSpanReporter.java
new file mode 100644
index 0000000..0cb6c9d
--- /dev/null
+++
b/systests/microprofile/client/tracing/src/test/java/org/apache/cxf/systest/microprofile/rest/client/tracing/brave/TestSpanReporter.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.microprofile.rest.client.tracing.brave;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import zipkin2.Span;
+import zipkin2.reporter.Reporter;
+
+public class TestSpanReporter implements Reporter<Span> {
+ private static List<Span> spans = Collections.synchronizedList(new
ArrayList<>());
+
+ @Override
+ public void report(Span span) {
+ spans.add(span);
+ }
+
+ public static List<Span> getAllSpans() {
+ return spans;
+ }
+
+ public static void clear() {
+ spans.clear();
+ }
+}
diff --git a/systests/microprofile/pom.xml b/systests/microprofile/pom.xml
index ca32506..e41bf89 100644
--- a/systests/microprofile/pom.xml
+++ b/systests/microprofile/pom.xml
@@ -133,6 +133,7 @@
<modules>
<module>client/async</module>
<module>client/jaxrs</module>
+ <module>client/tracing</module>
<module>client/weld</module>
</modules>
</project>