-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add conformance tests for lite runtime #148
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
conformance/common/src/main/kotlin/com/connectrpc/conformance/BaseConformanceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Copyright 2022-2023 The Connect Authors | ||
// | ||
// 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. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.connectrpc.conformance | ||
|
||
import com.connectrpc.ProtocolClientConfig | ||
import com.connectrpc.RequestCompression | ||
import com.connectrpc.SerializationStrategy | ||
import com.connectrpc.compression.GzipCompressionPool | ||
import com.connectrpc.conformance.ssl.sslContext | ||
import com.connectrpc.impl.ProtocolClient | ||
import com.connectrpc.okhttp.ConnectOkHttpClient | ||
import com.connectrpc.protocols.NetworkProtocol | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Protocol | ||
import org.junit.ClassRule | ||
import org.junit.runners.Parameterized | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy | ||
import java.time.Duration | ||
import java.util.Base64 | ||
|
||
abstract class BaseConformanceTest( | ||
private val protocol: NetworkProtocol, | ||
private val serverType: ServerType, | ||
) { | ||
lateinit var connectClient: ProtocolClient | ||
lateinit var shortTimeoutConnectClient: ProtocolClient | ||
|
||
companion object { | ||
private const val CONFORMANCE_VERSION = "88f85130640b46c0837e0d58c0484d83a110f418" | ||
|
||
@JvmStatic | ||
@Parameterized.Parameters(name = "client={0},server={1}") | ||
fun data(): Iterable<Array<Any>> { | ||
return arrayListOf( | ||
arrayOf(NetworkProtocol.CONNECT, ServerType.CONNECT_GO), | ||
arrayOf(NetworkProtocol.GRPC, ServerType.CONNECT_GO), | ||
arrayOf(NetworkProtocol.GRPC_WEB, ServerType.CONNECT_GO), | ||
arrayOf(NetworkProtocol.GRPC, ServerType.GRPC_GO), | ||
) | ||
} | ||
|
||
@JvmField | ||
@ClassRule | ||
val CONFORMANCE_CONTAINER_CONNECT = GenericContainer("connectrpc/conformance:$CONFORMANCE_VERSION") | ||
.withExposedPorts(8080, 8081) | ||
.withCommand( | ||
"/usr/local/bin/serverconnect", | ||
"--h1port", | ||
"8080", | ||
"--h2port", | ||
"8081", | ||
"--cert", | ||
"cert/localhost.crt", | ||
"--key", | ||
"cert/localhost.key", | ||
) | ||
.waitingFor(HostPortWaitStrategy().forPorts(8081)) | ||
|
||
@JvmField | ||
@ClassRule | ||
val CONFORMANCE_CONTAINER_GRPC = GenericContainer("connectrpc/conformance:$CONFORMANCE_VERSION") | ||
.withExposedPorts(8081) | ||
.withCommand( | ||
"/usr/local/bin/servergrpc", | ||
"--port", | ||
"8081", | ||
"--cert", | ||
"cert/localhost.crt", | ||
"--key", | ||
"cert/localhost.key", | ||
) | ||
.waitingFor(HostPortWaitStrategy().forPorts(8081)) | ||
} | ||
|
||
fun init(serializationStrategy: SerializationStrategy) { | ||
val serverPort = if (serverType == ServerType.CONNECT_GO) CONFORMANCE_CONTAINER_CONNECT.getMappedPort(8081) else CONFORMANCE_CONTAINER_GRPC.getMappedPort(8081) | ||
val host = "https://localhost:$serverPort" | ||
val (sslSocketFactory, trustManager) = sslContext() | ||
val client = OkHttpClient.Builder() | ||
.protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1)) | ||
.connectTimeout(Duration.ofMinutes(1)) | ||
.readTimeout(Duration.ofMinutes(1)) | ||
.writeTimeout(Duration.ofMinutes(1)) | ||
.callTimeout(Duration.ofMinutes(1)) | ||
.sslSocketFactory(sslSocketFactory, trustManager) | ||
.build() | ||
shortTimeoutConnectClient = ProtocolClient( | ||
httpClient = ConnectOkHttpClient( | ||
client.newBuilder() | ||
.connectTimeout(Duration.ofMillis(1)) | ||
.readTimeout(Duration.ofMillis(1)) | ||
.writeTimeout(Duration.ofMillis(1)) | ||
.callTimeout(Duration.ofMillis(1)) | ||
.build(), | ||
), | ||
ProtocolClientConfig( | ||
host = host, | ||
serializationStrategy = serializationStrategy, | ||
networkProtocol = protocol, | ||
requestCompression = RequestCompression(10, GzipCompressionPool), | ||
compressionPools = listOf(GzipCompressionPool), | ||
), | ||
) | ||
connectClient = ProtocolClient( | ||
httpClient = ConnectOkHttpClient(client), | ||
ProtocolClientConfig( | ||
host = host, | ||
serializationStrategy = serializationStrategy, | ||
networkProtocol = protocol, | ||
requestCompression = RequestCompression(10, GzipCompressionPool), | ||
compressionPools = listOf(GzipCompressionPool), | ||
), | ||
) | ||
} | ||
|
||
fun b64Encode(trailingValue: ByteArray): String { | ||
return String(Base64.getEncoder().encode(trailingValue)) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,12 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.connectrpc.conformance | ||
package com.connectrpc.conformance.java | ||
|
||
import com.connectrpc.Code | ||
import com.connectrpc.ConnectException | ||
import com.connectrpc.ProtocolClientConfig | ||
import com.connectrpc.RequestCompression | ||
import com.connectrpc.compression.GzipCompressionPool | ||
import com.connectrpc.conformance.ssl.sslContext | ||
import com.connectrpc.conformance.BaseConformanceTest | ||
import com.connectrpc.conformance.ServerType | ||
import com.connectrpc.conformance.v1.ErrorDetail | ||
import com.connectrpc.conformance.v1.PayloadType | ||
import com.connectrpc.conformance.v1.StreamingOutputCallResponse | ||
|
@@ -34,8 +32,6 @@ import com.connectrpc.conformance.v1.streamingInputCallRequest | |
import com.connectrpc.conformance.v1.streamingOutputCallRequest | ||
import com.connectrpc.extensions.GoogleJavaProtobufStrategy | ||
import com.connectrpc.getOrThrow | ||
import com.connectrpc.impl.ProtocolClient | ||
import com.connectrpc.okhttp.ConnectOkHttpClient | ||
import com.connectrpc.protocols.NetworkProtocol | ||
import com.google.protobuf.ByteString | ||
import com.google.protobuf.empty | ||
|
@@ -44,120 +40,27 @@ import kotlinx.coroutines.async | |
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.withContext | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Protocol | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.fail | ||
import org.junit.Before | ||
import org.junit.ClassRule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import org.junit.runners.Parameterized.Parameters | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy | ||
import java.time.Duration | ||
import java.util.Base64 | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
@RunWith(Parameterized::class) | ||
class Conformance( | ||
private val protocol: NetworkProtocol, | ||
private val serverType: ServerType, | ||
) { | ||
private lateinit var connectClient: ProtocolClient | ||
private lateinit var shortTimeoutConnectClient: ProtocolClient | ||
class ConformanceTest( | ||
protocol: NetworkProtocol, | ||
serverType: ServerType, | ||
): BaseConformanceTest(protocol, serverType) { | ||
|
||
private lateinit var unimplementedServiceClient: UnimplementedServiceClient | ||
private lateinit var testServiceConnectClient: TestServiceClient | ||
|
||
companion object { | ||
private const val CONFORMANCE_VERSION = "88f85130640b46c0837e0d58c0484d83a110f418" | ||
|
||
@JvmStatic | ||
@Parameters(name = "client={0},server={1}") | ||
fun data(): Iterable<Array<Any>> { | ||
return arrayListOf( | ||
arrayOf(NetworkProtocol.CONNECT, ServerType.CONNECT_GO), | ||
arrayOf(NetworkProtocol.GRPC, ServerType.CONNECT_GO), | ||
arrayOf(NetworkProtocol.GRPC_WEB, ServerType.CONNECT_GO), | ||
arrayOf(NetworkProtocol.GRPC, ServerType.GRPC_GO), | ||
) | ||
} | ||
|
||
@JvmField | ||
@ClassRule | ||
val CONFORMANCE_CONTAINER_CONNECT = GenericContainer("connectrpc/conformance:$CONFORMANCE_VERSION") | ||
.withExposedPorts(8080, 8081) | ||
.withCommand( | ||
"/usr/local/bin/serverconnect", | ||
"--h1port", | ||
"8080", | ||
"--h2port", | ||
"8081", | ||
"--cert", | ||
"cert/localhost.crt", | ||
"--key", | ||
"cert/localhost.key", | ||
) | ||
.waitingFor(HostPortWaitStrategy().forPorts(8081)) | ||
|
||
@JvmField | ||
@ClassRule | ||
val CONFORMANCE_CONTAINER_GRPC = GenericContainer("connectrpc/conformance:$CONFORMANCE_VERSION") | ||
.withExposedPorts(8081) | ||
.withCommand( | ||
"/usr/local/bin/servergrpc", | ||
"--port", | ||
"8081", | ||
"--cert", | ||
"cert/localhost.crt", | ||
"--key", | ||
"cert/localhost.key", | ||
) | ||
.waitingFor(HostPortWaitStrategy().forPorts(8081)) | ||
} | ||
|
||
@Before | ||
fun before() { | ||
val serverPort = if (serverType == ServerType.CONNECT_GO) CONFORMANCE_CONTAINER_CONNECT.getMappedPort(8081) else CONFORMANCE_CONTAINER_GRPC.getMappedPort(8081) | ||
val host = "https://localhost:$serverPort" | ||
val (sslSocketFactory, trustManager) = sslContext() | ||
val client = OkHttpClient.Builder() | ||
.protocols(listOf(Protocol.HTTP_2, Protocol.HTTP_1_1)) | ||
.connectTimeout(Duration.ofMinutes(1)) | ||
.readTimeout(Duration.ofMinutes(1)) | ||
.writeTimeout(Duration.ofMinutes(1)) | ||
.callTimeout(Duration.ofMinutes(1)) | ||
.sslSocketFactory(sslSocketFactory, trustManager) | ||
.build() | ||
shortTimeoutConnectClient = ProtocolClient( | ||
httpClient = ConnectOkHttpClient( | ||
client.newBuilder() | ||
.connectTimeout(Duration.ofMillis(1)) | ||
.readTimeout(Duration.ofMillis(1)) | ||
.writeTimeout(Duration.ofMillis(1)) | ||
.callTimeout(Duration.ofMillis(1)) | ||
.build(), | ||
), | ||
ProtocolClientConfig( | ||
host = host, | ||
serializationStrategy = GoogleJavaProtobufStrategy(), | ||
networkProtocol = protocol, | ||
requestCompression = RequestCompression(10, GzipCompressionPool), | ||
compressionPools = listOf(GzipCompressionPool), | ||
), | ||
) | ||
connectClient = ProtocolClient( | ||
httpClient = ConnectOkHttpClient(client), | ||
ProtocolClientConfig( | ||
host = host, | ||
serializationStrategy = GoogleJavaProtobufStrategy(), | ||
networkProtocol = protocol, | ||
requestCompression = RequestCompression(10, GzipCompressionPool), | ||
compressionPools = listOf(GzipCompressionPool), | ||
), | ||
) | ||
init(GoogleJavaProtobufStrategy()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only real change between the two clients. |
||
testServiceConnectClient = TestServiceClient(connectClient) | ||
unimplementedServiceClient = UnimplementedServiceClient(connectClient) | ||
} | ||
|
@@ -798,8 +701,4 @@ class Conformance( | |
assertThat(countDownLatch.count).isZero() | ||
} | ||
} | ||
|
||
private fun b64Encode(trailingValue: ByteArray): String { | ||
return String(Base64.getEncoder().encode(trailingValue)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ sourceSets { | |
|
||
dependencies { | ||
implementation(libs.kotlin.coroutines.core) | ||
implementation(libs.protobuf.kotlin) | ||
implementation(libs.protobuf.kotlinlite) | ||
implementation(project(":conformance:common")) | ||
implementation(project(":extensions:google-java")) | ||
implementation(project(":extensions:google-javalite")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These dependencies weren't correct before. |
||
implementation(project(":okhttp")) | ||
|
||
testImplementation(libs.okhttp.core) | ||
|
@@ -33,4 +33,5 @@ dependencies { | |
testImplementation(libs.mockito) | ||
testImplementation(libs.kotlin.coroutines.core) | ||
testImplementation(libs.testcontainers) | ||
testImplementation(libs.slf4j.simple) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the lite tests to use generated code with the same args as the full runtime tests.