Search in sources :

Example 1 with ContainerListener

use of org.talend.sdk.component.container.ContainerListener 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)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 Container (org.talend.sdk.component.container.Container)1 ContainerListener (org.talend.sdk.component.container.ContainerListener)1 ContainerManager (org.talend.sdk.component.container.ContainerManager)1