Search in sources :

Example 41 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration by spring-projects.

the class MBeanExporterIntegrationTests method testCircularReferenceWithChannel.

@Test
public void testCircularReferenceWithChannel() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "oref-channel.xml");
    messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
    assertNotNull(messageChannelsMonitor);
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Example 42 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration by spring-projects.

the class MBeanExporterIntegrationTests method testSelfDestruction.

@Test
public void testSelfDestruction() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "self-destruction-context.xml");
    SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class);
    adapter.start();
    int n = 0;
    while (adapter.isRunning()) {
        n += 10;
        if (n > 10000) {
            fail("Adapter failed to stop");
        }
        Thread.sleep(10);
    }
}
Also used : SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Test(org.junit.Test)

Example 43 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration by spring-projects.

the class MBeanExporterIntegrationTests method testDuplicateComponentNames.

@Test
public void testDuplicateComponentNames() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "duplicate-components.xml");
    messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
    assertNotNull(messageChannelsMonitor);
    MBeanServer server = context.getBean(MBeanServer.class);
    Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
    assertEquals(2, names.size());
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 44 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration by spring-projects.

the class MBeanExporterIntegrationTests method testLifecycleInEndpointWithoutMessageSource.

@Test
public void testLifecycleInEndpointWithoutMessageSource() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
    messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
    assertNotNull(messageChannelsMonitor);
    MBeanServer server = context.getBean(MBeanServer.class);
    Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
    assertEquals(1, names.size());
    names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=gateway,*"), null);
    assertEquals(1, names.size());
    MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
    String startName = null;
    for (MBeanOperationInfo info : operations) {
        String name = info.getName();
        if (name.startsWith("start")) {
            startName = name;
        }
    }
    // Lifecycle method name
    assertEquals("start", startName);
    context.close();
    context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
    server = context.getBean(MBeanServer.class);
    names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
    assertEquals(1, names.size());
    names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=gateway,*"), null);
    assertEquals(1, names.size());
}
Also used : MBeanOperationInfo(javax.management.MBeanOperationInfo) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 45 with GenericXmlApplicationContext

use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration by spring-projects.

the class MBeanExporterIntegrationTests method testLifecycleInEndpointWithMessageSource.

@Test
public void testLifecycleInEndpointWithMessageSource() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "lifecycle-source.xml");
    messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
    assertNotNull(messageChannelsMonitor);
    MBeanServer server = context.getBean(MBeanServer.class);
    Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
    assertEquals(2, names.size());
    names = server.queryNames(ObjectName.getInstance("org.springframework.integration:name=explicit,*"), null);
    assertEquals(1, names.size());
    MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
    String startName = null;
    for (MBeanOperationInfo info : operations) {
        String name = info.getName();
        if (name.startsWith("start")) {
            startName = name;
        }
    }
    // Lifecycle method name
    assertEquals("start", startName);
    assertTrue((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
    messageChannelsMonitor.stopActiveComponents(3000);
    assertFalse((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
    ActiveChannel activeChannel = context.getBean("activeChannel", ActiveChannel.class);
    assertTrue(activeChannel.isStopCalled());
    OtherActiveComponent otherActiveComponent = context.getBean(OtherActiveComponent.class);
    assertTrue(otherActiveComponent.isBeforeCalled());
    assertTrue(otherActiveComponent.isAfterCalled());
    assertTrue(otherActiveComponent.isRunning());
    assertFalse(context.getBean(AMessageProducer.class).isRunning());
    // check pollers are still running
    QueueChannel input = (QueueChannel) extractTarget(context.getBean("input"));
    QueueChannel input2 = (QueueChannel) extractTarget(context.getBean("input2"));
    input.purge(null);
    input2.purge(null);
    input.send(new GenericMessage<String>("foo"));
    assertNotNull(input2.receive(10000));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MBeanOperationInfo(javax.management.MBeanOperationInfo) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)61 Test (org.junit.Test)21 Test (org.junit.jupiter.api.Test)13 MBeanServer (javax.management.MBeanServer)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 Scanner (java.util.Scanner)4 ObjectName (javax.management.ObjectName)4 Resource (org.springframework.core.io.Resource)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 MessageChannel (org.springframework.messaging.MessageChannel)4 ApplicationContext (org.springframework.context.ApplicationContext)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 Message (org.springframework.messaging.Message)3 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 Server (org.eclipse.jetty.server.Server)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 BatchStatus (org.springframework.batch.core.BatchStatus)2 BeanDefinitionParsingException (org.springframework.beans.factory.parsing.BeanDefinitionParsingException)2 CacheInterceptor (org.springframework.cache.interceptor.CacheInterceptor)2