Search in sources :

Example 6 with ComponentHealthChecker

use of com.alipay.sofa.healthcheck.impl.ComponentHealthChecker in project sofa-boot by alipay.

the class ComponentHealthCheckerTest method componentHealthCheckerTest.

@Test
public void componentHealthCheckerTest() {
    ComponentHealthChecker componentHealthChecker = applicationContext.getBean(ComponentHealthChecker.class);
    Health health = componentHealthChecker.isHealthy();
    Map<String, Object> details = health.getDetails();
    for (String key : details.keySet()) {
        Assert.assertTrue(((String) details.get(key)).contains("passed"));
    }
}
Also used : ComponentHealthChecker(com.alipay.sofa.healthcheck.impl.ComponentHealthChecker) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ComponentHealthChecker

use of com.alipay.sofa.healthcheck.impl.ComponentHealthChecker in project sofa-boot by alipay.

the class HealthCheckerProcessorParallelTest method testComponentHealthCheckerFailedFirst.

@Test
public void testComponentHealthCheckerFailedFirst() {
    SofaRuntimeManager manager = new StandardSofaRuntimeManager("testComponentHealthCheckerFailedFirst", Thread.currentThread().getContextClassLoader(), null);
    manager.getComponentManager().register(new TestComponent("component1", true));
    manager.getComponentManager().register(new TestComponent("component2", true));
    manager.getComponentManager().register(new TestComponent("component3", false));
    manager.getComponentManager().register(new TestComponent("component4", true));
    manager.getComponentManager().register(new TestComponent("component5", false));
    ComponentHealthChecker componentHealthChecker = new ComponentHealthChecker(new SofaRuntimeContext(manager, manager.getComponentManager(), null));
    int i = 0;
    for (Map.Entry<String, Object> entry : componentHealthChecker.isHealthy().getDetails().entrySet()) {
        if (i < 2) {
            Assert.assertEquals(entry.getValue().toString(), "failed");
        } else {
            Assert.assertEquals(entry.getValue().toString(), "passed");
        }
        ++i;
    }
}
Also used : ComponentHealthChecker(com.alipay.sofa.healthcheck.impl.ComponentHealthChecker) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) StandardSofaRuntimeManager(com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager) SofaRuntimeContext(com.alipay.sofa.runtime.spi.component.SofaRuntimeContext) Test(org.junit.Test)

Example 8 with ComponentHealthChecker

use of com.alipay.sofa.healthcheck.impl.ComponentHealthChecker in project sofa-boot by alipay.

the class HealthCheckerConfigTest method testCustomConfig.

@Test
public void testCustomConfig() {
    ComponentHealthChecker componentHealthChecker = ctx.getBean(ComponentHealthChecker.class);
    Assert.assertEquals(customRetryCount, componentHealthChecker.getRetryCount());
    Assert.assertEquals(customRetryInterval, componentHealthChecker.getRetryTimeInterval());
}
Also used : ComponentHealthChecker(com.alipay.sofa.healthcheck.impl.ComponentHealthChecker) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with ComponentHealthChecker

use of com.alipay.sofa.healthcheck.impl.ComponentHealthChecker in project sofa-boot by alipay.

the class SofaComponentHealthCheckerTest method testDefaultConfig.

@Test
public void testDefaultConfig() {
    ComponentHealthChecker sofaComponentHealthChecker = ctx.getBean(ComponentHealthChecker.class);
    Assert.assertEquals(SofaBootConstants.SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_COUNT, sofaComponentHealthChecker.getRetryCount());
    Assert.assertEquals(SofaBootConstants.SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_INTERVAL, sofaComponentHealthChecker.getRetryTimeInterval());
}
Also used : ComponentHealthChecker(com.alipay.sofa.healthcheck.impl.ComponentHealthChecker) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 10 with ComponentHealthChecker

use of com.alipay.sofa.healthcheck.impl.ComponentHealthChecker in project sofa-boot by sofastack.

the class HealthCheckerConfigTest method testCustomConfig.

@Test
public void testCustomConfig() {
    ComponentHealthChecker componentHealthChecker = ctx.getBean(ComponentHealthChecker.class);
    Assert.assertEquals(customRetryCount, componentHealthChecker.getRetryCount());
    Assert.assertEquals(customRetryInterval, componentHealthChecker.getRetryTimeInterval());
}
Also used : ComponentHealthChecker(com.alipay.sofa.healthcheck.impl.ComponentHealthChecker) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

ComponentHealthChecker (com.alipay.sofa.healthcheck.impl.ComponentHealthChecker)10 Test (org.junit.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 StandardSofaRuntimeManager (com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager)4 SofaRuntimeContext (com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)4 SofaRuntimeManager (com.alipay.sofa.runtime.spi.component.SofaRuntimeManager)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Health (org.springframework.boot.actuate.health.Health)2