2

我正在NetworkClientServiceImpl使用 WireMock 技术为我的 Java 类编写集成测试,但我遇到了一些异常,我无法解决它们。

NetworkClientServiceImpl以下是我正在为其编写集成测试的类内部声明的方法。

 public Observable<NetworkOptionResponse> getSettingsValues(final NetworkClientQuery networkClientQuery, final String names) throws
    NetworkException {

    checkArgument(networkClientQuery != null, MISSING_REQUIRED_PARAMETER, "networkClientQuery");
    logger.info("Get Networking Settings Values for names:{} and QueryParams:{}", names,networkClientQuery.getQueryParams());

    try {
        String url = UriBuilder.fromPath("/networkmiddle/settings/{names}").build(names).getPath();
        logger.info("UrlPath "+url);
        return commandBuilder.build(url, HttpRequest.Verb.GET,NetworkOptionResponse.class,networkClientQuery.getQueryParams()).observe();


    } catch (final Exception ex) {

        String errorMessage = String.format("Failed to get NetworkSettings Values for names:[%s] with error:[%s]", names, NetworkClientUtils.getErrorMessage(ex));
        logger.error(errorMessage, ex);
        throw new NetworkException(errorMessage, Response.Status.INTERNAL_SERVER_ERROR);
    }
}

NetworkClientServiceImplIT常规文件:

class NetworkClientServiceImplIT extends Specification{

@Inject
NetworkClientService service
@Rule
private WireMockRule middleMock = new WireMockRule(WireMockConfiguration.wireMockConfig().port(19080));

def 'validate config'() {
    expect:
    service != null
}

def 'Get Settings Values'(){
    given:
    Builder builder = new Builder();
    builder = builder.withQueryParam("device", "000004FA4D88")
    builder = builder.withQueryParam("home", "8087300010167669")
    builder = builder.withQueryParam("user", "testid195")
    NetworkClientQuery query = builder.build();
    String names = "Favourites";
    String json = '{"settings": [{ "name": "DVS", "value": ["Off"] },{ "name": "Info Banner Duration", "value": ["15"] },{ "name": "Rating Locks", "value": ["TVMA","NC17","NR Mature"] }]}'
    ResponseDefinitionBuilder responseBuilder = new ResponseDefinitionBuilder();
    responseBuilder.build().setBody(json);
    String urlPath = "/networkmiddle/settings/"
    middleMock.stubFor(get(urlPathEqualTo(urlPath)).willReturn(responseBuilder))

    when:
    Observable<NetworkOptionResponse> response = service.getValues(query,names);
    println'********* Test1 ******'
    println'********* Test2 ******'+response
    println'********* Test3 ******'+response.getClass()
    NetworkOptionResponse response2 = response.toBlocking().single();
    println'********* Test4 ******'
    then:
    response != null
    println '** Response '+response
    response2 != null
    println '** Response2 '+response2

}
}

当我执行 Maven 全新安装时,我收到以下响应:

********* Test1 ******
 13:57:58.309 [hystrix-networkMiddleThreadPool-1] DEBUG c.c.a.h.u.aws.CharterHystrixCommand - HttpResuest URL: /networksettingsmiddle/settings/Favourites
13:57:58.310 [hystrix-networkMiddleThreadPool-1] DEBUG c.n.l.ZoneAwareLoadBalancer - Zone aware logic disabled or there is only one zone
13:57:58.311 [hystrix-networkMiddleThreadPool-1] WARN  c.n.loadbalancer.RoundRobinRule - No up servers available from load balancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=networkClient,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:com.netflix.loadbalancer.ConfigurationBasedServerList@24bdb479
********* Test2 ******rx.subjects.ReplaySubject@1542af63
13:57:58.344 [hystrix-networkMiddleThreadPool-1] DEBUG com.netflix.hystrix.AbstractCommand - Error executing HystrixCommand.run(). Proceeding to fallback logic ...
com.netflix.client.ClientException: Using ClientName: networkClient, VipAddress: 
at com.charter.aesd.hystrix.utils.aws.CharterHystrixCommand.run(CharterHystrixCommand.java:141) ~[ribbon-lib-2.3.0.jar:na]
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:294) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:289) [hystrix-core-1.4.23.jar:1.4.23]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable.unsafeSubscribe(Observable.java:8098) [rxjava-1.1.0.jar:1.1.0]
at com.netflix.hystrix.AbstractCommand$5.call(AbstractCommand.java:521) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.AbstractCommand$5.call(AbstractCommand.java:499) [hystrix-core-1.4.23.jar:1.4.23]
at rx.Observable.unsafeSubscribe(Observable.java:8098) [rxjava-1.1.0.jar:1.1.0]
at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62) [rxjava-1.1.0.jar:1.1.0]
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:56) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:47) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69) [hystrix-core-1.4.23.jar:1.4.23]
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) [rxjava-1.1.0.jar:1.1.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_91]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
Caused by: com.netflix.client.ClientException: LoadBalancer returned null Server for :networkClient
at com.netflix.client.LoadBalancerContext.computeFinalUriWithLoadBalancer(LoadBalancerContext.java:418) ~[ribbon-core-0.3.13.jar:na]
at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:166) ~[ribbon-core-0.3.13.jar:na]
at com.charter.aesd.hystrix.utils.aws.CharterHystrixCommand.run(CharterHystrixCommand.java:118) ~[ribbon-lib-2.3.0.jar:na]
... 22 common frames omitted
 13:57:58.392 [hystrix-networkMiddleThreadPool-1] DEBUG com.netflix.hystrix.AbstractCommand - No fallback for HystrixCommand. 
 java.lang.UnsupportedOperationException: No fallback available.
at com.netflix.hystrix.HystrixCommand.getFallback(HystrixCommand.java:284) ~[hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:311) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:306) [hystrix-core-1.4.23.jar:1.4.23]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable.unsafeSubscribe(Observable.java:8098) [rxjava-1.1.0.jar:1.1.0]
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:100) [rxjava-1.1.0.jar:1.1.0]
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) [rxjava-1.1.0.jar:1.1.0]
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) [rxjava-1.1.0.jar:1.1.0]
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$3.onError(AbstractCommand.java:1012) [hystrix-core-1.4.23.jar:1.4.23]
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) [rxjava-1.1.0.jar:1.1.0]
at rx.internal.operators.OperatorSubscribeOn$1$1$1.onError(OperatorSubscribeOn.java:71) [rxjava-1.1.0.jar:1.1.0]
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:71) [rxjava-1.1.0.jar:1.1.0]
at com.netflix.hystrix.AbstractCommand$DeprecatedOnRunHookApplication$1.onError(AbstractCommand.java:1480) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.AbstractCommand$ExecutionHookApplication$1.onError(AbstractCommand.java:1376) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:297) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:289) [hystrix-core-1.4.23.jar:1.4.23]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:162) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable$2.call(Observable.java:154) [rxjava-1.1.0.jar:1.1.0]
at rx.Observable.unsafeSubscribe(Observable.java:8098) [rxjava-1.1.0.jar:1.1.0]
at com.netflix.hystrix.AbstractCommand$5.call(AbstractCommand.java:521) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.AbstractCommand$5.call(AbstractCommand.java:499) [hystrix-core-1.4.23.jar:1.4.23]
at rx.Observable.unsafeSubscribe(Observable.java:8098) [rxjava-1.1.0.jar:1.1.0]
at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62) [rxjava-1.1.0.jar:1.1.0]
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:56) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:47) [hystrix-core-1.4.23.jar:1.4.23]
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69) [hystrix-core-1.4.23.jar:1.4.23]
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) [rxjava-1.1.0.jar:1.1.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_91]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
********* Test3 ******class rx.subjects.ReplaySubject
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.053 sec <<< FAILURE!
Get Settings Values(com.charter.aesd.network.client.api.test.NetworkClientServiceImplIT)  Time elapsed: 0.688 sec  <<< ERROR!
com.netflix.hystrix.exception.HystrixRuntimeException: networkMiddleCommand failed and no fallback available.
at com.netflix.client.LoadBalancerContext.computeFinalUriWithLoadBalancer(LoadBalancerContext.java:418)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:166)
at com.charter.aesd.hystrix.utils.aws.CharterHystrixCommand.run(CharterHystrixCommand.java:118)
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:294)
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:289)
at rx.Observable$2.call(Observable.java:162)
at rx.Observable$2.call(Observable.java:154)
at rx.Observable$2.call(Observable.java:162)
at rx.Observable$2.call(Observable.java:154)
at rx.Observable$2.call(Observable.java:162)
at rx.Observable$2.call(Observable.java:154)
at rx.Observable.unsafeSubscribe(Observable.java:8098)
at com.netflix.hystrix.AbstractCommand$5.call(AbstractCommand.java:521)
at com.netflix.hystrix.AbstractCommand$5.call(AbstractCommand.java:499)
at rx.Observable.unsafeSubscribe(Observable.java:8098)
at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62)
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:56)
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction$1.call(HystrixContexSchedulerAction.java:47)
at com.netflix.hystrix.strategy.concurrency.HystrixContexSchedulerAction.call(HystrixContexSchedulerAction.java:69)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

13:57:58.550 [Thread-2] INFO  c.n.l.DynamicServerListLoadBalancer - Shutting down the Executor Pool for DynamicServerListLoadBalancer

Results :

Tests in error: 
» HystrixRuntime networkMiddleCommand failed and no fallback availabl...
4

0 回答 0