Skip to content

Commit

Permalink
fixup! Use GrpcCleanupRule instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Sep 15, 2020
1 parent cc0185c commit a944c59
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder;
import io.grpc.internal.ManagedChannelImplBuilder.FixedPortProvider;
import io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder;
import io.grpc.testing.GrpcCleanupRule;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
Expand Down Expand Up @@ -80,6 +81,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(

@Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Rule public final ExpectedException thrown = ExpectedException.none();
@Rule public final GrpcCleanupRule grpcCleanupRule = new GrpcCleanupRule();

@Mock private ClientTransportFactory mockClientTransportFactory;
@Mock private ClientTransportFactoryBuilder mockClientTransportFactoryBuilder;
Expand All @@ -88,10 +90,6 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
private ManagedChannelImplBuilder directAddressBuilder;
private final FakeClock clock = new FakeClock();

private void shutdown(ManagedChannel mc) throws Exception {
mc.shutdownNow();
assertTrue(mc.awaitTermination(1, TimeUnit.SECONDS));
}

@Before
public void setUp() throws Exception {
Expand Down Expand Up @@ -318,7 +316,7 @@ public void userAgent_null() {
}

@Test
public void authorityIsReadable_default() throws Exception {
public void authorityIsReadable_default() {
when(mockClientTransportFactory.getScheduledExecutorService())
.thenReturn(clock.getScheduledExecutorService());
when(mockClientTransportFactoryBuilder.buildClientTransportFactory())
Expand All @@ -327,15 +325,12 @@ public void authorityIsReadable_default() throws Exception {
builder = new ManagedChannelImplBuilder(DUMMY_AUTHORITY_VALID,
mockClientTransportFactoryBuilder, new FixedPortProvider(DUMMY_PORT));
ManagedChannel channel = builder.build();
try {
assertEquals(DUMMY_AUTHORITY_VALID, channel.authority());
} finally {
shutdown(channel);
}
grpcCleanupRule.register(channel);
assertEquals(DUMMY_AUTHORITY_VALID, channel.authority());
}

@Test
public void authorityIsReadable_overrideAuthority() throws Exception {
public void authorityIsReadable_overrideAuthority() {
String overrideAuthority = "best-authority";
when(mockClientTransportFactory.getScheduledExecutorService())
.thenReturn(clock.getScheduledExecutorService());
Expand All @@ -345,11 +340,8 @@ public void authorityIsReadable_overrideAuthority() throws Exception {
builder = new ManagedChannelImplBuilder(DUMMY_TARGET,
mockClientTransportFactoryBuilder, new FixedPortProvider(DUMMY_PORT));
ManagedChannel channel = builder.overrideAuthority(overrideAuthority).build();
try {
assertEquals(overrideAuthority, channel.authority());
} finally {
shutdown(channel);
}
grpcCleanupRule.register(channel);
assertEquals(overrideAuthority, channel.authority());
}

@Test
Expand Down

0 comments on commit a944c59

Please sign in to comment.