Search in sources :

Example 6 with Lifecycle

use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.

the class DefaultLifecycleControllerTest method testCanStart.

@Test
public void testCanStart() throws Exception {
    Lifecycle lifecycle = new NoOpLifecycleObject();
    try {
        lifecycle.start();
        Assert.fail();
    } catch (Exception e) {
    }
    lifecycle.initialize();
    lifecycle.start();
    lifecycle.stop();
    lifecycle.start();
    lifecycle.stop();
    lifecycle.dispose();
    try {
        lifecycle.start();
        Assert.fail();
    } catch (Exception e) {
    }
}
Also used : Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 7 with Lifecycle

use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.

the class DefaultLifecycleControllerTest method testCanDispose.

@Test
public void testCanDispose() throws Exception {
    Lifecycle lifecycle = new NoOpLifecycleObject();
    try {
        lifecycle.dispose();
        Assert.fail();
    } catch (Exception e) {
    }
    lifecycle.initialize();
    lifecycle.dispose();
    lifecycle.initialize();
    lifecycle.start();
    try {
        lifecycle.dispose();
        Assert.fail();
    } catch (Exception e) {
    }
    lifecycle.stop();
    lifecycle.dispose();
    try {
        lifecycle.dispose();
        Assert.fail();
    } catch (Exception e) {
    }
}
Also used : Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 8 with Lifecycle

use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.

the class DefaultLifecycleControllerTest method testCanStop.

@Test
public void testCanStop() throws Exception {
    Lifecycle lifecycle = new NoOpLifecycleObject();
    try {
        lifecycle.stop();
        Assert.fail();
    } catch (Exception e) {
    }
    lifecycle.initialize();
    try {
        lifecycle.stop();
        Assert.fail();
    } catch (Exception e) {
    }
    lifecycle.start();
    lifecycle.stop();
    lifecycle.dispose();
    try {
        lifecycle.stop();
        Assert.fail();
    } catch (Exception e) {
    }
}
Also used : Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 9 with Lifecycle

use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.

the class SpringComponentRegistry method lifecycleCallable.

@Override
public List<Lifecycle> lifecycleCallable() {
    List<Lifecycle> result = new LinkedList<>();
    Map<String, Lifecycle> beans = applicationContext.getBeansOfType(Lifecycle.class);
    for (Entry<String, Lifecycle> entry : beans.entrySet()) {
        @SuppressWarnings("unused") String name = entry.getKey();
        Lifecycle bean = entry.getValue();
        if (bean instanceof TopElement) {
            result.add((Lifecycle) bean);
        }
    }
    return sort(result);
}
Also used : TopElement(com.ctrip.xpipe.api.lifecycle.TopElement) Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) LinkedList(java.util.LinkedList)

Example 10 with Lifecycle

use of com.ctrip.xpipe.api.lifecycle.Lifecycle in project x-pipe by ctripcorp.

the class SpringComponentRegistryTest method test.

@Test
public void test() throws Exception {
    ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(TestFactory.class);
    ComponentRegistry componentRegistry = new SpringComponentRegistry(applicationContext);
    componentRegistry.initialize();
    componentRegistry.start();
    Map<String, Lifecycle> objects = componentRegistry.getComponents(Lifecycle.class);
    for (Lifecycle lifecycle : objects.values()) {
        if (lifecycle instanceof TopElement) {
            Assert.assertTrue(lifecycle.getLifecycleState().isStarted());
        } else {
            Assert.assertTrue(lifecycle.getLifecycleState().isEmpty());
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TopElement(com.ctrip.xpipe.api.lifecycle.TopElement) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Aggregations

Lifecycle (com.ctrip.xpipe.api.lifecycle.Lifecycle)10 AbstractTest (com.ctrip.xpipe.AbstractTest)6 Test (org.junit.Test)6 TopElement (com.ctrip.xpipe.api.lifecycle.TopElement)2 ComponentRegistry (com.ctrip.xpipe.api.lifecycle.ComponentRegistry)1 CreatedComponentRedistry (com.ctrip.xpipe.lifecycle.CreatedComponentRedistry)1 SpringComponentRegistry (com.ctrip.xpipe.lifecycle.SpringComponentRegistry)1 LinkedList (java.util.LinkedList)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1