Search in sources :

Example 1 with CreatedComponentRedistry

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

the class CreatedComponentRedistryTest method test.

@Test
public void test() throws Exception {
    CreatedComponentRedistry registry = new CreatedComponentRedistry();
    String name = registry.add(new Object());
    logger.info("{}", name);
    Lifecycle lifecycle = new NoOpLifecycleObject();
    registry.add(lifecycle);
    registry.initialize();
    registry.start();
    Assert.assertTrue(lifecycle.getLifecycleState().isStarted());
    Lifecycle lifecycle2 = new NoOpLifecycleObject();
    registry.add(lifecycle2);
    Assert.assertTrue(lifecycle2.getLifecycleState().isStarted());
    registry.remove(lifecycle2);
    Assert.assertTrue(lifecycle2.getLifecycleState().isDisposed());
    Assert.assertEquals(2, registry.allComponents().size());
}
Also used : CreatedComponentRedistry(com.ctrip.xpipe.lifecycle.CreatedComponentRedistry) Lifecycle(com.ctrip.xpipe.api.lifecycle.Lifecycle) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 2 with CreatedComponentRedistry

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

the class AbstractTest method beforeAbstractTest.

@Before
public void beforeAbstractTest() throws Exception {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
    // clear interrupt
    Thread.interrupted();
    executors = Executors.newCachedThreadPool(XpipeThreadFactory.create(getTestName()));
    scheduled = Executors.newScheduledThreadPool(OsUtils.getCpuCount(), XpipeThreadFactory.create(getTestName()));
    orginProperties = (Properties) System.getProperties().clone();
    doBeforeAbstractTest();
    logger.info(remarkableMessage("[begin test][{}]"), name.getMethodName());
    componentRegistry = new DefaultRegistry(new CreatedComponentRedistry(), getSpringRegistry());
    startedComponentRegistry = new CreatedComponentRedistry();
    startedComponentRegistry.initialize();
    startedComponentRegistry.start();
    Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
    InputStream fins = getClass().getClassLoader().getResourceAsStream("xpipe-test.properties");
    try {
        properties.load(fins);
    } finally {
        if (fins != null) {
            fins.close();
        }
    }
    File file = new File(getTestFileDir());
    if (file.exists() && deleteTestDirBeforeTest()) {
        deleteTestDir();
    }
    if (!file.exists()) {
        boolean testSucceed = file.mkdirs();
        if (!testSucceed) {
            throw new IllegalStateException("test dir make failed!" + file);
        }
    }
}
Also used : CreatedComponentRedistry(com.ctrip.xpipe.lifecycle.CreatedComponentRedistry) DefaultRegistry(com.ctrip.xpipe.lifecycle.DefaultRegistry) DefaultExceptionHandler(com.ctrip.xpipe.exception.DefaultExceptionHandler)

Example 3 with CreatedComponentRedistry

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

the class AppTest method initComponentRegistry.

private void initComponentRegistry(ConfigurableApplicationContext context) throws Exception {
    ComponentRegistry registry = new DefaultRegistry(new CreatedComponentRedistry(), new SpringComponentRegistry(context));
    registry.initialize();
    registry.start();
    ComponentRegistryHolder.initializeRegistry(registry);
}
Also used : SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) CreatedComponentRedistry(com.ctrip.xpipe.lifecycle.CreatedComponentRedistry) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) DefaultRegistry(com.ctrip.xpipe.lifecycle.DefaultRegistry)

Example 4 with CreatedComponentRedistry

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

the class KeeperContainerApplication method initComponentRegistry.

private static ComponentRegistry initComponentRegistry(ConfigurableApplicationContext context) throws Exception {
    final ComponentRegistry registry = new DefaultRegistry(new CreatedComponentRedistry(), new SpringComponentRegistry(context));
    registry.initialize();
    registry.start();
    ComponentRegistryHolder.initializeRegistry(registry);
    return registry;
}
Also used : SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) CreatedComponentRedistry(com.ctrip.xpipe.lifecycle.CreatedComponentRedistry) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) DefaultRegistry(com.ctrip.xpipe.lifecycle.DefaultRegistry)

Aggregations

CreatedComponentRedistry (com.ctrip.xpipe.lifecycle.CreatedComponentRedistry)4 DefaultRegistry (com.ctrip.xpipe.lifecycle.DefaultRegistry)3 ComponentRegistry (com.ctrip.xpipe.api.lifecycle.ComponentRegistry)2 SpringComponentRegistry (com.ctrip.xpipe.lifecycle.SpringComponentRegistry)2 AbstractTest (com.ctrip.xpipe.AbstractTest)1 Lifecycle (com.ctrip.xpipe.api.lifecycle.Lifecycle)1 DefaultExceptionHandler (com.ctrip.xpipe.exception.DefaultExceptionHandler)1 Test (org.junit.Test)1