Skip to content

Commit f6dde49

Browse files
authored
Fix interceptor tests (#148)
Fix compile issues with interceptor tests.
1 parent ef1b973 commit f6dde49

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

stub/src/test/java/io/grpc/kotlin/AbstractCallsTest.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,17 @@ abstract class AbstractCallsTest {
149149
}
150150

151151
/** Generates a channel to a Greeter server with the specified implementation. */
152-
fun makeChannel(impl: BindableService): ManagedChannel {
152+
fun makeChannel(impl: BindableService, vararg interceptors: ServerInterceptor): ManagedChannel =
153+
makeChannel(ServerInterceptors.intercept(impl, *interceptors))
154+
155+
fun makeChannel(serverServiceDefinition: ServerServiceDefinition): ManagedChannel {
153156
val serverName = InProcessServerBuilder.generateName()
154157

155158
grpcCleanup.register(
156159
InProcessServerBuilder.forName(serverName)
157160
.run { this as ServerBuilder<*> } // workaround b/123879662
158161
.executor(executor)
159-
.addService(impl)
162+
.addService(serverServiceDefinition)
160163
.build()
161164
.start()
162165
)
@@ -173,20 +176,17 @@ abstract class AbstractCallsTest {
173176
fun makeChannel(
174177
impl: ServerMethodDefinition<*, *>,
175178
vararg interceptors: ServerInterceptor
176-
): ManagedChannel =
177-
makeChannel(
178-
BindableService {
179-
val builder = ServerServiceDefinition.builder(greeterService)
180-
for (method in greeterService.methods) {
181-
if (method == impl.methodDescriptor) {
182-
builder.addMethod(impl)
183-
} else {
184-
builder.addMethod(method, ServerCallHandler { _, _ -> TODO() })
185-
}
186-
}
187-
ServerInterceptors.intercept(builder.build(), *interceptors)
179+
): ManagedChannel {
180+
val builder = ServerServiceDefinition.builder(greeterService)
181+
for (method in greeterService.methods) {
182+
if (method == impl.methodDescriptor) {
183+
builder.addMethod(impl)
184+
} else {
185+
builder.addMethod(method, ServerCallHandler { _, _ -> TODO() })
188186
}
189-
)
187+
}
188+
return makeChannel(ServerInterceptors.intercept(builder.build(), *interceptors))
189+
}
190190

191191
fun <R> runBlocking(block: suspend CoroutineScope.() -> R): Unit =
192192
kotlinx.coroutines.runBlocking(context) {

stub/src/test/java/io/grpc/kotlin/CoroutineContextServerInterceptorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import kotlin.coroutines.coroutineContext
1616
import io.grpc.Metadata as GrpcMetadata
1717

1818
/** Tests for [CoroutineContextServerInterceptor]. */
19-
@RunWith(JUnit4::class) /* inserted by Copybara: */ @com.google.testing.testsize.MediumTest
19+
@RunWith(JUnit4::class)
2020
class CoroutineContextServerInterceptorTest : AbstractCallsTest() {
2121
class ArbitraryContextElement(val message: String = "") : CoroutineContext.Element {
2222
companion object Key : CoroutineContext.Key<ArbitraryContextElement>

0 commit comments

Comments
 (0)