From 55379d105d8d80d34d20f188240bcfb7c854fb9e Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Mon, 5 Jun 2017 15:25:42 -0700 Subject: [PATCH] testing: GrpcServerRule#directExecutor can only be called at instantiation otherwise it cannot take effect --- testing/src/main/java/io/grpc/testing/GrpcServerRule.java | 5 ++++- .../src/test/java/io/grpc/testing/GrpcServerRuleTest.java | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/testing/src/main/java/io/grpc/testing/GrpcServerRule.java b/testing/src/main/java/io/grpc/testing/GrpcServerRule.java index d6959b2ca0..3f37f4c37c 100644 --- a/testing/src/main/java/io/grpc/testing/GrpcServerRule.java +++ b/testing/src/main/java/io/grpc/testing/GrpcServerRule.java @@ -16,6 +16,8 @@ package io.grpc.testing; +import static com.google.common.base.Preconditions.checkState; + import io.grpc.BindableService; import io.grpc.ExperimentalApi; import io.grpc.ManagedChannel; @@ -49,9 +51,10 @@ public class GrpcServerRule extends ExternalResource { /** * Returns {@code this} configured to use a direct executor for the {@link ManagedChannel} and - * {@link Server}. + * {@link Server}. This can only be called at the rule instantiation. */ public final GrpcServerRule directExecutor() { + checkState(serverName == null, "directExecutor() can only be called at the rule instantiation"); useDirectExecutor = true; return this; } diff --git a/testing/src/test/java/io/grpc/testing/GrpcServerRuleTest.java b/testing/src/test/java/io/grpc/testing/GrpcServerRuleTest.java index 4c2dcc9c2b..56e2380736 100644 --- a/testing/src/test/java/io/grpc/testing/GrpcServerRuleTest.java +++ b/testing/src/test/java/io/grpc/testing/GrpcServerRuleTest.java @@ -95,6 +95,11 @@ public class GrpcServerRuleTest { assertThat(testService.lastEmptyCallRequestThread).isNotEqualTo(Thread.currentThread()); } + + @Test(expected = IllegalStateException.class) + public void callDirectExecutorNotAtRuleInstantiation() { + grpcServerRule.directExecutor(); + } } @RunWith(JUnit4.class)