Skip to content

Commit

Permalink
moves to square/wire based tests in kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Apr 25, 2019
1 parent 7e86319 commit 94ac6cf
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 103 deletions.
2 changes: 1 addition & 1 deletion benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<version>${wire.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.proto3</groupId>
<groupId>org.apache.zipkin.proto3</groupId>
<artifactId>zipkin-proto3</artifactId>
</dependency>
</dependencies>
Expand Down
25 changes: 23 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@
<url>https://github.com/openzipkin/zipkin/issues</url>
</issueManagement>

<repositories>
<repository>
<id>apache.snapshots.https</id>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>apache.snapshots.https</id>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -362,9 +382,9 @@
</dependency>

<dependency>
<groupId>io.zipkin.proto3</groupId>
<groupId>org.apache.zipkin.proto3</groupId>
<artifactId>zipkin-proto3</artifactId>
<version>0.2.0</version>
<version>0.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.squareup.wire</groupId>
Expand Down Expand Up @@ -627,6 +647,7 @@
<mapping>
<!-- Don't use javadoc style as this makes code formatters break it by adding tags! -->
<java>SLASHSTAR_STYLE</java>
<kt>SLASHSTAR_STYLE</kt>
</mapping>
<excludes>
<exclude>.travis.yml</exclude>
Expand Down
95 changes: 64 additions & 31 deletions zipkin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<main.java.version>1.8</main.java.version>
<main.signature.artifact>java18</main.signature.artifact>
<start-class>zipkin.server.ZipkinServer</start-class>
<kotlin.version>1.3.30</kotlin.version>
<maven-invoker-plugin.version>3.2.0</maven-invoker-plugin.version>
</properties>

Expand All @@ -47,6 +48,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.linecorp.armeria</groupId>
<artifactId>armeria-bom</artifactId>
<version>${armeria.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -66,22 +74,18 @@
<dependency>
<groupId>com.linecorp.armeria</groupId>
<artifactId>armeria-spring-boot-autoconfigure</artifactId>
<version>${armeria.version}</version>
</dependency>
<dependency>
<groupId>com.linecorp.armeria</groupId>
<artifactId>armeria-spring-boot-actuator-starter</artifactId>
<version>${armeria.version}</version>
</dependency>
<dependency>
<groupId>com.linecorp.armeria</groupId>
<artifactId>armeria-zipkin</artifactId>
<version>${armeria.version}</version>
</dependency>
<dependency>
<groupId>com.linecorp.armeria</groupId>
<artifactId>armeria-grpc-protocol</artifactId>
<version>${armeria.version}</version>
</dependency>

<!-- zipkin requires exporting /health endpoint -->
Expand Down Expand Up @@ -126,28 +130,22 @@
<version>1.11.3</version>
</dependency>

<!-- to test the experimental grpc endpoint with google's library -->
<!-- to test the experimental grpc endpoint with the square/wire library -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-testing</artifactId>
<version>${grpc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
<groupId>org.apache.zipkin.proto3</groupId>
<artifactId>zipkin-proto3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zipkin.proto3</groupId>
<artifactId>zipkin-proto3</artifactId>
<groupId>com.squareup.wire</groupId>
<artifactId>wire-grpc-client</artifactId>
<version>${wire.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc.version}</version>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -374,35 +372,70 @@
</resource>
</resources>
<plugins>
<!-- protobuf-maven-plugin cannot get proto definitions from dependencies, so we will -->
<!-- wire-maven-plugin cannot get proto definitions from dependencies, so we will -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<groupId>com.squareup.wire</groupId>
<artifactId>wire-maven-plugin</artifactId>
<executions>
<!-- structs need to be compiled before the service that uses them -->
<execution>
<id>test-compile-proto</id>
<phase>generate-test-sources</phase>
<goals>
<goal>test-compile</goal>
<goal>generate-sources</goal>
</goals>
<configuration>
<generatedSourceDirectory>${project.build.directory}/generated-test-sources/wire</generatedSourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<experimentalCoroutines>enable</experimentalCoroutines>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>none</phase>
</execution>
<execution>
<id>test-compile-proto-service</id>
<id>test-compile</id>
<goals>
<goal>test-compile-custom</goal>
<goal>test-compile</goal>
</goals>
<configuration>
<pluginId>grpc-java</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
</pluginArtifact>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
<sourceDir>${project.build.directory}/generated-test-sources/wire</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<executions>
<!-- Defer test compilation to the kotlin plugin -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<List<Span>>(storage.traces)
.containsExactly(TestObjects.TRACE)
}
}

0 comments on commit 94ac6cf

Please sign in to comment.