From 94ac6cf7f124fb8a913e21856a5c5d91e1bae73b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 25 Apr 2019 11:28:52 +0800 Subject: [PATCH] moves to square/wire based tests in kotlin --- benchmarks/pom.xml | 2 +- pom.xml | 25 ++++- zipkin-server/pom.xml | 95 +++++++++++++------ .../internal/ITZipkinGrpcCollector.java | 69 -------------- .../server/internal/ITZipkinGrpcCollector.kt | 85 +++++++++++++++++ 5 files changed, 173 insertions(+), 103 deletions(-) delete mode 100644 zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinGrpcCollector.java create mode 100644 zipkin-server/src/test/kotlin/zipkin2/server/internal/ITZipkinGrpcCollector.kt diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 009b2e688ce..0ae57bb421b 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -80,7 +80,7 @@ ${wire.version} - io.zipkin.proto3 + org.apache.zipkin.proto3 zipkin-proto3 diff --git a/pom.xml b/pom.xml index 8f4b34ff8f2..6e34b0a9418 100755 --- a/pom.xml +++ b/pom.xml @@ -154,6 +154,26 @@ https://github.com/openzipkin/zipkin/issues + + + apache.snapshots.https + https://repository.apache.org/content/repositories/snapshots/ + + false + + + + + + + apache.snapshots.https + https://repository.apache.org/content/repositories/snapshots/ + + false + + + + @@ -362,9 +382,9 @@ - io.zipkin.proto3 + org.apache.zipkin.proto3 zipkin-proto3 - 0.2.0 + 0.2.1-SNAPSHOT com.squareup.wire @@ -627,6 +647,7 @@ SLASHSTAR_STYLE + SLASHSTAR_STYLE .travis.yml diff --git a/zipkin-server/pom.xml b/zipkin-server/pom.xml index c51e5b58ead..c90419633bf 100644 --- a/zipkin-server/pom.xml +++ b/zipkin-server/pom.xml @@ -34,6 +34,7 @@ 1.8 java18 zipkin.server.ZipkinServer + 1.3.30 3.2.0 @@ -47,6 +48,13 @@ pom import + + com.linecorp.armeria + armeria-bom + ${armeria.version} + pom + import + @@ -66,22 +74,18 @@ com.linecorp.armeria armeria-spring-boot-autoconfigure - ${armeria.version} com.linecorp.armeria armeria-spring-boot-actuator-starter - ${armeria.version} com.linecorp.armeria armeria-zipkin - ${armeria.version} com.linecorp.armeria armeria-grpc-protocol - ${armeria.version} @@ -126,28 +130,22 @@ 1.11.3 - + - io.grpc - grpc-testing - ${grpc.version} - test - - - io.grpc - grpc-protobuf - ${grpc.version} + org.apache.zipkin.proto3 + zipkin-proto3 test - io.zipkin.proto3 - zipkin-proto3 + com.squareup.wire + wire-grpc-client + ${wire.version} test - io.grpc - grpc-netty-shaded - ${grpc.version} + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} test @@ -374,35 +372,70 @@ - + maven-dependency-plugin - org.xolstice.maven.plugins - protobuf-maven-plugin + com.squareup.wire + wire-maven-plugin - - test-compile-proto + generate-test-sources - test-compile + generate-sources + + ${project.build.directory}/generated-test-sources/wire + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + enable + + + + compile + none - test-compile-proto-service + test-compile - test-compile-custom + test-compile - grpc-java - - io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} - + + ${project.basedir}/src/test/kotlin + ${project.basedir}/src/test/java + ${project.build.directory}/generated-test-sources/wire + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + + default-testCompile + none + + + java-test-compile + test-compile + + testCompile + + + + org.springframework.boot spring-boot-maven-plugin diff --git a/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinGrpcCollector.java b/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinGrpcCollector.java deleted file mode 100644 index bac10edf439..00000000000 --- a/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinGrpcCollector.java +++ /dev/null @@ -1,69 +0,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. - */ -package zipkin2.server.internal; - -import com.linecorp.armeria.server.Server; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import zipkin.server.ZipkinServer; -import zipkin2.TestObjects; -import zipkin2.codec.SpanBytesEncoder; -import zipkin2.proto3.ListOfSpans; -import zipkin2.proto3.SpanServiceGrpc; -import zipkin2.storage.InMemoryStorage; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest( - classes = ZipkinServer.class, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { - "spring.config.name=zipkin-server", - "zipkin.collector.grpc.enabled=true" - }) -@RunWith(SpringRunner.class) -public class ITZipkinGrpcCollector { - @Autowired InMemoryStorage storage; - @Autowired Server server; - - @Test public void report_withGoogleGrpcLibrary() throws Exception { - ListOfSpans message = - ListOfSpans.parseFrom(SpanBytesEncoder.PROTO3.encodeList(TestObjects.TRACE)); - - // sanity check the encoding is the same by spot checking a middle field - for (int i = 0, length = TestObjects.TRACE.size(); i < length; i++) { - assertThat(message.getSpans(i).getLocalEndpoint().getServiceName()) - .isEqualTo(TestObjects.TRACE.get(i).localServiceName()); - } - - ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", - server.activePort().get().localAddress().getPort()).usePlaintext().build(); - try { - SpanServiceGrpc.newBlockingStub(channel).report(message); - } finally { - channel.shutdown(); - } - - assertThat(storage.getTraces()) - .containsExactly(TestObjects.TRACE); - } -} diff --git a/zipkin-server/src/test/kotlin/zipkin2/server/internal/ITZipkinGrpcCollector.kt b/zipkin-server/src/test/kotlin/zipkin2/server/internal/ITZipkinGrpcCollector.kt new file mode 100644 index 00000000000..c87d133ef3d --- /dev/null +++ b/zipkin-server/src/test/kotlin/zipkin2/server/internal/ITZipkinGrpcCollector.kt @@ -0,0 +1,85 @@ +/* + * 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 zipkin2.server.internal + +import com.linecorp.armeria.server.Server +import com.squareup.wire.GrpcClient +import com.squareup.wire.Service +import com.squareup.wire.WireRpc +import kotlinx.coroutines.runBlocking +import okhttp3.OkHttpClient +import okhttp3.Protocol +import org.assertj.core.api.Assertions.assertThat +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.junit4.SpringRunner +import zipkin.server.ZipkinServer +import zipkin2.Span +import zipkin2.TestObjects +import zipkin2.codec.SpanBytesDecoder +import zipkin2.codec.SpanBytesEncoder +import zipkin2.proto3.ListOfSpans +import zipkin2.proto3.ReportResponse +import zipkin2.storage.InMemoryStorage + +@SpringBootTest(classes = [ZipkinServer::class], + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = ["spring.config.name=zipkin-server", "zipkin.collector.grpc.enabled=true"]) +@RunWith(SpringRunner::class) +// Written in Kotlin as Square Wire's grpc client is Kotlin. +// Also, the first author of this test wanted an excuse to write Kotlin. +class ITZipkinGrpcCollector { + @Autowired lateinit var storage: InMemoryStorage + @Autowired lateinit var server: Server + + var request = ListOfSpans.ADAPTER.decode(SpanBytesEncoder.PROTO3.encodeList(TestObjects.TRACE)) + lateinit var spanService: SpanService + + interface SpanService : Service { + @WireRpc( + path = "/zipkin.proto3.SpanService/Report", + requestAdapter = "zipkin2.proto3.ListOfSpans#ADAPTER", + responseAdapter = "zipkin2.proto3.ReportResponse#ADAPTER" + ) + suspend fun Report(request: ListOfSpans): ReportResponse + } + + @Before fun sanityCheckCodecCompatible() { + assertThat(SpanBytesDecoder.PROTO3.decodeList(request.encode())) + .containsExactlyElementsOf(TestObjects.TRACE) + } + + @Before fun createClient() { + spanService = GrpcClient.Builder() + .client(OkHttpClient.Builder().protocols(listOf(Protocol.H2_PRIOR_KNOWLEDGE)).build()) + .baseUrl("http://localhost:" + server.activePort().get().localAddress().port) + .build().create(SpanService::class) + } + + /** This tests that we accept messages constructed by other clients. */ + @Test fun report_withWireGrpcLibrary() { + runBlocking { + spanService.Report(request) // Result is effectively void + } + assertThat>(storage.traces) + .containsExactly(TestObjects.TRACE) + } +}