From ff0ad5fac3cf944a5ce5fb3ccef7df4a2d0bdf14 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Mon, 10 Jul 2017 16:30:38 -0700 Subject: [PATCH] testing: refactor part of TestUtils to internal Moved the following APIs from `io.grpc.testing.TestUtils` to `io.grpc.internal.TestUtils`: `InetSocketAddress testServerAddress(String host, int port)` `InetSocketAddress testServerAddress(int port)` `List preferredTestCiphers()` `File loadCert(String name)` `X509Certificate loadX509Cert(String fileName)` `SSLSocketFactory newSslSocketFactoryForCa(Provider provider, File certChainFile)` `void sleepAtLeast(long millis)` APIs not to be moved: `ServerInterceptor recordRequestHeadersInterceptor()` `ServerInterceptor recordServerCallInterceptor()` --- .../main/java/io/grpc/benchmarks/Utils.java | 2 +- .../io/grpc/benchmarks/driver/LoadServer.java | 2 +- .../io/grpc/benchmarks/qps/AsyncServer.java | 2 +- .../benchmarks/qps/ClientConfiguration.java | 2 +- .../testing/integration/StressTestClient.java | 2 +- .../integration/TestServiceClient.java | 2 +- .../integration/TestServiceServer.java | 2 +- .../testing/integration/ConcurrencyTest.java | 2 +- .../testing/integration/Http2NettyTest.java | 2 +- .../testing/integration/Http2OkHttpTest.java | 2 +- .../io/grpc/testing/integration/TlsTest.java | 2 +- .../grpc/netty/NettyClientTransportTest.java | 2 +- .../io/grpc/netty/NettyServerHandlerTest.java | 2 +- .../grpc/netty/ProtocolNegotiatorsTest.java | 2 +- .../io/grpc/internal/testing/TestUtils.java | 181 ++++++++++++++++++ .../main/java/io/grpc/testing/TestUtils.java | 22 +++ .../{ => internal}/testing/TestUtilsTest.java | 4 +- 17 files changed, 219 insertions(+), 16 deletions(-) create mode 100644 testing/src/main/java/io/grpc/internal/testing/TestUtils.java rename testing/src/test/java/io/grpc/{ => internal}/testing/TestUtilsTest.java (92%) diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/Utils.java b/benchmarks/src/main/java/io/grpc/benchmarks/Utils.java index eed1d13ae7..b2b54436b1 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/Utils.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/Utils.java @@ -28,12 +28,12 @@ import io.grpc.benchmarks.proto.Messages.Payload; import io.grpc.benchmarks.proto.Messages.SimpleRequest; import io.grpc.benchmarks.proto.Messages.SimpleResponse; import io.grpc.internal.GrpcUtil; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.okhttp.internal.Platform; -import io.grpc.testing.TestUtils; import io.netty.channel.epoll.EpollDomainSocketChannel; import io.netty.channel.epoll.EpollEventLoopGroup; import io.netty.channel.epoll.EpollSocketChannel; diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadServer.java b/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadServer.java index 14677135cd..0ad4cbb42a 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadServer.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/driver/LoadServer.java @@ -36,8 +36,8 @@ import io.grpc.benchmarks.proto.BenchmarkServiceGrpc; import io.grpc.benchmarks.proto.Control; import io.grpc.benchmarks.proto.Messages; import io.grpc.benchmarks.proto.Stats; +import io.grpc.internal.testing.TestUtils; import io.grpc.stub.StreamObserver; -import io.grpc.testing.TestUtils; import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; import java.io.File; diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java index 3f8fedcb4c..fa77a6d5fd 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncServer.java @@ -22,10 +22,10 @@ import io.grpc.benchmarks.Utils; import io.grpc.benchmarks.proto.BenchmarkServiceGrpc; import io.grpc.benchmarks.proto.Messages.SimpleRequest; import io.grpc.benchmarks.proto.Messages.SimpleResponse; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NettyServerBuilder; import io.grpc.stub.StreamObserver; -import io.grpc.testing.TestUtils; import io.netty.channel.EventLoopGroup; import io.netty.channel.ServerChannel; import io.netty.channel.nio.NioEventLoopGroup; diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/ClientConfiguration.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/ClientConfiguration.java index 8190d50adf..39a8440c57 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/ClientConfiguration.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/ClientConfiguration.java @@ -26,7 +26,7 @@ import io.grpc.benchmarks.Utils; import io.grpc.benchmarks.proto.Control.RpcType; import io.grpc.benchmarks.proto.Messages; import io.grpc.benchmarks.proto.Messages.PayloadType; -import io.grpc.testing.TestUtils; +import io.grpc.internal.testing.TestUtils; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java index f88544072c..f6724e5815 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/StressTestClient.java @@ -37,11 +37,11 @@ import io.grpc.Server; import io.grpc.ServerBuilder; import io.grpc.Status; import io.grpc.StatusException; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.stub.StreamObserver; -import io.grpc.testing.TestUtils; import io.netty.handler.ssl.SslContext; import java.io.IOException; import java.net.InetAddress; diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java index 4882d9c138..08425cd945 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceClient.java @@ -19,12 +19,12 @@ package io.grpc.testing.integration; import com.google.common.io.Files; import io.grpc.ManagedChannel; import io.grpc.internal.GrpcUtil; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.okhttp.internal.Platform; -import io.grpc.testing.TestUtils; import io.netty.handler.ssl.SslContext; import java.io.File; import java.io.FileInputStream; diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java index fd8919fa86..48dd37dbc9 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java @@ -20,9 +20,9 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.MoreExecutors; import io.grpc.Server; import io.grpc.ServerInterceptors; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NettyServerBuilder; -import io.grpc.testing.TestUtils; import io.netty.handler.ssl.SslContext; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; 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 368d4ffc3f..638e33bb70 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 @@ -20,12 +20,12 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.MoreExecutors; import io.grpc.ManagedChannel; import io.grpc.Server; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; import io.grpc.stub.StreamObserver; -import io.grpc.testing.TestUtils; import io.grpc.testing.integration.Messages.PayloadType; import io.grpc.testing.integration.Messages.ResponseParameters; import io.grpc.testing.integration.Messages.StreamingOutputCallRequest; 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 faac9bc856..07542e91e8 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 @@ -17,10 +17,10 @@ package io.grpc.testing.integration; import io.grpc.ManagedChannel; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; -import io.grpc.testing.TestUtils; import io.netty.handler.ssl.ClientAuth; import io.netty.handler.ssl.SslProvider; import io.netty.handler.ssl.SupportedCipherSuiteFilter; 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 c4bccf5449..0dcf7d4f87 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 @@ -26,13 +26,13 @@ import com.squareup.okhttp.ConnectionSpec; import com.squareup.okhttp.TlsVersion; import io.grpc.ManagedChannel; import io.grpc.internal.GrpcUtil; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NettyServerBuilder; import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.okhttp.internal.Platform; import io.grpc.stub.StreamObserver; import io.grpc.testing.StreamRecorder; -import io.grpc.testing.TestUtils; import io.netty.handler.ssl.OpenSsl; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/TlsTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/TlsTest.java index e336111b0a..fa0abbe0f9 100644 --- a/interop-testing/src/test/java/io/grpc/testing/integration/TlsTest.java +++ b/interop-testing/src/test/java/io/grpc/testing/integration/TlsTest.java @@ -27,11 +27,11 @@ import io.grpc.Server; import io.grpc.ServerBuilder; import io.grpc.Status; import io.grpc.StatusRuntimeException; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NegotiationType; import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyServerBuilder; -import io.grpc.testing.TestUtils; import io.netty.handler.ssl.ClientAuth; import io.netty.handler.ssl.OpenSsl; import io.netty.handler.ssl.SslContext; diff --git a/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java b/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java index bc2cda09ba..881ea56fca 100644 --- a/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java @@ -56,7 +56,7 @@ import io.grpc.internal.ServerStream; import io.grpc.internal.ServerStreamListener; import io.grpc.internal.ServerTransport; import io.grpc.internal.ServerTransportListener; -import io.grpc.testing.TestUtils; +import io.grpc.internal.testing.TestUtils; import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelOption; import io.netty.channel.nio.NioEventLoopGroup; diff --git a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java index 99b99540b5..ea47200f4a 100644 --- a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java +++ b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java @@ -20,6 +20,7 @@ import static com.google.common.base.Charsets.UTF_8; import static io.grpc.internal.GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE; import static io.grpc.internal.GrpcUtil.DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS; import static io.grpc.internal.GrpcUtil.DEFAULT_SERVER_KEEPALIVE_TIME_NANOS; +import static io.grpc.internal.testing.TestUtils.sleepAtLeast; import static io.grpc.netty.NettyServerBuilder.MAX_CONNECTION_AGE_GRACE_NANOS_INFINITE; import static io.grpc.netty.NettyServerBuilder.MAX_CONNECTION_AGE_NANOS_DISABLED; import static io.grpc.netty.NettyServerBuilder.MAX_CONNECTION_IDLE_NANOS_DISABLED; @@ -28,7 +29,6 @@ import static io.grpc.netty.Utils.CONTENT_TYPE_HEADER; import static io.grpc.netty.Utils.HTTP_METHOD; import static io.grpc.netty.Utils.TE_HEADER; import static io.grpc.netty.Utils.TE_TRAILERS; -import static io.grpc.testing.TestUtils.sleepAtLeast; import static io.netty.buffer.Unpooled.directBuffer; import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_WINDOW_SIZE; import static org.junit.Assert.assertArrayEquals; diff --git a/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java b/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java index c573a20884..684928648b 100644 --- a/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java +++ b/netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java @@ -26,9 +26,9 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; +import io.grpc.internal.testing.TestUtils; import io.grpc.netty.ProtocolNegotiators.ServerTlsHandler; import io.grpc.netty.ProtocolNegotiators.TlsNegotiator; -import io.grpc.testing.TestUtils; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; diff --git a/testing/src/main/java/io/grpc/internal/testing/TestUtils.java b/testing/src/main/java/io/grpc/internal/testing/TestUtils.java new file mode 100644 index 0000000000..649e8e09f4 --- /dev/null +++ b/testing/src/main/java/io/grpc/internal/testing/TestUtils.java @@ -0,0 +1,181 @@ +/* + * Copyright 2014, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.internal.testing; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.security.KeyStore; +import java.security.NoSuchAlgorithmException; +import java.security.Provider; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManagerFactory; +import javax.security.auth.x500.X500Principal; + +/** + * Internal utility functions useful for writing tests. + */ +public class TestUtils { + public static final String TEST_SERVER_HOST = "foo.test.google.fr"; + + /** + * Creates a new {@link InetSocketAddress} that overrides the host with {@link #TEST_SERVER_HOST}. + */ + public static InetSocketAddress testServerAddress(String host, int port) { + try { + InetAddress inetAddress = InetAddress.getByName(host); + inetAddress = InetAddress.getByAddress(TEST_SERVER_HOST, inetAddress.getAddress()); + return new InetSocketAddress(inetAddress, port); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } + + /** + * Creates a new {@link InetSocketAddress} on localhost that overrides the host with + * {@link #TEST_SERVER_HOST}. + */ + public static InetSocketAddress testServerAddress(int port) { + try { + InetAddress inetAddress = InetAddress.getByName("::1"); + inetAddress = InetAddress.getByAddress(TEST_SERVER_HOST, inetAddress.getAddress()); + return new InetSocketAddress(inetAddress, port); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } + + /** + * Returns the ciphers preferred to use during tests. They may be chosen because they are widely + * available or because they are fast. There is no requirement that they provide confidentiality + * or integrity. + */ + public static List preferredTestCiphers() { + String[] ciphers; + try { + ciphers = SSLContext.getDefault().getDefaultSSLParameters().getCipherSuites(); + } catch (NoSuchAlgorithmException ex) { + throw new RuntimeException(ex); + } + List ciphersMinusGcm = new ArrayList(); + for (String cipher : ciphers) { + // The GCM implementation in Java is _very_ slow (~1 MB/s) + if (cipher.contains("_GCM_")) { + continue; + } + ciphersMinusGcm.add(cipher); + } + return Collections.unmodifiableList(ciphersMinusGcm); + } + + /** + * Saves a file from the classpath resources in src/main/resources/certs as a file on the + * filesystem. + * + * @param name name of a file in src/main/resources/certs. + */ + public static File loadCert(String name) throws IOException { + InputStream + in = new BufferedInputStream(TestUtils.class.getResourceAsStream("/certs/" + name)); + File tmpFile = File.createTempFile(name, ""); + tmpFile.deleteOnExit(); + + OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile)); + try { + int b; + while ((b = in.read()) != -1) { + os.write(b); + } + os.flush(); + } finally { + in.close(); + os.close(); + } + + return tmpFile; + } + + /** + * Loads an X.509 certificate from the classpath resources in src/main/resources/certs. + * + * @param fileName name of a file in src/main/resources/certs. + */ + public static X509Certificate loadX509Cert(String fileName) + throws CertificateException, IOException { + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + InputStream in = TestUtils.class.getResourceAsStream("/certs/" + fileName); + try { + return (X509Certificate) cf.generateCertificate(in); + } finally { + in.close(); + } + } + + /** + * Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate. + */ + public static SSLSocketFactory newSslSocketFactoryForCa(Provider provider, + File certChainFile) throws Exception { + KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); + ks.load(null, null); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert = (X509Certificate) cf.generateCertificate( + new BufferedInputStream(new FileInputStream(certChainFile))); + X500Principal principal = cert.getSubjectX500Principal(); + ks.setCertificateEntry(principal.getName("RFC2253"), cert); + + // Set up trust manager factory to use our key store. + TrustManagerFactory trustManagerFactory = + TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + trustManagerFactory.init(ks); + SSLContext context = SSLContext.getInstance("TLS", provider); + context.init(null, trustManagerFactory.getTrustManagers(), null); + return context.getSocketFactory(); + } + + /** + * Sleeps for at least the specified time. When in need of a guaranteed sleep time, use this in + * preference to {@code Thread.sleep} which might not sleep for the required time. + */ + public static void sleepAtLeast(long millis) throws InterruptedException { + long delay = TimeUnit.MILLISECONDS.toNanos(millis); + long end = System.nanoTime() + delay; + while (delay > 0) { + TimeUnit.NANOSECONDS.sleep(delay); + delay = end - System.nanoTime(); + } + } + + private TestUtils() {} +} diff --git a/testing/src/main/java/io/grpc/testing/TestUtils.java b/testing/src/main/java/io/grpc/testing/TestUtils.java index ac4664ef53..eedd25b145 100644 --- a/testing/src/main/java/io/grpc/testing/TestUtils.java +++ b/testing/src/main/java/io/grpc/testing/TestUtils.java @@ -53,6 +53,7 @@ import javax.security.auth.x500.X500Principal; */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1791") public class TestUtils { + @Deprecated public static final String TEST_SERVER_HOST = "foo.test.google.fr"; /** @@ -92,7 +93,10 @@ public class TestUtils { /** * Creates a new {@link InetSocketAddress} that overrides the host with {@link #TEST_SERVER_HOST}. + * + * @deprecated Not for public use */ + @Deprecated public static InetSocketAddress testServerAddress(String host, int port) { try { InetAddress inetAddress = InetAddress.getByName(host); @@ -106,7 +110,10 @@ public class TestUtils { /** * Creates a new {@link InetSocketAddress} on localhost that overrides the host with * {@link #TEST_SERVER_HOST}. + * + * @deprecated Not for public use */ + @Deprecated public static InetSocketAddress testServerAddress(int port) { try { InetAddress inetAddress = InetAddress.getByName("::1"); @@ -121,7 +128,10 @@ public class TestUtils { * Returns the ciphers preferred to use during tests. They may be chosen because they are widely * available or because they are fast. There is no requirement that they provide confidentiality * or integrity. + * + * @deprecated Not for public use */ + @Deprecated public static List preferredTestCiphers() { String[] ciphers; try { @@ -145,7 +155,10 @@ public class TestUtils { * filesystem. * * @param name name of a file in src/main/resources/certs. + * + * @deprecated Not for public use */ + @Deprecated public static File loadCert(String name) throws IOException { InputStream in = new BufferedInputStream(TestUtils.class.getResourceAsStream("/certs/" + name)); File tmpFile = File.createTempFile(name, ""); @@ -170,7 +183,10 @@ public class TestUtils { * Loads an X.509 certificate from the classpath resources in src/main/resources/certs. * * @param fileName name of a file in src/main/resources/certs. + * + * @deprecated Not for public use */ + @Deprecated public static X509Certificate loadX509Cert(String fileName) throws CertificateException, IOException { CertificateFactory cf = CertificateFactory.getInstance("X.509"); @@ -185,7 +201,10 @@ public class TestUtils { /** * Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate. + * + * @deprecated Not for public use */ + @Deprecated public static SSLSocketFactory newSslSocketFactoryForCa(Provider provider, File certChainFile) throws Exception { KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); @@ -208,7 +227,10 @@ public class TestUtils { /** * Sleeps for at least the specified time. When in need of a guaranteed sleep time, use this in * preference to {@code Thread.sleep} which might not sleep for the required time. + * + * @deprecated Not for public use */ + @Deprecated public static void sleepAtLeast(long millis) throws InterruptedException { long delay = TimeUnit.MILLISECONDS.toNanos(millis); long end = System.nanoTime() + delay; diff --git a/testing/src/test/java/io/grpc/testing/TestUtilsTest.java b/testing/src/test/java/io/grpc/internal/testing/TestUtilsTest.java similarity index 92% rename from testing/src/test/java/io/grpc/testing/TestUtilsTest.java rename to testing/src/test/java/io/grpc/internal/testing/TestUtilsTest.java index 3db60a9a04..baf4868877 100644 --- a/testing/src/test/java/io/grpc/testing/TestUtilsTest.java +++ b/testing/src/test/java/io/grpc/internal/testing/TestUtilsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.grpc.testing; +package io.grpc.internal.testing; import static com.google.common.truth.Truth.assertThat; @@ -24,7 +24,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** - * Unit tests for {@link TestUtils}. + * Unit tests for {@link io.grpc.internal.testing.TestUtils}. */ @RunWith(JUnit4.class) public class TestUtilsTest {