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();
}
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();
}
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();
}
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));
}
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;
}
Aggregations