Search in sources :

Example 1 with ContainerManager

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());
        }
    });
}
Also used : ContainerManager(org.talend.sdk.component.container.ContainerManager) Container(org.talend.sdk.component.container.Container) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with ContainerManager

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();
    });
}
Also used : ContainerManager(org.talend.sdk.component.container.ContainerManager) Test(org.junit.jupiter.api.Test)

Example 3 with ContainerManager

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());
}
Also used : Container(org.talend.sdk.component.container.Container) ContainerManager(org.talend.sdk.component.container.ContainerManager) ArrayList(java.util.ArrayList) ContainerListener(org.talend.sdk.component.container.ContainerListener) Test(org.junit.jupiter.api.Test)

Example 4 with ContainerManager

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));
}
Also used : ContainerManager(org.talend.sdk.component.container.ContainerManager) MvnDependencyListLocalRepositoryResolver(org.talend.sdk.component.dependencies.maven.MvnDependencyListLocalRepositoryResolver) File(java.io.File) Date(java.util.Date) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.jupiter.api.Test)

Example 5 with ContainerManager

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()));
}
Also used : ContainerManager(org.talend.sdk.component.container.ContainerManager) Container(org.talend.sdk.component.container.Container) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 ContainerManager (org.talend.sdk.component.container.ContainerManager)5 Container (org.talend.sdk.component.container.Container)3 File (java.io.File)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 ContainerListener (org.talend.sdk.component.container.ContainerListener)1 MvnDependencyListLocalRepositoryResolver (org.talend.sdk.component.dependencies.maven.MvnDependencyListLocalRepositoryResolver)1