Search in sources :

Example 1 with MuleLifecycleInterceptor

use of org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor in project mule by mulesoft.

the class TransientRegistryTestCase method testLifecycleStateOutOfSequenceDisposeFirstWithTransientRegistryDirectly.

@Test
public void testLifecycleStateOutOfSequenceDisposeFirstWithTransientRegistryDirectly() throws Exception {
    TransientRegistry reg = new TransientRegistry(UUID.getUUID(), muleContext, new MuleLifecycleInterceptor());
    reg.fireLifecycle(Disposable.PHASE_NAME);
    InterfaceBasedTracker tracker = new InterfaceBasedTracker();
    try {
        reg.registerObject(TEST_KEY, tracker);
        fail("Cannot register objects on a disposed registry");
    } catch (RegistrationException e) {
    // Expected
    }
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) Test(org.junit.Test)

Example 2 with MuleLifecycleInterceptor

use of org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor in project mule by mulesoft.

the class RegistryBrokerTestCase method testConcurrentRegistryAddRemove.

@Test
public void testConcurrentRegistryAddRemove() throws Exception {
    MuleLifecycleInterceptor lifecycleInterceptor = new MuleLifecycleInterceptor();
    final RegistryBroker broker = new DefaultRegistryBroker(muleContext, lifecycleInterceptor);
    final int N = 50;
    final CountDownLatch start = new CountDownLatch(1);
    final CountDownLatch end = new CountDownLatch(N);
    final AtomicInteger errors = new AtomicInteger(0);
    for (int i = 0; i < N; i++) {
        new Thread(() -> {
            try {
                start.await();
                broker.addRegistry(new TransientRegistry(getUUID(), muleContext, lifecycleInterceptor));
                broker.lookupByType(Object.class);
            } catch (Exception e) {
                errors.incrementAndGet();
            } finally {
                end.countDown();
            }
        }, "thread-eval-" + i).start();
    }
    start.countDown();
    end.await();
    if (errors.get() > 0) {
        fail();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) MuleException(org.mule.runtime.api.exception.MuleException) Test(org.junit.Test)

Example 3 with MuleLifecycleInterceptor

use of org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor in project mule by mulesoft.

the class TryProcessorFactoryBeanTestCase method setUp.

@Before
public void setUp() throws RegistrationException {
    registry = new SimpleRegistry(muleContextMock, new MuleLifecycleInterceptor());
    registry.registerObject("txFactory", new TransactionFactoryLocator());
}
Also used : TransactionFactoryLocator(org.mule.runtime.core.internal.transaction.TransactionFactoryLocator) SimpleRegistry(org.mule.runtime.core.internal.registry.SimpleRegistry) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) Before(org.junit.Before)

Example 4 with MuleLifecycleInterceptor

use of org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor in project mule by mulesoft.

the class ExtensionPluginMetadataGenerator method createExtensionManager.

/**
 * Creates a {@link ExtensionManager} needed for generating the metadata for an extension. It would be later discarded due to
 * the manager would have references to classes loaded with the launcher class loader instead of the hierarchical class loaders
 * created as result of the classification process.
 *
 * @return an {@link ExtensionManager} that would be used to register the extensions.
 */
private ExtensionManager createExtensionManager() {
    DefaultExtensionManager extensionManager = new DefaultExtensionManager();
    extensionManager.setMuleContext(new DefaultMuleContext() {

        private ErrorTypeRepository errorTypeRepository = createDefaultErrorTypeRepository();

        private ErrorTypeLocator errorTypeLocator = createDefaultErrorTypeLocator(errorTypeRepository);

        @Override
        public MuleRegistry getRegistry() {
            return new MuleRegistryHelper(new DefaultRegistryBroker(this, new MuleLifecycleInterceptor()), this);
        }

        @Override
        public ErrorTypeLocator getErrorTypeLocator() {
            return errorTypeLocator;
        }

        @Override
        public ErrorTypeRepository getErrorTypeRepository() {
            return errorTypeRepository;
        }
    });
    try {
        extensionManager.initialise();
    } catch (InitialisationException e) {
        throw new RuntimeException("Error while initialising the extension manager", e);
    }
    return extensionManager;
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) DefaultMuleContext(org.mule.runtime.core.internal.context.DefaultMuleContext) DefaultRegistryBroker(org.mule.runtime.core.internal.registry.DefaultRegistryBroker) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) DefaultExtensionManager(org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager)

Example 5 with MuleLifecycleInterceptor

use of org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor in project mule by mulesoft.

the class RegistryBrokerTestCase method testCrossRegistryLifecycleOrder.

@Test
public void testCrossRegistryLifecycleOrder() throws MuleException {
    TransientRegistry reg1 = new TransientRegistry(getUUID(), muleContext, new MuleLifecycleInterceptor());
    reg1.initialise();
    TransientRegistry reg2 = new TransientRegistry(getUUID(), muleContext, new MuleLifecycleInterceptor());
    reg2.initialise();
    reg1.registerObject("flow", new LifecycleTrackerFlow("flow", muleContext));
    reg2.registerObject("flow2", new LifecycleTrackerFlow("flow2", muleContext));
    ((MuleContextWithRegistries) muleContext).addRegistry(reg1);
    ((MuleContextWithRegistries) muleContext).addRegistry(reg2);
    muleContext.start();
    // Both connectors are started before either flow
    assertEquals("flow2-start flow-start ", tracker.toString());
    tracker = new String();
    muleContext.stop();
    // Both services are stopped before either connector
    assertEquals("flow2-stop flow-stop ", tracker);
}
Also used : MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) Test(org.junit.Test)

Aggregations

MuleLifecycleInterceptor (org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor)5 Test (org.junit.Test)3 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Before (org.junit.Before)1 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)1 MuleException (org.mule.runtime.api.exception.MuleException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 DefaultMuleContext (org.mule.runtime.core.internal.context.DefaultMuleContext)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 ErrorTypeLocatorFactory.createDefaultErrorTypeLocator (org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator)1 ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository (org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository)1 DefaultRegistryBroker (org.mule.runtime.core.internal.registry.DefaultRegistryBroker)1 MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)1 MuleRegistryHelper (org.mule.runtime.core.internal.registry.MuleRegistryHelper)1 SimpleRegistry (org.mule.runtime.core.internal.registry.SimpleRegistry)1 TransactionFactoryLocator (org.mule.runtime.core.internal.transaction.TransactionFactoryLocator)1 ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)1 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)1 DefaultExtensionManager (org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager)1