From 5e36a8deb51d008f699a70de8e375e535c642cce Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Thu, 5 Oct 2017 11:24:15 -0700 Subject: [PATCH] all: upgrade to JUnit 4.12 --- build.gradle | 2 +- .../io/grpc/internal/DnsNameResolverTest.java | 9 ++- documentation/monitoring-service-tutorial.md | 4 +- documentation/server-reflection-tutorial.md | 2 +- examples/build.gradle | 2 +- examples/pom.xml | 2 +- .../integration/AbstractInteropTest.java | 65 ++++++++++--------- .../testing/integration/ConcurrencyTest.java | 7 +- .../testing/integration/Http2NettyTest.java | 4 +- .../testing/integration/Http2OkHttpTest.java | 8 +-- .../integration/MoreInProcessTest.java | 2 +- .../integration/StressTestClientTest.java | 7 +- .../io/grpc/netty/NettyServerHandlerTest.java | 7 +- .../grpc/netty/ProtocolNegotiatorsTest.java | 7 +- .../java/io/grpc/netty/WriteQueueTest.java | 7 +- .../okhttp/OkHttpClientTransportTest.java | 3 +- 16 files changed, 85 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index 95f05b3448..0c2fa9cf6d 100644 --- a/build.gradle +++ b/build.gradle @@ -210,7 +210,7 @@ subprojects { netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.6.Final', // Test dependencies. - junit: 'junit:junit:4.11', + junit: 'junit:junit:4.12', mockito: 'org.mockito:mockito-core:1.9.5', truth: 'com.google.truth:truth:0.28', diff --git a/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java b/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java index fd8fd932d8..59a90e6b09 100644 --- a/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java +++ b/core/src/test/java/io/grpc/internal/DnsNameResolverTest.java @@ -51,7 +51,9 @@ import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Assume; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; @@ -62,6 +64,9 @@ import org.mockito.MockitoAnnotations; /** Unit tests for {@link DnsNameResolver}. */ @RunWith(JUnit4.class) public class DnsNameResolverTest { + + @Rule public final Timeout globalTimeout = Timeout.seconds(10); + private static final int DEFAULT_PORT = 887; private static final Attributes NAME_RESOLVER_PARAMS = Attributes.newBuilder().set(NameResolver.Factory.PARAMS_DEFAULT_PORT, DEFAULT_PORT).build(); @@ -270,7 +275,7 @@ public class DnsNameResolverTest { verifyNoMoreInteractions(mockListener); } - @Test(timeout = 10000) + @Test public void jdkResolverWorks() throws Exception { DnsNameResolver.DelegateResolver resolver = new DnsNameResolver.JdkResolver(); @@ -280,7 +285,7 @@ public class DnsNameResolverTest { assertThat(results.txtRecords).isNotNull(); } - @Test(timeout = 10000) + @Test public void jndiResolverWorks() throws Exception { Assume.assumeTrue(DnsNameResolver.jndiAvailable()); DnsNameResolver.DelegateResolver resolver = new DnsNameResolver.JndiResolver(); diff --git a/documentation/monitoring-service-tutorial.md b/documentation/monitoring-service-tutorial.md index 61256ba6db..8ad9c2243b 100644 --- a/documentation/monitoring-service-tutorial.md +++ b/documentation/monitoring-service-tutorial.md @@ -46,7 +46,7 @@ monitoring service, we need to make the following changes: + compile "io.grpc:grpc-services:${grpcVersion}" compile "io.grpc:grpc-stub:${grpcVersion}" - testCompile "junit:junit:4.11" + testCompile "junit:junit:4.12" --- a/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java +++ b/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java @@ -33,6 +33,8 @@ package io.grpc.examples.helloworld; @@ -113,7 +113,7 @@ Unix domain socket (`/tmp/grpc_monitoring.sock`) alongside the + // This must match the version of netty used by grpcVersion + compile "io.netty:netty-transport-native-epoll:4.1.8.Final:linux-x86_64" - testCompile "junit:junit:4.11" + testCompile "junit:junit:4.12" testCompile "org.mockito:mockito-core:1.9.5" --- a/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldClient.java +++ b/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldClient.java diff --git a/documentation/server-reflection-tutorial.md b/documentation/server-reflection-tutorial.md index 4cd68b617a..025d3b050d 100644 --- a/documentation/server-reflection-tutorial.md +++ b/documentation/server-reflection-tutorial.md @@ -28,7 +28,7 @@ need to make the following changes: + compile "io.grpc:grpc-services:${grpcVersion}" compile "io.grpc:grpc-stub:${grpcVersion}" - testCompile "junit:junit:4.11" + testCompile "junit:junit:4.12" --- a/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java +++ b/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java @@ -33,6 +33,7 @@ package io.grpc.examples.helloworld; diff --git a/examples/build.gradle b/examples/build.gradle index 816d007b99..605be66d49 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -31,7 +31,7 @@ dependencies { compile "io.grpc:grpc-stub:${grpcVersion}" testCompile "io.grpc:grpc-testing:${grpcVersion}" - testCompile "junit:junit:4.11" + testCompile "junit:junit:4.12" testCompile "org.mockito:mockito-core:1.9.5" } diff --git a/examples/pom.xml b/examples/pom.xml index ed597c1660..1e59538547 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -43,7 +43,7 @@ junit junit - 4.11 + 4.12 test diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java index 30487e7567..a8e5f69648 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java @@ -110,7 +110,9 @@ import org.junit.After; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.Timeout; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.mockito.verification.VerificationMode; @@ -121,6 +123,9 @@ import org.mockito.verification.VerificationMode; *

New tests should avoid using Mockito to support running on AppEngine.

*/ public abstract class AbstractInteropTest { + + @Rule public final Timeout globalTimeout = Timeout.seconds(30); + /** Must be at least {@link #unaryPayloadLength()}, plus some to account for encoding overhead. */ public static final int MAX_MESSAGE_SIZE = 16 * 1024 * 1024; public static final Metadata.Key METADATA_KEY = @@ -266,7 +271,7 @@ public abstract class AbstractInteropTest { return true; } - @Test(timeout = 10000) + @Test public void emptyUnary() throws Exception { assertEquals(EMPTY, blockingStub.emptyCall(EMPTY)); } @@ -309,7 +314,7 @@ public abstract class AbstractInteropTest { assertNotEquals(response1, response3); } - @Test(timeout = 10000) + @Test public void largeUnary() throws Exception { assumeEnoughMemory(); final SimpleRequest request = SimpleRequest.newBuilder() @@ -393,7 +398,7 @@ public abstract class AbstractInteropTest { * compliant server, this test will exercise the code path for receiving a compressed response but * cannot itself verify that the response was compressed. */ - @Test(timeout = 10000) + @Test public void serverCompressedUnary() throws Exception { assumeEnoughMemory(); final SimpleRequest responseShouldBeCompressed = @@ -432,7 +437,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void serverStreaming() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .setResponseType(PayloadType.COMPRESSABLE) @@ -474,7 +479,7 @@ public abstract class AbstractInteropTest { assertEquals(goldenResponses, recorder.getValues()); } - @Test(timeout = 10000) + @Test public void clientStreaming() throws Exception { final List requests = Arrays.asList( StreamingInputCallRequest.newBuilder() @@ -589,7 +594,7 @@ public abstract class AbstractInteropTest { assertEquals(goldenResponses, recorder.getValues()); } - @Test(timeout = 10000) + @Test public void pingPong() throws Exception { final List requests = Arrays.asList( StreamingOutputCallRequest.newBuilder() @@ -666,7 +671,7 @@ public abstract class AbstractInteropTest { assertEquals("Completed", queue.poll(operationTimeoutMillis(), TimeUnit.MILLISECONDS)); } - @Test(timeout = 10000) + @Test public void emptyStream() throws Exception { StreamRecorder responseObserver = StreamRecorder.create(); StreamObserver requestObserver @@ -675,7 +680,7 @@ public abstract class AbstractInteropTest { responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS); } - @Test(timeout = 10000) + @Test public void cancelAfterBegin() throws Exception { StreamRecorder responseObserver = StreamRecorder.create(); StreamObserver requestObserver = @@ -698,7 +703,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void cancelAfterFirstResponse() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(ResponseParameters.newBuilder() @@ -728,7 +733,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void fullDuplexCallShouldSucceed() throws Exception { // Build the request. List responseSizes = Arrays.asList(50, 100, 150, 200); @@ -769,7 +774,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void halfDuplexCallShouldSucceed() throws Exception { // Build the request. List responseSizes = Arrays.asList(50, 100, 150, 200); @@ -804,7 +809,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void serverStreamingShouldBeFlowControlled() throws Exception { final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .setResponseType(COMPRESSABLE) @@ -863,7 +868,7 @@ public abstract class AbstractInteropTest { assertEquals(Status.OK, queue.poll(operationTimeoutMillis(), TimeUnit.MILLISECONDS)); } - @Test(timeout = 30000) + @Test public void veryLargeRequest() throws Exception { assumeEnoughMemory(); final SimpleRequest request = SimpleRequest.newBuilder() @@ -882,7 +887,7 @@ public abstract class AbstractInteropTest { assertEquals(goldenResponse, blockingStub.unaryCall(request)); } - @Test(timeout = 30000) + @Test public void veryLargeResponse() throws Exception { assumeEnoughMemory(); final SimpleRequest request = SimpleRequest.newBuilder() @@ -898,7 +903,7 @@ public abstract class AbstractInteropTest { assertEquals(goldenResponse, blockingStub.unaryCall(request)); } - @Test(timeout = 10000) + @Test public void exchangeMetadataUnaryCall() throws Exception { TestServiceGrpc.TestServiceBlockingStub stub = blockingStub; @@ -921,7 +926,7 @@ public abstract class AbstractInteropTest { Assert.assertEquals(contextValue, trailersCapture.get().get(METADATA_KEY)); } - @Test(timeout = 10000) + @Test public void exchangeMetadataStreamingCall() throws Exception { TestServiceGrpc.TestServiceStub stub = asyncStub; @@ -968,7 +973,7 @@ public abstract class AbstractInteropTest { Assert.assertEquals(contextValue, trailersCapture.get().get(METADATA_KEY)); } - @Test(timeout = 10000) + @Test public void sendsTimeoutHeader() { Assume.assumeTrue("can not capture server side request headers", server != null); long configuredTimeoutMinutes = 100; @@ -996,7 +1001,7 @@ public abstract class AbstractInteropTest { .build()).next(); } - @Test(timeout = 25000) + @Test public void deadlineExceeded() throws Exception { // warm up the channel and JVM blockingStub.emptyCall(Empty.getDefaultInstance()); @@ -1024,7 +1029,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void deadlineExceededServerStreaming() throws Exception { // warm up the channel and JVM blockingStub.emptyCall(Empty.getDefaultInstance()); @@ -1057,7 +1062,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void deadlineInPast() throws Exception { // Test once with idle channel and once with active channel try { @@ -1099,7 +1104,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void maxInboundSize_exact() { StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(ResponseParameters.newBuilder().setSize(1)) @@ -1112,7 +1117,7 @@ public abstract class AbstractInteropTest { stub.streamingOutputCall(request).next(); } - @Test(timeout = 10000) + @Test public void maxInboundSize_tooBig() { StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder() .addResponseParameters(ResponseParameters.newBuilder().setSize(1)) @@ -1132,7 +1137,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void maxOutboundSize_exact() { // warm up the channel and JVM blockingStub.emptyCall(Empty.getDefaultInstance()); @@ -1147,7 +1152,7 @@ public abstract class AbstractInteropTest { stub.streamingOutputCall(request).next(); } - @Test(timeout = 10000) + @Test public void maxOutboundSize_tooBig() { // warm up the channel and JVM blockingStub.emptyCall(Empty.getDefaultInstance()); @@ -1172,7 +1177,7 @@ public abstract class AbstractInteropTest { return 10485760; } - @Test(timeout = 10000) + @Test public void gracefulShutdown() throws Exception { final List requests = Arrays.asList( StreamingOutputCallRequest.newBuilder() @@ -1252,7 +1257,7 @@ public abstract class AbstractInteropTest { assertFalse(errorSeen.isDone()); } - @Test(timeout = 10000) + @Test public void customMetadata() throws Exception { final int responseSize = 314159; final int requestSize = 271828; @@ -1331,7 +1336,7 @@ public abstract class AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void statusCodeAndMessage() throws Exception { int errorCode = 2; String errorMessage = "test status message"; @@ -1378,7 +1383,7 @@ public abstract class AbstractInteropTest { } /** Sends an rpc to an unimplemented method within TestService. */ - @Test(timeout = 10000) + @Test public void unimplementedMethod() { try { blockingStub.unimplementedCall(Empty.getDefaultInstance()); @@ -1394,7 +1399,7 @@ public abstract class AbstractInteropTest { } /** Sends an rpc to an unimplemented service on the server. */ - @Test(timeout = 10000) + @Test public void unimplementedService() { UnimplementedServiceGrpc.UnimplementedServiceBlockingStub stub = UnimplementedServiceGrpc.newBlockingStub(channel).withInterceptors(tracerSetupInterceptor); @@ -1413,7 +1418,7 @@ public abstract class AbstractInteropTest { /** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */ @SuppressWarnings("MissingFail") - @Test(timeout = 10000) + @Test public void timeoutOnSleepingServer() throws Exception { TestServiceGrpc.TestServiceStub stub = asyncStub.withDeadlineAfter(1, TimeUnit.MILLISECONDS); diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java index 638e33bb70..39fc2ba5f1 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java @@ -44,7 +44,9 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -59,6 +61,9 @@ import org.junit.runners.JUnit4; // bidirectional streaming requests also. @RunWith(JUnit4.class) public class ConcurrencyTest { + + @Rule public final Timeout globalTimeout = Timeout.seconds(10); + /** * A response observer that signals a {@code CountDownLatch} when the proper number of responses * arrives and the server signals that the RPC is complete. @@ -165,7 +170,7 @@ public class ConcurrencyTest { /** * Tests that gRPC can handle concurrent server-streaming RPCs. */ - @Test(timeout = 10000) + @Test public void serverStreamingTest() throws Exception { CyclicBarrier startBarrier = new CyclicBarrier(NUM_CONCURRENT_REQUESTS); CountDownLatch responsesDoneSignal = new CountDownLatch(NUM_CONCURRENT_REQUESTS); diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java index 07542e91e8..eeb406173d 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java @@ -82,12 +82,12 @@ public class Http2NettyTest extends AbstractInteropTest { } } - @Test(timeout = 10000) + @Test public void remoteAddr() { assertRemoteAddr("/0:0:0:0:0:0:0:1"); } - @Test(timeout = 10000) + @Test public void tlsInfo() { assertX500SubjectDn("CN=testclient, O=Internet Widgits Pty Ltd, ST=Some-State, C=AU"); } diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java index a6c0c67fb5..68082f4c5a 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java @@ -116,7 +116,7 @@ public class Http2OkHttpTest extends AbstractInteropTest { return builder; } - @Test(timeout = 10000) + @Test public void receivedDataForFinishedStream() throws Exception { Messages.ResponseParameters.Builder responseParameters = Messages.ResponseParameters.newBuilder() @@ -141,7 +141,7 @@ public class Http2OkHttpTest extends AbstractInteropTest { assertEquals(EMPTY, blockingStub.emptyCall(EMPTY)); } - @Test(timeout = 10000) + @Test public void wrongHostNameFailHostnameVerification() throws Exception { ManagedChannel channel = createChannelBuilder() .overrideAuthority(GrpcUtil.authorityFromHostAndPort( @@ -161,7 +161,7 @@ public class Http2OkHttpTest extends AbstractInteropTest { channel.shutdown(); } - @Test(timeout = 10000) + @Test public void hostnameVerifierWithBadHostname() throws Exception { ManagedChannel channel = createChannelBuilder() .overrideAuthority(GrpcUtil.authorityFromHostAndPort( @@ -181,7 +181,7 @@ public class Http2OkHttpTest extends AbstractInteropTest { channel.shutdown(); } - @Test(timeout = 10000) + @Test public void hostnameVerifierWithCorrectHostname() throws Exception { ManagedChannel channel = createChannelBuilder() .overrideAuthority(GrpcUtil.authorityFromHostAndPort( diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java index b9506e28f3..26f3c88875 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java @@ -51,7 +51,7 @@ public class MoreInProcessTest { private static final String UNIQUE_SERVER_NAME = "in-process server for " + MoreInProcessTest.class; @Rule - public final Timeout globalTimeout = new Timeout(1000); + public final Timeout globalTimeout = new Timeout(1, TimeUnit.SECONDS); // use a mutable service registry for later registering the service impl for each test case. private final MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry(); private final Server inProcessServer = InProcessServerBuilder.forName(UNIQUE_SERVER_NAME) diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java index 6665073d61..54abe97d83 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java @@ -33,7 +33,9 @@ import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -41,6 +43,9 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class StressTestClientTest { + @Rule + public final Timeout globalTimeout = Timeout.seconds(5); + @Test public void ipv6AddressesShouldBeSupported() { StressTestClient client = new StressTestClient(); @@ -108,7 +113,7 @@ public class StressTestClientTest { assertEquals("foo.test.google.fr", client.addresses().get(0).getHostName()); } - @Test(timeout = 5000) + @Test public void gaugesShouldBeExported() throws Exception { TestServiceServer server = new TestServiceServer(); diff --git a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java index 98a0f73920..5ae27bd646 100644 --- a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java @@ -87,7 +87,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.concurrent.TimeUnit; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.Timeout; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.mockito.ArgumentCaptor; @@ -103,6 +105,9 @@ import org.mockito.stubbing.Answer; @RunWith(JUnit4.class) public class NettyServerHandlerTest extends NettyHandlerTestBase { + @Rule + public final Timeout globalTimeout = Timeout.seconds(1); + private static final int STREAM_ID = 3; @Mock @@ -529,7 +534,7 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase