MockRestServiceServer simulate backend timeout in integration test

前端 未结 5 1902
太阳男子
太阳男子 2021-02-12 20:02

I am writing some kind of integration test on my REST controller using MockRestServiceServer to mock backend behaviour. What I am trying to achieve now is to simulate very slow

5条回答
  •  时光说笑
    2021-02-12 20:44

    If you control timeout in your http client and use for example 1 seconds you can use mock server delay

    new MockServerClient("localhost", 1080)
    .when(
        request()
            .withPath("/some/path")
    )
    .respond(
        response()
            .withBody("some_response_body")
            .withDelay(TimeUnit.SECONDS, 10)
    );
    

    If you want to drop connection in Mock Server use mock server error action

    new MockServerClient("localhost", 1080)
    .when(
        request()
            .withPath("/some/path")
    )
    .error(
        error()
            .withDropConnection(true)
    );
    

提交回复
热议问题