ARTEMIS-3627 - allow default classpath properties name to be configured and use non intrusive property for testing, root cause of falure in test identified by ARTEMIS-3652

This commit is contained in:
gtully 2022-01-24 11:53:21 +00:00 committed by Gary Tully
parent 3af6d0d58c
commit c05177d723
3 changed files with 46 additions and 7 deletions

View File

@ -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'.
@ -53,6 +54,16 @@ public class EmbeddedActiveMQ {
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
*
@ -144,9 +155,11 @@ public class EmbeddedActiveMQ {
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());
}
}
}

View File

@ -45,7 +45,7 @@ public class JMSServerPropertyConfigTest extends ActiveMQTestBase {
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());
@ -54,7 +54,7 @@ public class JMSServerPropertyConfigTest extends ActiveMQTestBase {
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);
@ -78,7 +78,31 @@ public class JMSServerPropertyConfigTest extends ActiveMQTestBase {
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();

View File

@ -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