Skip to content

Commit

Permalink
ARTEMIS-3627 - allow default classpath properties name to be configur…
Browse files Browse the repository at this point in the history
…ed and use non intrusive property for testing, root cause of falure in test identified by ARTEMIS-3652
  • Loading branch information
gtully committed Jan 24, 2022
1 parent 3af6d0d commit c05177d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class EmbeddedActiveMQ {
protected Configuration configuration;
protected ActiveMQServer activeMQServer;
protected MBeanServer mbeanServer;
protected String propertiesResourcePath = ActiveMQDefaultConfiguration.BROKER_PROPERTIES_SYSTEM_PROPERTY_NAME;

/**
* Classpath resource for activemq server config. Defaults to 'broker.xml'.
Expand All @@ -53,6 +54,16 @@ public EmbeddedActiveMQ setConfigResourcePath(String filename) {
return this;
}

/**
* Classpath resource for broker properties file. Defaults to 'broker.properties'.
*
* @param filename
*/
public EmbeddedActiveMQ setPropertiesResourcePath(String filename) {
propertiesResourcePath = filename;
return this;
}

/**
* Set the activemq security manager. This defaults to org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManagerImpl
*
Expand Down Expand Up @@ -144,9 +155,11 @@ protected void initStart() throws Exception {
activeMQServer = new ActiveMQServerImpl(configuration, mbeanServer, securityManager);
}

URL brokerPropertiesFromClasspath = this.getClass().getClassLoader().getResource(ActiveMQDefaultConfiguration.BROKER_PROPERTIES_SYSTEM_PROPERTY_NAME);
if (brokerPropertiesFromClasspath != null) {
activeMQServer.setProperties(new File(brokerPropertiesFromClasspath.toURI()).getAbsolutePath());
if (propertiesResourcePath != null) {
URL brokerPropertiesFromClasspath = this.getClass().getClassLoader().getResource(propertiesResourcePath);
if (brokerPropertiesFromClasspath != null) {
activeMQServer.setProperties(new File(brokerPropertiesFromClasspath.toURI()).getAbsolutePath());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testConfigViaBrokerPropertiesSystemProperty() throws Exception {

try (PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(propertiesInBindingsDir)))) {
// use the same name property as from the classpath broker.properties to verify precedence of system prop
out.println("name=nameFromCopiedPropertiesRefViaSystemProp");
out.println("gracefulShutdownTimeout=-3");
}

System.setProperty(ActiveMQDefaultConfiguration.BROKER_PROPERTIES_SYSTEM_PROPERTY_NAME, propertiesInBindingsDir.getAbsolutePath());
Expand All @@ -54,7 +54,7 @@ public void testConfigViaBrokerPropertiesSystemProperty() throws Exception {
server.setConfiguration(configuration);
server.start();

assertEquals("nameFromCopiedPropertiesRefViaSystemProp", server.getActiveMQServer().getConfiguration().getName());
assertEquals(-3, server.getActiveMQServer().getConfiguration().getGracefulShutdownTimeout());

} finally {
System.getProperties().remove(ActiveMQDefaultConfiguration.BROKER_PROPERTIES_SYSTEM_PROPERTY_NAME);
Expand All @@ -78,7 +78,31 @@ public void testConfigViaBrokerPropertiesFromClasspath() throws Exception {
server.setConfiguration(configuration);
server.start();

assertEquals("ConfiguredViaProperties", server.getActiveMQServer().getConfiguration().getName());
assertEquals(-2, server.getActiveMQServer().getConfiguration().getGracefulShutdownTimeout());

} finally {
server.stop();
}
}

@Test
public void testIgnoreConfigViaBrokerPropertiesFromClasspath() throws Exception {

EmbeddedActiveMQ server = new EmbeddedActiveMQ();
ConfigurationImpl configuration = new ConfigurationImpl();

configuration.setJournalDirectory(new File(getTestDir(), "./journal").getAbsolutePath()).
setPagingDirectory(new File(getTestDir(), "./paging").getAbsolutePath()).
setLargeMessagesDirectory(new File(getTestDir(), "./largemessages").getAbsolutePath()).
setBindingsDirectory(new File(getTestDir(), "./bindings").getAbsolutePath()).setPersistenceEnabled(true);

try {

server.setPropertiesResourcePath(null);
server.setConfiguration(configuration);
server.start();

assertEquals(ActiveMQDefaultConfiguration.getDefaultGracefulShutdownTimeout(), server.getActiveMQServer().getConfiguration().getGracefulShutdownTimeout());

} finally {
server.stop();
Expand Down
4 changes: 3 additions & 1 deletion tests/integration-tests/src/test/resources/broker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# limitations under the License.
#

name=ConfiguredViaProperties
# use a very innocuous bit of config b/c it will be picked up by all embedded servers in the integration tests
# this is semantically the same as the default value
gracefulShutdownTimeout=-2

0 comments on commit c05177d

Please sign in to comment.