testing: GrpcServerRule#directExecutor can only be called at instantiation

otherwise it cannot take effect
This commit is contained in:
ZHANG Dapeng 2017-06-05 15:25:42 -07:00 committed by GitHub
parent adc2de7533
commit 55379d105d
2 changed files with 9 additions and 1 deletions

View File

@ -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;
}

View File

@ -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)