有没有一种方法可以在使用Cloud Translation Java库时轻松编写集成测试?

时间:2020-02-19 13:04:35

标签: google-translate

我正在编写一项将调用Google Cloud Translation服务的服务。

我正在使用Java库com.google.cloud:google-cloud-translate:4.0.0

我想用以下设置编写一些集成测试:

  • wiremock服务器将充当翻译api
  • 我的服务将 配置TranslationServiceClient以用作我的自定义端点 Wiremock

原因是,针对真实api进行全套集成测试会很快变得昂贵。

我似乎无法覆盖HostNameVerifier的实现,因此我的所有测试均失败,但出现以下异常:

java.security.cert.CertificateException: No name matching localhost found
at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:231) ~[na:1.8.0_152]
at sun.security.util.HostnameChecker.match(HostnameChecker.java:96) ~[na:1.8.0_152]
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:455) ~[na:1.8.0_152]
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:436) ~[na:1.8.0_152]
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:252) ~[na:1.8.0_152]
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:136) ~[na:1.8.0_152]
at io.grpc.netty.shaded.io.netty.handler.ssl.OpenSslTlsv13X509ExtendedTrustManager.checkServerTrusted(OpenSslTlsv13X509ExtendedTrustManager.java:221) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslClientContext$ExtendedTrustManagerVerifyCallback.verify(ReferenceCountedOpenSslClientContext.java:248) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslContext$AbstractCertificateVerifier.verify(ReferenceCountedOpenSslContext.java:699) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.internal.tcnative.SSL.readFromSSL(Native Method) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine.readPlaintextData(ReferenceCountedOpenSslEngine.java:589) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine.unwrap(ReferenceCountedOpenSslEngine.java:1172) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine.unwrap(ReferenceCountedOpenSslEngine.java:1289) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.ReferenceCountedOpenSslEngine.unwrap(ReferenceCountedOpenSslEngine.java:1332) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler$SslEngineType$1.unwrap(SslHandler.java:204) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1329) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1224) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1271) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:505) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:444) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:283) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1044) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[grpc-netty-shaded-1.27.0.jar:1.27.0]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]

关于如何实现此目标的任何建议?

0 个答案:

没有答案