Skip to content

Commit

Permalink
fix: gets tests running again (grpc#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Apr 8, 2020
1 parent 4d5ca9e commit 8f766cd
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 76 deletions.
40 changes: 40 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
id 'org.jetbrains.kotlin.jvm' version'1.3.61' apply false
}
Expand Down Expand Up @@ -122,6 +125,43 @@ subprojects {
}
}
}

tasks.withType(Test) {
testLogging {
showStandardStreams = true
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true

// set options for log level DEBUG and INFO
debug {
events TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat

afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
}

def artifactForGradlePlugin(MavenPublication pub, String os, String arch) {
Expand Down
7 changes: 0 additions & 7 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,3 @@ protobuf {
}
}
}

test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class GrpcClientStubGenerator(config: GeneratorConfig) : ServiceCodeGenerator(co
"""
Returns a [%flow:T] that, when collected, executes this RPC and emits responses from the
server as they arrive. That flow finishes normally if the server closes its response with
[`Status.OK`][%status:T], and fails by throwing a [%statusException:T] otherwise. If
[`Status.OK`][%status:T], and fails by throwing a [%statusException:T] otherwise. If
collecting the flow downstream fails exceptionally (including via cancellation), the RPC
is cancelled with that exception as a cause.
""".trimIndent()
Expand All @@ -237,8 +237,8 @@ class GrpcClientStubGenerator(config: GeneratorConfig) : ServiceCodeGenerator(co
MethodType.BIDI_STREAMING -> {
kDocComponents.add(
"""
The [%flow:T] of requests is collected once each time the [%flow:T] of responses is
collected. If collection of the [%flow:T] of responses completes normally or
The [%flow:T] of requests is collected once each time the [%flow:T] of responses is
collected. If collection of the [%flow:T] of responses completes normally or
exceptionally before collection of `%parameter:N` completes, the collection of
`%parameter:N` is cancelled. If the collection of `%parameter:N` completes
exceptionally for any other reason, then the collection of the [%flow:T] of responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class GrpcCoroutineServerGenerator(config: GeneratorConfig): ServiceCodeGenerato
.addModifiers(KModifier.ABSTRACT)
.addKdoc(
"""
Skeletal implementation of the %L service based on Kotlin coroutines.
Skeletal implementation of the %L service based on Kotlin coroutines.
""".trimIndent(),
service.fullName
)
Expand Down Expand Up @@ -219,7 +219,7 @@ class GrpcCoroutineServerGenerator(config: GeneratorConfig): ServiceCodeGenerato
If creating or collecting the returned flow fails with a [%statusException:T], the RPC
will fail with the corresponding [%status:T]. If it fails with a
[%cancellationException:T], the RPC will fail with status `Status.CANCELLED`. If creating
or collecting the returned flow fails for any other reason, the RPC will fail with
or collecting the returned flow fails for any other reason, the RPC will fail with
`Status.UNKNOWN` with the exception as a cause.
""".trimIndent()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import kotlinx.coroutines.flow.Flow
/**
* Skeletal implementation of the helloworld.Greeter service based on Kotlin coroutines.
*/
abstract class GreeterCoroutineImplBase(coroutineContext: CoroutineContext = EmptyCoroutineContext)
: AbstractCoroutineServerImpl(coroutineContext) {
abstract class GreeterCoroutineImplBase(
coroutineContext: CoroutineContext = EmptyCoroutineContext
) : AbstractCoroutineServerImpl(coroutineContext) {
/**
* Returns the response to an RPC for helloworld.Greeter.SayHello.
*
Expand All @@ -33,10 +34,8 @@ abstract class GreeterCoroutineImplBase(coroutineContext: CoroutineContext = Emp
*
* @param request The request from the client.
*/
open suspend fun sayHello(request: HelloRequest): HelloReply {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.SayHello is unimplemented"))
}
open suspend fun sayHello(request: HelloRequest): HelloReply = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.SayHello is unimplemented"))

/**
* Returns the response to an RPC for helloworld.Greeter.ClientStreamSayHello.
Expand All @@ -51,10 +50,8 @@ abstract class GreeterCoroutineImplBase(coroutineContext: CoroutineContext = Emp
* collected only once and throws [java.lang.IllegalStateException] on attempts to collect
* it more than once.
*/
open suspend fun clientStreamSayHello(requests: Flow<HelloRequest>): HelloReply {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ClientStreamSayHello is unimplemented"))
}
open suspend fun clientStreamSayHello(requests: Flow<HelloRequest>): HelloReply = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ClientStreamSayHello is unimplemented"))

/**
* Returns a [Flow] of responses to an RPC for helloworld.Greeter.ServerStreamSayHello.
Expand All @@ -68,10 +65,8 @@ abstract class GreeterCoroutineImplBase(coroutineContext: CoroutineContext = Emp
*
* @param request The request from the client.
*/
open fun serverStreamSayHello(request: MultiHelloRequest): Flow<HelloReply> {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ServerStreamSayHello is unimplemented"))
}
open fun serverStreamSayHello(request: MultiHelloRequest): Flow<HelloReply> = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ServerStreamSayHello is unimplemented"))

/**
* Returns a [Flow] of responses to an RPC for helloworld.Greeter.BidiStreamSayHello.
Expand All @@ -87,10 +82,8 @@ abstract class GreeterCoroutineImplBase(coroutineContext: CoroutineContext = Emp
* collected only once and throws [java.lang.IllegalStateException] on attempts to collect
* it more than once.
*/
open fun bidiStreamSayHello(requests: Flow<HelloRequest>): Flow<HelloReply> {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.BidiStreamSayHello is unimplemented"))
}
open fun bidiStreamSayHello(requests: Flow<HelloRequest>): Flow<HelloReply> = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.BidiStreamSayHello is unimplemented"))

final override fun bindService(): ServerServiceDefinition = builder(getServiceDescriptor())
.addMethod(unaryServerMethodDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import kotlinx.coroutines.flow.Flow
* A stub for issuing RPCs to a(n) helloworld.Greeter service as suspending coroutines.
*/
@StubFor(GreeterGrpc::class)
class GreeterCoroutineStub @JvmOverloads constructor(channel: Channel, callOptions: CallOptions =
DEFAULT) : AbstractCoroutineStub<GreeterCoroutineStub>(channel, callOptions) {
class GreeterCoroutineStub @JvmOverloads constructor(
channel: Channel,
callOptions: CallOptions = DEFAULT
) : AbstractCoroutineStub<GreeterCoroutineStub>(channel, callOptions) {
override fun build(channel: Channel, callOptions: CallOptions): GreeterCoroutineStub =
GreeterCoroutineStub(channel, callOptions)

Expand Down Expand Up @@ -68,7 +70,6 @@ class GreeterCoroutineStub @JvmOverloads constructor(channel: Channel, callOptio
* Returns a [Flow] that, when collected, executes this RPC and emits responses from the
* server as they arrive. That flow finishes normally if the server closes its response with
* [`Status.OK`][io.grpc.Status], and fails by throwing a [io.grpc.StatusException] otherwise. If
*
* collecting the flow downstream fails exceptionally (including via cancellation), the RPC
* is cancelled with that exception as a cause.
*
Expand All @@ -87,7 +88,6 @@ class GreeterCoroutineStub @JvmOverloads constructor(channel: Channel, callOptio
* Returns a [Flow] that, when collected, executes this RPC and emits responses from the
* server as they arrive. That flow finishes normally if the server closes its response with
* [`Status.OK`][io.grpc.Status], and fails by throwing a [io.grpc.StatusException] otherwise. If
*
* collecting the flow downstream fails exceptionally (including via cancellation), the RPC
* is cancelled with that exception as a cause.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.grpc.kotlin.generator

import com.google.common.io.Resources
import com.google.protobuf.Descriptors.MethodDescriptor
import com.google.protobuf.Descriptors.ServiceDescriptor
import io.grpc.kotlin.generator.protoc.GeneratorConfig
Expand All @@ -26,6 +25,9 @@ import io.grpc.examples.helloworld.HelloWorldProto
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths

@RunWith(JUnit4::class)
class GrpcClientStubGeneratorTest {
Expand Down Expand Up @@ -72,12 +74,12 @@ class GrpcClientStubGeneratorTest {
/**
* Returns a [kotlinx.coroutines.flow.Flow] that, when collected, executes this RPC and emits responses from the
* server as they arrive. That flow finishes normally if the server closes its response with
* [`Status.OK`][io.grpc.Status], and fails by throwing a [io.grpc.StatusException] otherwise. If
* [`Status.OK`][io.grpc.Status], and fails by throwing a [io.grpc.StatusException] otherwise. If
* collecting the flow downstream fails exceptionally (including via cancellation), the RPC
* is cancelled with that exception as a cause.
*
* The [kotlinx.coroutines.flow.Flow] of requests is collected once each time the [kotlinx.coroutines.flow.Flow] of responses is
* collected. If collection of the [kotlinx.coroutines.flow.Flow] of responses completes normally or
* The [kotlinx.coroutines.flow.Flow] of requests is collected once each time the [kotlinx.coroutines.flow.Flow] of responses is
* collected. If collection of the [kotlinx.coroutines.flow.Flow] of responses completes normally or
* exceptionally before collection of `requests` completes, the collection of
* `requests` is cancelled. If the collection of `requests` completes
* exceptionally for any other reason, then the collection of the [kotlinx.coroutines.flow.Flow] of responses
Expand All @@ -100,11 +102,15 @@ class GrpcClientStubGeneratorTest {

@Test
fun generateServiceStub() {
val expectedFileContents = Files.readAllLines(
Paths.get(
"src/test/java/io/grpc/kotlin/generator",
"GreeterCoroutineStub.expected"
),
StandardCharsets.UTF_8
)
assertThat(generator.generate(greeterServiceDescriptor)).generatesEnclosed(
Resources.toString(
Resources.getResource("io/grpc/kotlin/generator/GreeterCoroutineStub.expected"),
Charsets.UTF_8
)
expectedFileContents.joinToString("\n") + "\n"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ object GreeterGrpcKt {
* A stub for issuing RPCs to a(n) helloworld.Greeter service as suspending coroutines.
*/
@StubFor(GreeterGrpc::class)
class GreeterCoroutineStub @JvmOverloads constructor(channel: Channel, callOptions: CallOptions =
DEFAULT) : AbstractCoroutineStub<GreeterCoroutineStub>(channel, callOptions) {
class GreeterCoroutineStub @JvmOverloads constructor(
channel: Channel,
callOptions: CallOptions = DEFAULT
) : AbstractCoroutineStub<GreeterCoroutineStub>(channel, callOptions) {
override fun build(channel: Channel, callOptions: CallOptions): GreeterCoroutineStub =
GreeterCoroutineStub(channel, callOptions)

Expand Down Expand Up @@ -126,8 +128,9 @@ object GreeterGrpcKt {
/**
* Skeletal implementation of the helloworld.Greeter service based on Kotlin coroutines.
*/
abstract class GreeterCoroutineImplBase(coroutineContext: CoroutineContext =
EmptyCoroutineContext) : AbstractCoroutineServerImpl(coroutineContext) {
abstract class GreeterCoroutineImplBase(
coroutineContext: CoroutineContext = EmptyCoroutineContext
) : AbstractCoroutineServerImpl(coroutineContext) {
/**
* Returns the response to an RPC for helloworld.Greeter.SayHello.
*
Expand All @@ -139,10 +142,8 @@ object GreeterGrpcKt {
*
* @param request The request from the client.
*/
open suspend fun sayHello(request: HelloRequest): HelloReply {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.SayHello is unimplemented"))
}
open suspend fun sayHello(request: HelloRequest): HelloReply = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.SayHello is unimplemented"))

/**
* Returns the response to an RPC for helloworld.Greeter.ClientStreamSayHello.
Expand All @@ -158,10 +159,8 @@ object GreeterGrpcKt {
* collect
* it more than once.
*/
open suspend fun clientStreamSayHello(requests: Flow<HelloRequest>): HelloReply {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ClientStreamSayHello is unimplemented"))
}
open suspend fun clientStreamSayHello(requests: Flow<HelloRequest>): HelloReply = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ClientStreamSayHello is unimplemented"))

/**
* Returns a [Flow] of responses to an RPC for helloworld.Greeter.ServerStreamSayHello.
Expand All @@ -175,10 +174,8 @@ object GreeterGrpcKt {
*
* @param request The request from the client.
*/
open fun serverStreamSayHello(request: MultiHelloRequest): Flow<HelloReply> {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ServerStreamSayHello is unimplemented"))
}
open fun serverStreamSayHello(request: MultiHelloRequest): Flow<HelloReply> = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.ServerStreamSayHello is unimplemented"))

/**
* Returns a [Flow] of responses to an RPC for helloworld.Greeter.BidiStreamSayHello.
Expand All @@ -195,10 +192,8 @@ object GreeterGrpcKt {
* collect
* it more than once.
*/
open fun bidiStreamSayHello(requests: Flow<HelloRequest>): Flow<HelloReply> {
throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.BidiStreamSayHello is unimplemented"))
}
open fun bidiStreamSayHello(requests: Flow<HelloRequest>): Flow<HelloReply> = throw
StatusException(UNIMPLEMENTED.withDescription("Method helloworld.Greeter.BidiStreamSayHello is unimplemented"))

final override fun bindService(): ServerServiceDefinition = builder(getServiceDescriptor())
.addMethod(unaryServerMethodDefinition(
Expand Down
7 changes: 0 additions & 7 deletions examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,3 @@ applicationDistribution.into('bin') {
from(routeGuideServer)
fileMode = 0755
}

test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
}
}
7 changes: 0 additions & 7 deletions stub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,3 @@ protobuf {
}
}
}

test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
}
}

0 comments on commit 8f766cd

Please sign in to comment.