首页 > 解决方案 > 如何测试应用程序的弹性

问题描述

我们在 SAP Cloud Platform Cloud Foundry 上运行了一个云应用程序,它利用了其他重用服务,例如审计服务

为了测试弹性,我们需要模拟重用服务的停止

您能否分享一些指导如何实现这一目标?

问候, Apoorv

标签: sap-cloud-platform

解决方案


按照教程Introduce Resilience to your Application,他们在他们的应用程序中添加了一个测试,为了模拟被调用服务的问题,他们只是指向一个不存在的目的地。

他们介绍的测试是:

@Test
    public void testWithFallback() {
        // Simulate a failed VDM call with non-existent destination
        DestinationAccessor.setLoader((n, o) -> Try.success(dummyDestination));

        // Assure an empty list is returned as fallback
        when()
                .get("/businesspartners")
                .then()
                .statusCode(200)
                .contentType(ContentType.JSON)
                .body("", Matchers.hasSize(0));
    }

目的地定义为:

private static final String DESTINATION_NAME = "MyErpSystem";
    private static final Destination dummyDestination = DefaultDestination.builder().property("name", DESTINATION_NAME).property("URL", "foo").build();

希望这可以帮助您朝着正确的方向前进。

氪,凯派


推荐阅读