@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1791") public class TestUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
TEST_SERVER_HOST |
| Modifier and Type | Method and Description |
|---|---|
static io.grpc.ServerInterceptor |
echoRequestHeadersInterceptor(io.grpc.Metadata.Key<?>... keys)
Echo the request headers from a client into response headers and trailers.
|
static File |
loadCert(String name)
Saves a file from the classpath resources in src/main/resources/certs as a file on the
filesystem.
|
static X509Certificate |
loadX509Cert(String fileName)
Loads an X.509 certificate from the classpath resources in src/main/resources/certs.
|
static SSLSocketFactory |
newSslSocketFactoryForCa(File certChainFile)
Creates an SSLSocketFactory which contains
certChainFile as its only root certificate. |
static SSLSocketFactory |
newSslSocketFactoryForCa(InputStream certChain)
Creates an SSLSocketFactory which contains
certChainFile as its only root certificate. |
static List<String> |
preferredTestCiphers()
Returns the ciphers preferred to use during tests.
|
static io.grpc.ServerInterceptor |
recordRequestHeadersInterceptor(AtomicReference<io.grpc.Metadata> headersCapture)
Capture the request headers from a client.
|
static io.grpc.ServerInterceptor |
recordServerCallInterceptor(AtomicReference<io.grpc.ServerCall<?,?>> serverCallCapture)
Capture the request attributes.
|
static InetSocketAddress |
testServerAddress(int port)
Creates a new
InetSocketAddress on localhost that overrides the host with
TEST_SERVER_HOST. |
static InetSocketAddress |
testServerAddress(String host,
int port)
Creates a new
InetSocketAddress that overrides the host with TEST_SERVER_HOST. |
public static final String TEST_SERVER_HOST
public static io.grpc.ServerInterceptor echoRequestHeadersInterceptor(io.grpc.Metadata.Key<?>... keys)
public static io.grpc.ServerInterceptor recordRequestHeadersInterceptor(AtomicReference<io.grpc.Metadata> headersCapture)
echoRequestHeadersInterceptor(io.grpc.Metadata.Key<?>...).public static io.grpc.ServerInterceptor recordServerCallInterceptor(AtomicReference<io.grpc.ServerCall<?,?>> serverCallCapture)
ServerCall.attributes()public static InetSocketAddress testServerAddress(String host, int port)
InetSocketAddress that overrides the host with TEST_SERVER_HOST.public static InetSocketAddress testServerAddress(int port)
InetSocketAddress on localhost that overrides the host with
TEST_SERVER_HOST.public static List<String> preferredTestCiphers()
public static File loadCert(String name) throws IOException
name - name of a file in src/main/resources/certs.IOExceptionpublic static X509Certificate loadX509Cert(String fileName) throws CertificateException, IOException
fileName - name of a file in src/main/resources/certs.CertificateExceptionIOExceptionpublic static SSLSocketFactory newSslSocketFactoryForCa(File certChainFile) throws Exception
certChainFile as its only root certificate.Exceptionpublic static SSLSocketFactory newSslSocketFactoryForCa(InputStream certChain) throws Exception
certChainFile as its only root certificate.Exception