all: upgrade to JUnit 4.12

This commit is contained in:
Carl Mastrangelo 2017-10-05 11:24:15 -07:00 committed by GitHub
parent 765a40c7e6
commit 5e36a8deb5
16 changed files with 85 additions and 53 deletions

View File

@ -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',

View File

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

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -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;
* <p> New tests should avoid using Mockito to support running on AppEngine.</p>
*/
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<Messages.SimpleContext> 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<StreamingInputCallRequest> 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<StreamingOutputCallRequest> 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<StreamingOutputCallResponse> responseObserver = StreamRecorder.create();
StreamObserver<StreamingOutputCallRequest> requestObserver
@ -675,7 +680,7 @@ public abstract class AbstractInteropTest {
responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS);
}
@Test(timeout = 10000)
@Test
public void cancelAfterBegin() throws Exception {
StreamRecorder<StreamingInputCallResponse> responseObserver = StreamRecorder.create();
StreamObserver<StreamingInputCallRequest> 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<Integer> 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<Integer> 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<StreamingOutputCallRequest> 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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<NettyServerHandler> {
@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<NettyServerHand
assertFalse(channel().isActive());
}
@Test(timeout = 1000)
@Test
public void keepAliveEnforcer_sendingDataResetsCounters() throws Exception {
permitKeepAliveWithoutCalls = false;
permitKeepAliveTimeInNanos = TimeUnit.HOURS.toNanos(1);

View File

@ -63,6 +63,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
@ -74,6 +75,8 @@ public class ProtocolNegotiatorsTest {
@Override public void run() {}
};
@Rule public final Timeout globalTimeout = Timeout.seconds(5);
@Rule
public final ExpectedException thrown = ExpectedException.none();
@ -303,7 +306,7 @@ public class ProtocolNegotiatorsTest {
ProtocolNegotiators.plaintext()));
}
@Test(timeout = 5000)
@Test
public void httpProxy_completes() throws Exception {
DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
// ProxyHandler is incompatible with EmbeddedChannel because when channelRegistered() is called
@ -367,7 +370,7 @@ public class ProtocolNegotiatorsTest {
channel.close();
}
@Test(timeout = 5000)
@Test
public void httpProxy_500() throws Exception {
DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
// ProxyHandler is incompatible with EmbeddedChannel because when channelRegistered() is called

View File

@ -33,7 +33,9 @@ import io.netty.channel.EventLoop;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
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.Mock;
@ -45,6 +47,9 @@ import org.mockito.stubbing.Answer;
@RunWith(JUnit4.class)
public class WriteQueueTest {
@Rule
public final Timeout globalTimeout = Timeout.seconds(10);
private final Object lock = new Object();
@Mock
@ -138,7 +143,7 @@ public class WriteQueueTest {
verify(channel, times(2)).flush();
}
@Test(timeout = 10000)
@Test
public void concurrentWriteAndFlush() throws Throwable {
final WriteQueue queue = new WriteQueue(channel);
final CountDownLatch flusherStarted = new CountDownLatch(1);

View File

@ -118,8 +118,7 @@ public class OkHttpClientTransportTest {
private static final int HEADER_LENGTH = 5;
private static final Status SHUTDOWN_REASON = Status.UNAVAILABLE.withDescription("for test");
@Rule
public Timeout globalTimeout = new Timeout(10 * 1000);
@Rule public final Timeout globalTimeout = Timeout.seconds(10);
@Mock
private FrameWriter frameWriter;