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();
}
}
}
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();
}
}
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");
}
}
}
Aggregations