Search in sources :

Example 1 with FileBroker

use of org.apache.activemq.artemis.integration.FileBroker in project activemq-artemis by apache.

the class FileBrokerTest method startTwoBrokersWithSameDataDir.

@Test
public void startTwoBrokersWithSameDataDir() throws Exception {
    ServerDTO serverDTO1 = new ServerDTO();
    ServerDTO serverDTO2 = new ServerDTO();
    serverDTO1.configuration = "FileBrokerTest-broker1.xml";
    serverDTO2.configuration = "FileBrokerTest-broker2.xml";
    FileBroker broker1 = new FileBroker(serverDTO1, new ActiveMQJAASSecurityManager());
    FileBroker broker2 = new FileBroker(serverDTO2, new ActiveMQJAASSecurityManager());
    try {
        broker1.start();
        Assert.assertTrue(broker1.isStarted());
        Thread thread = new Thread(() -> {
            try {
                broker2.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        thread.start();
        Assert.assertFalse(broker2.isStarted());
        // only if broker1 is stopped can broker2 be fully started
        broker1.stop();
        broker1 = null;
        thread.join(5000);
        Assert.assertTrue(broker2.isStarted());
        broker2.stop();
    } finally {
        if (broker1 != null) {
            broker1.stop();
        }
        if (broker2 != null) {
            broker2.stop();
        }
    }
}
Also used : FileBroker(org.apache.activemq.artemis.integration.FileBroker) ServerDTO(org.apache.activemq.artemis.dto.ServerDTO) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with FileBroker

use of org.apache.activemq.artemis.integration.FileBroker in project activemq-artemis by apache.

the class FileBrokerTest method startWithoutJMS.

@Test
public void startWithoutJMS() throws Exception {
    ServerDTO serverDTO = new ServerDTO();
    serverDTO.configuration = "broker-nojms.xml";
    FileBroker broker = null;
    try {
        broker = new FileBroker(serverDTO, new ActiveMQJAASSecurityManager());
        broker.start();
        JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms");
        Assert.assertNull(jmsServerManager);
        ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core");
        Assert.assertNotNull(activeMQServer);
        Assert.assertTrue(activeMQServer.isStarted());
        Assert.assertTrue(broker.isStarted());
    } finally {
        assert broker != null;
        broker.stop();
    }
}
Also used : FileBroker(org.apache.activemq.artemis.integration.FileBroker) ServerDTO(org.apache.activemq.artemis.dto.ServerDTO) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) Test(org.junit.Test)

Example 3 with FileBroker

use of org.apache.activemq.artemis.integration.FileBroker in project activemq-artemis by apache.

the class FileBrokerTest method testConfigFileReload.

@Test
public void testConfigFileReload() throws Exception {
    ServerDTO serverDTO = new ServerDTO();
    serverDTO.configuration = "broker-reload.xml";
    FileBroker broker = null;
    String path = null;
    try {
        SecurityConfiguration securityConfiguration = new SecurityConfiguration();
        securityConfiguration.addUser("myUser", "myPass");
        securityConfiguration.addRole("myUser", "guest");
        ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
        broker = new FileBroker(serverDTO, securityManager);
        broker.start();
        ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core");
        Assert.assertNotNull(activeMQServer);
        Assert.assertTrue(activeMQServer.isStarted());
        Assert.assertTrue(broker.isStarted());
        File file = new File(activeMQServer.getConfiguration().getConfigurationUrl().toURI());
        path = file.getPath();
        Assert.assertNotNull(activeMQServer.getConfiguration().getConfigurationUrl());
        Thread.sleep(activeMQServer.getConfiguration().getConfigurationFileRefreshPeriod() * 2);
        ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616");
        ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession("myUser", "myPass", false, true, false, false, 0);
        ClientProducer producer = session.createProducer("DLQ");
        producer.send(session.createMessage(true));
        replacePatternInFile(path, "guest", "X");
        Thread.sleep(activeMQServer.getConfiguration().getConfigurationFileRefreshPeriod() * 2);
        try {
            producer.send(session.createMessage(true));
            fail("Should throw a security exception");
        } catch (Exception e) {
        }
        locator.close();
    } finally {
        assert broker != null;
        broker.stop();
        if (path != null) {
            replacePatternInFile(path, "X", "guest");
        }
    }
}
Also used : FileBroker(org.apache.activemq.artemis.integration.FileBroker) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) IOException(java.io.IOException) ServerDTO(org.apache.activemq.artemis.dto.ServerDTO) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) File(java.io.File) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

ServerDTO (org.apache.activemq.artemis.dto.ServerDTO)3 FileBroker (org.apache.activemq.artemis.integration.FileBroker)3 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)2 File (java.io.File)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 SecurityConfiguration (org.apache.activemq.artemis.core.config.impl.SecurityConfiguration)1 JMSServerManagerImpl (org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl)1 InVMLoginModule (org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule)1