Search in sources :

Example 16 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerTestCase method disposesCoreExtensions.

@Test
public void disposesCoreExtensions() throws Exception {
    List<MuleCoreExtension> extensions = new LinkedList<>();
    TestDeploymentServiceAwareExtension extension1 = mock(TestDeploymentServiceAwareExtension.class);
    MuleCoreExtension extension2 = mock(MuleCoreExtension.class);
    extensions.add(extension1);
    extensions.add(extension2);
    when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
    List<MuleCoreExtension> orderedExtensions = new LinkedList<>();
    orderedExtensions.add(extension1);
    orderedExtensions.add(extension2);
    when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(orderedExtensions);
    coreExtensionManager.initialise();
    coreExtensionManager.dispose();
    InOrder inOrder = inOrder(extension1, extension2);
    inOrder.verify(extension1).dispose();
    inOrder.verify(extension2).dispose();
}
Also used : InOrder(org.mockito.InOrder) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 17 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerTestCase method initializesCoreExtensionsInOrder.

@Test
public void initializesCoreExtensionsInOrder() throws Exception {
    List<MuleCoreExtension> extensions = new LinkedList<>();
    MuleCoreExtension extension1 = mock(MuleCoreExtension.class);
    MuleCoreExtension extension2 = mock(MuleCoreExtension.class);
    extensions.add(extension1);
    extensions.add(extension2);
    when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
    List<MuleCoreExtension> orderedExtensions = new LinkedList<>();
    orderedExtensions.add(extension2);
    orderedExtensions.add(extension1);
    when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(orderedExtensions);
    coreExtensionManager.initialise();
    InOrder ordered = inOrder(extension1, extension2);
    ordered.verify(extension2).initialise();
    ordered.verify(extension1).initialise();
}
Also used : InOrder(org.mockito.InOrder) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 18 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerTestCase method stopsCoreExtensionsAfterStartFail.

@Test
public void stopsCoreExtensionsAfterStartFail() throws Exception {
    List<MuleCoreExtension> extensions = new LinkedList<>();
    MuleCoreExtension extension1 = mock(MuleCoreExtension.class);
    MuleCoreExtension extension2 = mock(MuleCoreExtension.class);
    Exception firstStartFailure = new RuntimeException();
    doThrow(firstStartFailure).when(extension1).start();
    when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
    extensions.add(extension1);
    extensions.add(extension2);
    List<MuleCoreExtension> orderedExtensions = new LinkedList<>();
    orderedExtensions.add(extension1);
    orderedExtensions.add(extension2);
    when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(orderedExtensions);
    coreExtensionManager.initialise();
    try {
        coreExtensionManager.start();
        fail();
    } catch (Exception e) {
        assertThat(e, sameInstance(firstStartFailure));
    }
    coreExtensionManager.stop();
    verify(extension2, never()).stop();
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException(org.junit.rules.ExpectedException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 19 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class ReflectionMuleCoreExtensionDependencyResolverTestCase method resolvesIndependentExtensions.

@Test
public void resolvesIndependentExtensions() throws Exception {
    MuleCoreExtension extension1 = mockCoreExtension(EXTENSION1);
    MuleCoreExtension extension2 = mockCoreExtension(EXTENSION2);
    List<MuleCoreExtension> coreExtensions = new LinkedList<>();
    coreExtensions.add(extension2);
    coreExtensions.add(extension1);
    final List<MuleCoreExtension> resolvedCoreExtensions = dependencyResolver.resolveDependencies(coreExtensions);
    verify(dependencyDiscoverer, times(2)).findDependencies(Matchers.<MuleCoreExtension>anyObject());
    assertThat(resolvedCoreExtensions.size(), equalTo(2));
    assertThat(resolvedCoreExtensions.get(0), sameInstance(extension1));
    assertThat(resolvedCoreExtensions.get(1), sameInstance(extension2));
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 20 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class ReflectionMuleCoreExtensionDependencyResolver method resolveCoreExtensionDependenciesOrder.

private List<MuleCoreExtension> resolveCoreExtensionDependenciesOrder(List<MuleCoreExtension> sortedCoreExtensions) {
    List<MuleCoreExtension> unresolvedExtensions = new LinkedList<>(sortedCoreExtensions);
    List<MuleCoreExtension> resolvedExtensions = new LinkedList<>();
    boolean continueResolution = true;
    while (continueResolution) {
        int initialResolvedCount = resolvedExtensions.size();
        List<MuleCoreExtension> pendingUnresolvedExtensions = new LinkedList<>();
        for (MuleCoreExtension muleCoreExtension : unresolvedExtensions) {
            if (isResolvedCoreExtension(muleCoreExtension, resolvedExtensions)) {
                resolvedExtensions.add(muleCoreExtension);
            } else {
                pendingUnresolvedExtensions.add(muleCoreExtension);
            }
        }
        // Will try to resolve the extensions that are still unresolved
        unresolvedExtensions = pendingUnresolvedExtensions;
        continueResolution = resolvedExtensions.size() > initialResolvedCount;
    }
    if (unresolvedExtensions.size() != 0) {
        throw new UnresolveableDependencyException("Unable to resolve core extension dependencies: " + unresolvedExtensions);
    }
    return resolvedExtensions;
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList)

Aggregations

MuleCoreExtension (org.mule.runtime.container.api.MuleCoreExtension)23 LinkedList (java.util.LinkedList)17 Test (org.junit.Test)15 SmallTest (org.mule.tck.size.SmallTest)14 InOrder (org.mockito.InOrder)5 MuleException (org.mule.runtime.api.exception.MuleException)4 URL (java.net.URL)2 ExpectedException (org.junit.rules.ExpectedException)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 Map (java.util.Map)1 Properties (java.util.Properties)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ServiceRepository (org.mule.runtime.api.service.ServiceRepository)1 ArtifactClassLoaderManagerAware (org.mule.runtime.container.api.ArtifactClassLoaderManagerAware)1 CoreExtensionsAware (org.mule.runtime.container.api.CoreExtensionsAware)1 Injector (org.mule.runtime.core.api.Injector)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 PropertiesUtils.loadProperties (org.mule.runtime.core.api.util.PropertiesUtils.loadProperties)1 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)1 ArtifactDeploymentListener (org.mule.runtime.module.deployment.api.ArtifactDeploymentListener)1