use of org.talend.sdk.component.container.ContainerManager in project component-runtime by Talend.
the class ContainerManagerTest method autoContainerId.
@Test
void autoContainerId(final TempJars jars) {
Stream.of("ziplock-7.00.3.jar", "ziplock-7.3.jar", "ziplock-7.3-SNAPSHOT.jar", "ziplock-7.3.0-SNAPSHOT.jar").forEach(jarName -> {
try (final ContainerManager manager = createDefaultManager()) {
final File module = createZiplockJar(jars);
final File jar = new File(module.getParentFile(), jarName);
assertTrue(module.renameTo(jar));
final Container container = manager.builder(jar.getAbsolutePath()).create();
assertEquals("ziplock", /* no version, no .jar */
container.getId());
}
});
}
use of org.talend.sdk.component.container.ContainerManager in project component-runtime by Talend.
the class ContainerManagerTest method close.
@Test
void close(final TempJars jars) {
assertThrows(IllegalStateException.class, () -> {
final ContainerManager manager = createDefaultManager();
manager.close();
manager.builder("foo", createZiplockJar(jars).getAbsolutePath()).create();
});
}
use of org.talend.sdk.component.container.ContainerManager in project component-runtime by Talend.
the class ContainerManagerTest method listeners.
@Test
void listeners(final TempJars jars) {
final Collection<String> states = new ArrayList<>();
final ContainerListener listener = new ContainerListener() {
@Override
public void onCreate(final Container container) {
states.add("deploy #" + container.getId());
}
@Override
public void onClose(final Container container) {
states.add("undeploy #" + container.getId());
}
};
try (final ContainerManager manager = createDefaultManager().registerListener(listener)) {
assertEquals(emptyList(), states);
try (final Container container = manager.builder(createZiplockJar(jars).getAbsolutePath()).create()) {
assertEquals(1, states.size());
}
assertEquals(2, states.size());
manager.unregisterListener(listener);
try (final Container container = manager.builder(createZiplockJar(jars).getAbsolutePath()).create()) {
assertEquals(2, states.size());
}
assertEquals(2, states.size());
}
assertEquals(2, states.size());
}
use of org.talend.sdk.component.container.ContainerManager in project component-runtime by Talend.
the class JmxManagerTest method jmx.
@Test
void jmx() throws Exception {
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
final JmxManager jmxManager = new JmxManager(null, "org.talend.test:type=plugin,name=%s", mBeanServer);
final ContainerManager containerManager = new ContainerManager(ContainerManager.DependenciesResolutionConfiguration.builder().resolver(new MvnDependencyListLocalRepositoryResolver(Constants.DEPENDENCIES_LIST_RESOURCE_PATH)).rootRepositoryLocation(new File(Constants.DEPENDENCIES_LOCATION)).create(), ContainerManager.ClassLoaderConfiguration.builder().create(), null, Level.INFO);
containerManager.registerListener(jmxManager);
containerManager.builder("foo.jar", new File("missing/normally").getName()).create();
final ObjectName name = new ObjectName("org.talend.test:name=foo.jar,type=plugin");
try {
assertTrue(mBeanServer.isRegistered(name));
assertFalse(Boolean.class.cast(mBeanServer.getAttribute(name, "closed")));
final Object created = mBeanServer.getAttribute(name, "created");
assertTrue(Date.class.isInstance(created));
// ensure date is stable until reloading
assertEquals(created, created);
mBeanServer.invoke(name, "reload", new Object[0], new String[0]);
assertNotSame(created, mBeanServer.getAttribute(name, "created"));
} finally {
containerManager.close();
}
assertFalse(mBeanServer.isRegistered(name));
}
use of org.talend.sdk.component.container.ContainerManager in project component-runtime by Talend.
the class ContainerManagerTest method manage.
// note: in this method we could keep a ref of list or finds but
// we abuse intentionally of the manager methods
// to ensure they are reentrant
@Test
void manage(final TempJars jars) {
final ContainerManager ref;
final Collection<Container> containers;
try (final ContainerManager manager = createDefaultManager()) {
ref = manager;
final Container container = manager.builder("foo", createZiplockJar(jars).getAbsolutePath()).create();
assertNotNull(container);
// container is not tested here but in ContainerTest. Here we just take care
// of the manager.
assertEquals(1, manager.findAll().size());
assertEquals(singletonList(container), new ArrayList<>(manager.findAll()));
assertTrue(manager.find("foo").isPresent());
assertEquals(container, manager.find("foo").get());
final Container xbean = manager.builder("bar", createZiplockJar(jars).getAbsolutePath()).create();
assertEquals(2, manager.findAll().size());
Stream.of(container, xbean).forEach(c -> assertTrue(manager.findAll().contains(c)));
containers = manager.findAll();
}
// now manager is closed so all containers are cleaned up
assertTrue(ref.isClosed());
containers.forEach(c -> assertTrue(c.isClosed()));
}
Aggregations