Search in sources :

Example 1 with SofaRuntimeContext

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeContext in project sofa-boot by sofastack.

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 2 with SofaRuntimeContext

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeContext in project sofa-boot by sofastack.

the class HealthCheckerProcessorTest 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 3 with SofaRuntimeContext

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeContext in project sofa-boot by alipay.

the class HealthCheckerProcessorTest 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 4 with SofaRuntimeContext

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeContext in project sofa-boot by alipay.

the class ComponentManagerShutdownTest method initComponentManager.

private ComponentManager initComponentManager() {
    AnnotationConfigApplicationContext rootContext = new AnnotationConfigApplicationContext(ComponentManagerTestConfiguration.class);
    SofaRuntimeContext sofaRuntimeContext = rootContext.getBean(SofaRuntimeContext.class);
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ComponentName serviceComponentName = ComponentNameFactory.createComponentName(SERVICE_COMPONENT_TYPE, SampleService.class, "");
    ComponentInfo serviceComponentInfo = componentManager.getComponentInfo(serviceComponentName);
    componentManager.register(serviceComponentInfo);
    GenericApplicationContext applicationContext = new GenericApplicationContext();
    ComponentName springComponentName = ComponentNameFactory.createComponentName(SPRING_COMPONENT_TYPE, "testModule");
    ComponentInfo springComponentInfo = new SpringContextComponent(springComponentName, new SpringContextImplementation(applicationContext), sofaRuntimeContext);
    applicationContext.refresh();
    componentManager.register(springComponentInfo);
    return componentManager;
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) SpringContextImplementation(com.alipay.sofa.runtime.spring.SpringContextImplementation) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) SpringContextComponent(com.alipay.sofa.runtime.spring.SpringContextComponent) SofaRuntimeContext(com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)

Example 5 with SofaRuntimeContext

use of com.alipay.sofa.runtime.spi.component.SofaRuntimeContext 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)

Aggregations

SofaRuntimeContext (com.alipay.sofa.runtime.spi.component.SofaRuntimeContext)6 ComponentHealthChecker (com.alipay.sofa.healthcheck.impl.ComponentHealthChecker)4 StandardSofaRuntimeManager (com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager)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 Test (org.junit.Test)4 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)2 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)2 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)2 SpringContextComponent (com.alipay.sofa.runtime.spring.SpringContextComponent)2 SpringContextImplementation (com.alipay.sofa.runtime.spring.SpringContextImplementation)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2