From 98e1389a6e9803554186e0b44cb0be58b9cff276 Mon Sep 17 00:00:00 2001 From: Robbie Gemmell Date: Tue, 21 May 2024 16:15:12 +0100 Subject: [PATCH] ARTEMIS-4778: clean up configuration test heirarchy, remove hundreds of duplicate tests, isolate parameterized tests --- .../impl/AbstractConfigurationTestBase.java | 490 ++++++++++++++++++ .../config/impl/ConfigurationImplTest.java | 473 +---------------- .../impl/DefaultsFileConfigurationTest.java | 24 +- ...gurationBrokerConnectionEncryptedTest.java | 36 +- .../FileConfigurationDbEncryptedPassTest.java | 39 +- .../FileConfigurationSecurityPluginTest.java | 41 +- .../config/impl/FileConfigurationTest.java | 41 +- .../impl/FileXIncludeConfigurationTest.java | 10 +- .../FileXIncludeSchemaConfigurationTest.java | 16 +- 9 files changed, 636 insertions(+), 534 deletions(-) create mode 100644 artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/AbstractConfigurationTestBase.java diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/AbstractConfigurationTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/AbstractConfigurationTestBase.java new file mode 100644 index 0000000000..01babe492c --- /dev/null +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/AbstractConfigurationTestBase.java @@ -0,0 +1,490 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.core.config.impl; + +import java.util.Properties; + +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.core.config.Configuration; +import org.apache.activemq.artemis.core.config.ha.PrimaryOnlyPolicyConfiguration; +import org.apache.activemq.artemis.core.config.routing.ConnectionRouterConfiguration; +import org.apache.activemq.artemis.core.server.JournalType; +import org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin; +import org.apache.activemq.artemis.core.server.routing.KeyType; +import org.apache.activemq.artemis.core.server.routing.policies.ConsistentHashModuloPolicy; +import org.apache.activemq.artemis.core.server.routing.policies.ConsistentHashPolicy; +import org.apache.activemq.artemis.tests.util.ServerTestBase; +import org.apache.activemq.artemis.utils.RandomUtil; +import org.junit.Before; + +public abstract class AbstractConfigurationTestBase extends ServerTestBase { + + protected Configuration conf; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + + conf = createConfiguration(); + } + + protected abstract Configuration createConfiguration() throws Exception; + + // Utility method, not itself a test; call it from actual test method + public static void doSetGetAttributesTestImpl(Configuration configuration) throws Exception { + for (int j = 0; j < 100; j++) { + int i = RandomUtil.randomInt(); + configuration.setScheduledThreadPoolMaxSize(i); + assertEquals(i, configuration.getScheduledThreadPoolMaxSize()); + + long l = RandomUtil.randomLong(); + configuration.setSecurityInvalidationInterval(l); + assertEquals(l, configuration.getSecurityInvalidationInterval()); + + boolean b = RandomUtil.randomBoolean(); + configuration.setSecurityEnabled(b); + assertEquals(b, configuration.isSecurityEnabled()); + + String s = RandomUtil.randomString(); + configuration.setBindingsDirectory(s); + assertEquals(s, configuration.getBindingsDirectory()); + + b = RandomUtil.randomBoolean(); + configuration.setCreateBindingsDir(b); + assertEquals(b, configuration.isCreateBindingsDir()); + + s = RandomUtil.randomString(); + configuration.setJournalDirectory(s); + assertEquals(s, configuration.getJournalDirectory()); + + b = RandomUtil.randomBoolean(); + configuration.setCreateJournalDir(b); + assertEquals(b, configuration.isCreateJournalDir()); + + i = RandomUtil.randomInt() % 2; + JournalType journal = i == 0 ? JournalType.ASYNCIO : JournalType.NIO; + configuration.setJournalType(journal); + assertEquals(journal, configuration.getJournalType()); + + b = RandomUtil.randomBoolean(); + configuration.setJournalSyncTransactional(b); + assertEquals(b, configuration.isJournalSyncTransactional()); + + b = RandomUtil.randomBoolean(); + configuration.setJournalSyncNonTransactional(b); + assertEquals(b, configuration.isJournalSyncNonTransactional()); + + i = RandomUtil.randomInt(); + configuration.setJournalFileSize(i); + assertEquals(i, configuration.getJournalFileSize()); + + i = RandomUtil.randomInt(); + configuration.setJournalMinFiles(i); + assertEquals(i, configuration.getJournalMinFiles()); + + i = RandomUtil.randomInt(); + configuration.setJournalMaxIO_AIO(i); + assertEquals(i, configuration.getJournalMaxIO_AIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalMaxIO_NIO(i); + assertEquals(i, configuration.getJournalMaxIO_NIO()); + + s = RandomUtil.randomString(); + configuration.setManagementAddress(new SimpleString(s)); + assertEquals(s, configuration.getManagementAddress().toString()); + + l = RandomUtil.randomLong(); + configuration.setMessageExpiryScanPeriod(l); + assertEquals(l, configuration.getMessageExpiryScanPeriod()); + + b = RandomUtil.randomBoolean(); + configuration.setPersistDeliveryCountBeforeDelivery(b); + assertEquals(b, configuration.isPersistDeliveryCountBeforeDelivery()); + + b = RandomUtil.randomBoolean(); + configuration.setEnabledAsyncConnectionExecution(b); + assertEquals(b, configuration.isAsyncConnectionExecutionEnabled()); + + b = RandomUtil.randomBoolean(); + configuration.setPersistenceEnabled(b); + assertEquals(b, configuration.isPersistenceEnabled()); + + b = RandomUtil.randomBoolean(); + configuration.setJMXManagementEnabled(b); + assertEquals(b, configuration.isJMXManagementEnabled()); + + l = RandomUtil.randomLong(); + configuration.setFileDeployerScanPeriod(l); + assertEquals(l, configuration.getFileDeployerScanPeriod()); + + l = RandomUtil.randomLong(); + configuration.setConnectionTTLOverride(l); + assertEquals(l, configuration.getConnectionTTLOverride()); + + i = RandomUtil.randomInt(); + configuration.setThreadPoolMaxSize(i); + assertEquals(i, configuration.getThreadPoolMaxSize()); + + SimpleString ss = RandomUtil.randomSimpleString(); + configuration.setManagementNotificationAddress(ss); + assertEquals(ss, configuration.getManagementNotificationAddress()); + + s = RandomUtil.randomString(); + configuration.setClusterUser(s); + assertEquals(s, configuration.getClusterUser()); + + i = RandomUtil.randomInt(); + configuration.setIDCacheSize(i); + assertEquals(i, configuration.getIDCacheSize()); + + b = RandomUtil.randomBoolean(); + configuration.setPersistIDCache(b); + assertEquals(b, configuration.isPersistIDCache()); + + i = RandomUtil.randomInt(); + configuration.setJournalCompactMinFiles(i); + assertEquals(i, configuration.getJournalCompactMinFiles()); + + i = RandomUtil.randomInt(); + configuration.setJournalCompactPercentage(i); + assertEquals(i, configuration.getJournalCompactPercentage()); + + l = RandomUtil.randomLong(); + configuration.setJournalLockAcquisitionTimeout(l); + assertEquals(l, configuration.getJournalLockAcquisitionTimeout()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferSize_AIO(i); + assertEquals(i, configuration.getJournalBufferSize_AIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferTimeout_AIO(i); + assertEquals(i, configuration.getJournalBufferTimeout_AIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferSize_NIO(i); + assertEquals(i, configuration.getJournalBufferSize_NIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferTimeout_NIO(i); + assertEquals(i, configuration.getJournalBufferTimeout_NIO()); + + b = RandomUtil.randomBoolean(); + configuration.setLogJournalWriteRate(b); + assertEquals(b, configuration.isLogJournalWriteRate()); + + l = RandomUtil.randomLong(); + configuration.setServerDumpInterval(l); + assertEquals(l, configuration.getServerDumpInterval()); + + s = RandomUtil.randomString(); + configuration.setPagingDirectory(s); + assertEquals(s, configuration.getPagingDirectory()); + + s = RandomUtil.randomString(); + configuration.setLargeMessagesDirectory(s); + assertEquals(s, configuration.getLargeMessagesDirectory()); + + l = RandomUtil.randomLong(); + configuration.setTransactionTimeout(l); + assertEquals(l, configuration.getTransactionTimeout()); + + b = RandomUtil.randomBoolean(); + configuration.setMessageCounterEnabled(b); + assertEquals(b, configuration.isMessageCounterEnabled()); + + l = RandomUtil.randomPositiveLong(); + configuration.setMessageCounterSamplePeriod(l); + assertEquals(l, configuration.getMessageCounterSamplePeriod()); + + i = RandomUtil.randomInt(); + configuration.setMessageCounterMaxDayHistory(i); + assertEquals(i, configuration.getMessageCounterMaxDayHistory()); + + l = RandomUtil.randomLong(); + configuration.setTransactionTimeoutScanPeriod(l); + assertEquals(l, configuration.getTransactionTimeoutScanPeriod()); + + s = RandomUtil.randomString(); + configuration.setClusterPassword(s); + assertEquals(s, configuration.getClusterPassword()); + + i = RandomUtil.randomInt(); + configuration.setPageSyncTimeout(i); + assertEquals(i, configuration.getPageSyncTimeout()); + } + } + + // Utility method, not itself a test; call it from actual test method + public static void doGetSetInterceptorsTestImpl(Configuration configuration) { + final String name1 = "uqwyuqywuy"; + final String name2 = "yugyugyguyg"; + + configuration.getIncomingInterceptorClassNames().add(name1); + configuration.getIncomingInterceptorClassNames().add(name2); + + assertTrue(configuration.getIncomingInterceptorClassNames().contains(name1)); + assertTrue(configuration.getIncomingInterceptorClassNames().contains(name2)); + assertFalse(configuration.getIncomingInterceptorClassNames().contains("iijij")); + } + + // Utility method, not itself a test; call it from actual test method + public static void doSerializeTestImpl(Configuration configuration) throws Exception { + boolean b = RandomUtil.randomBoolean(); + + configuration.setHAPolicyConfiguration(new PrimaryOnlyPolicyConfiguration()); + + int i = RandomUtil.randomInt(); + configuration.setScheduledThreadPoolMaxSize(i); + assertEquals(i, configuration.getScheduledThreadPoolMaxSize()); + + long l = RandomUtil.randomLong(); + configuration.setSecurityInvalidationInterval(l); + assertEquals(l, configuration.getSecurityInvalidationInterval()); + + b = RandomUtil.randomBoolean(); + configuration.setSecurityEnabled(b); + assertEquals(b, configuration.isSecurityEnabled()); + + String s = RandomUtil.randomString(); + configuration.setBindingsDirectory(s); + assertEquals(s, configuration.getBindingsDirectory()); + + b = RandomUtil.randomBoolean(); + configuration.setCreateBindingsDir(b); + assertEquals(b, configuration.isCreateBindingsDir()); + + s = RandomUtil.randomString(); + configuration.setJournalDirectory(s); + assertEquals(s, configuration.getJournalDirectory()); + + b = RandomUtil.randomBoolean(); + configuration.setCreateJournalDir(b); + assertEquals(b, configuration.isCreateJournalDir()); + + i = RandomUtil.randomInt() % 2; + JournalType journal = i == 0 ? JournalType.ASYNCIO : JournalType.NIO; + configuration.setJournalType(journal); + assertEquals(journal, configuration.getJournalType()); + + b = RandomUtil.randomBoolean(); + configuration.setJournalSyncTransactional(b); + assertEquals(b, configuration.isJournalSyncTransactional()); + + b = RandomUtil.randomBoolean(); + configuration.setJournalSyncNonTransactional(b); + assertEquals(b, configuration.isJournalSyncNonTransactional()); + + i = RandomUtil.randomInt(); + configuration.setJournalFileSize(i); + assertEquals(i, configuration.getJournalFileSize()); + + i = RandomUtil.randomInt(); + configuration.setJournalMinFiles(i); + assertEquals(i, configuration.getJournalMinFiles()); + + i = RandomUtil.randomInt(); + configuration.setJournalMaxIO_AIO(i); + assertEquals(i, configuration.getJournalMaxIO_AIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalMaxIO_NIO(i); + assertEquals(i, configuration.getJournalMaxIO_NIO()); + + s = RandomUtil.randomString(); + configuration.setManagementAddress(new SimpleString(s)); + assertEquals(s, configuration.getManagementAddress().toString()); + + l = RandomUtil.randomLong(); + configuration.setMessageExpiryScanPeriod(l); + assertEquals(l, configuration.getMessageExpiryScanPeriod()); + + b = RandomUtil.randomBoolean(); + configuration.setPersistDeliveryCountBeforeDelivery(b); + assertEquals(b, configuration.isPersistDeliveryCountBeforeDelivery()); + + b = RandomUtil.randomBoolean(); + configuration.setEnabledAsyncConnectionExecution(b); + assertEquals(b, configuration.isAsyncConnectionExecutionEnabled()); + + b = RandomUtil.randomBoolean(); + configuration.setPersistenceEnabled(b); + assertEquals(b, configuration.isPersistenceEnabled()); + + b = RandomUtil.randomBoolean(); + configuration.setJMXManagementEnabled(b); + assertEquals(b, configuration.isJMXManagementEnabled()); + + l = RandomUtil.randomLong(); + configuration.setFileDeployerScanPeriod(l); + assertEquals(l, configuration.getFileDeployerScanPeriod()); + + l = RandomUtil.randomLong(); + configuration.setConnectionTTLOverride(l); + assertEquals(l, configuration.getConnectionTTLOverride()); + + i = RandomUtil.randomInt(); + configuration.setThreadPoolMaxSize(i); + assertEquals(i, configuration.getThreadPoolMaxSize()); + + SimpleString ss = RandomUtil.randomSimpleString(); + configuration.setManagementNotificationAddress(ss); + assertEquals(ss, configuration.getManagementNotificationAddress()); + + s = RandomUtil.randomString(); + configuration.setClusterUser(s); + assertEquals(s, configuration.getClusterUser()); + + i = RandomUtil.randomInt(); + configuration.setIDCacheSize(i); + assertEquals(i, configuration.getIDCacheSize()); + + b = RandomUtil.randomBoolean(); + configuration.setPersistIDCache(b); + assertEquals(b, configuration.isPersistIDCache()); + + i = RandomUtil.randomInt(); + configuration.setJournalCompactMinFiles(i); + assertEquals(i, configuration.getJournalCompactMinFiles()); + + i = RandomUtil.randomInt(); + configuration.setJournalCompactPercentage(i); + assertEquals(i, configuration.getJournalCompactPercentage()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferSize_AIO(i); + assertEquals(i, configuration.getJournalBufferSize_AIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferTimeout_AIO(i); + assertEquals(i, configuration.getJournalBufferTimeout_AIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferSize_NIO(i); + assertEquals(i, configuration.getJournalBufferSize_NIO()); + + i = RandomUtil.randomInt(); + configuration.setJournalBufferTimeout_NIO(i); + assertEquals(i, configuration.getJournalBufferTimeout_NIO()); + + b = RandomUtil.randomBoolean(); + configuration.setLogJournalWriteRate(b); + assertEquals(b, configuration.isLogJournalWriteRate()); + + l = RandomUtil.randomLong(); + configuration.setServerDumpInterval(l); + assertEquals(l, configuration.getServerDumpInterval()); + + s = RandomUtil.randomString(); + configuration.setPagingDirectory(s); + assertEquals(s, configuration.getPagingDirectory()); + + s = RandomUtil.randomString(); + configuration.setLargeMessagesDirectory(s); + assertEquals(s, configuration.getLargeMessagesDirectory()); + + b = RandomUtil.randomBoolean(); + configuration.setWildcardRoutingEnabled(b); + assertEquals(b, configuration.isWildcardRoutingEnabled()); + + l = RandomUtil.randomLong(); + configuration.setTransactionTimeout(l); + assertEquals(l, configuration.getTransactionTimeout()); + + b = RandomUtil.randomBoolean(); + configuration.setMessageCounterEnabled(b); + assertEquals(b, configuration.isMessageCounterEnabled()); + + l = RandomUtil.randomPositiveLong(); + configuration.setMessageCounterSamplePeriod(l); + assertEquals(l, configuration.getMessageCounterSamplePeriod()); + + i = RandomUtil.randomInt(); + configuration.setMessageCounterMaxDayHistory(i); + assertEquals(i, configuration.getMessageCounterMaxDayHistory()); + + l = RandomUtil.randomLong(); + configuration.setTransactionTimeoutScanPeriod(l); + assertEquals(l, configuration.getTransactionTimeoutScanPeriod()); + + s = RandomUtil.randomString(); + configuration.setClusterPassword(s); + assertEquals(s, configuration.getClusterPassword()); + + i = RandomUtil.randomInt(); + configuration.setPageSyncTimeout(i); + assertEquals(i, configuration.getPageSyncTimeout()); + + configuration.registerBrokerPlugin(new LoggingActiveMQServerPlugin()); + assertEquals("ensure one plugin registered", 1, configuration.getBrokerPlugins().size()); + assertEquals("ensure one connection plugin registered", 1, configuration.getBrokerConnectionPlugins().size()); + + + // This will use serialization to perform a deep copy of the object + Configuration conf2 = configuration.copy(); + + assertTrue(configuration.equals(conf2)); + } + + // Utility method, not itself a test; call it from actual test method + public static void doSetConnectionRoutersPolicyConfigurationTestImpl(ConfigurationImpl configuration) throws Throwable { + Properties insertionOrderedProperties = new ConfigurationImpl.InsertionOrderedProperties(); + insertionOrderedProperties.put("connectionRouters.autoShard.localTargetFilter", "NULL|$STATEFUL_SET_ORDINAL"); + insertionOrderedProperties.put("connectionRouters.autoShard.keyType", KeyType.CLIENT_ID); + insertionOrderedProperties.put("connectionRouters.autoShard.policyConfiguration", ConsistentHashModuloPolicy.NAME); + insertionOrderedProperties.put("connectionRouters.autoShard.policyConfiguration.properties." + ConsistentHashModuloPolicy.MODULO, 2); + + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.keyType", KeyType.CLIENT_ID); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.keyFilter", "^.{3}"); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.policyConfiguration", ConsistentHashPolicy.NAME); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.username", "guest-username"); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.password", "guest-password"); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.quorumSize", "2"); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.localTargetEnabled", Boolean.TRUE.toString()); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.discoveryGroupName", "discovery-group-1"); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.cacheConfiguration.persisted", Boolean.TRUE.toString()); + insertionOrderedProperties.put("connectionRouters.symmetricRedirect.cacheConfiguration.timeout", "1234"); + + configuration.parsePrefixedProperties(insertionOrderedProperties, null); + + assertEquals(2, configuration.getConnectionRouters().size()); + + ConnectionRouterConfiguration autoShardConfig = configuration.getConnectionRouters().stream().filter( + connectionRouterConfig -> "autoShard".equals(connectionRouterConfig.getName())).findFirst().get(); + assertEquals(KeyType.CLIENT_ID, autoShardConfig.getKeyType()); + assertEquals("2", autoShardConfig.getPolicyConfiguration().getProperties().get(ConsistentHashModuloPolicy.MODULO)); + assertNull(autoShardConfig.getCacheConfiguration()); + assertNull(autoShardConfig.getPoolConfiguration()); + + ConnectionRouterConfiguration symmetricRedirectConfig = configuration.getConnectionRouters().stream().filter( + connectionRouterConfig -> "symmetricRedirect".equals(connectionRouterConfig.getName())).findFirst().get(); + assertEquals(KeyType.CLIENT_ID, symmetricRedirectConfig.getKeyType()); + assertEquals("^.{3}", symmetricRedirectConfig.getKeyFilter()); + assertEquals(ConsistentHashPolicy.NAME, symmetricRedirectConfig.getPolicyConfiguration().getName()); + assertNotNull(symmetricRedirectConfig.getPoolConfiguration()); + assertEquals("guest-username", symmetricRedirectConfig.getPoolConfiguration().getUsername()); + assertEquals("guest-password", symmetricRedirectConfig.getPoolConfiguration().getPassword()); + assertEquals(2, symmetricRedirectConfig.getPoolConfiguration().getQuorumSize()); + assertEquals(Boolean.TRUE, symmetricRedirectConfig.getPoolConfiguration().isLocalTargetEnabled()); + assertEquals("discovery-group-1", symmetricRedirectConfig.getPoolConfiguration().getDiscoveryGroupName()); + assertNotNull(symmetricRedirectConfig.getCacheConfiguration()); + assertEquals(Boolean.TRUE, symmetricRedirectConfig.getCacheConfiguration().isPersisted()); + assertEquals(1234, symmetricRedirectConfig.getCacheConfiguration().getTimeout()); + } +} diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java index 8280afacae..b061c71d62 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java @@ -58,14 +58,12 @@ import org.apache.activemq.artemis.core.config.federation.FederationPolicySet; import org.apache.activemq.artemis.core.config.federation.FederationQueuePolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.ColocatedPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.LiveOnlyPolicyConfiguration; -import org.apache.activemq.artemis.core.config.ha.PrimaryOnlyPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.ReplicationBackupPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.ReplicationPrimaryPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.SharedStoreBackupPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.SharedStorePrimaryPolicyConfiguration; -import org.apache.activemq.artemis.core.config.routing.ConnectionRouterConfiguration; import org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration; import org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser; import org.apache.activemq.artemis.core.io.SequentialFileFactory; @@ -76,20 +74,16 @@ import org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl; import org.apache.activemq.artemis.core.persistence.StorageManager; import org.apache.activemq.artemis.core.security.Role; import org.apache.activemq.artemis.core.server.ComponentConfigurationRoutingType; -import org.apache.activemq.artemis.core.server.JournalType; import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType; import org.apache.activemq.artemis.core.server.impl.LegacyLDAPSecuritySettingPlugin; import org.apache.activemq.artemis.core.server.plugin.impl.ConnectionPeriodicExpiryPlugin; import org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin; import org.apache.activemq.artemis.core.server.routing.KeyType; -import org.apache.activemq.artemis.core.server.routing.policies.ConsistentHashModuloPolicy; -import org.apache.activemq.artemis.core.server.routing.policies.ConsistentHashPolicy; import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy; import org.apache.activemq.artemis.core.settings.impl.DeletionPolicy; import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings; import org.apache.activemq.artemis.logs.AssertionLoggerHandler; import org.apache.activemq.artemis.core.settings.impl.SlowConsumerThresholdMeasurementUnit; -import org.apache.activemq.artemis.tests.util.ServerTestBase; import org.apache.activemq.artemis.utils.RandomUtil; import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy; import org.apache.commons.lang3.ClassUtils; @@ -99,14 +93,16 @@ import org.slf4j.LoggerFactory; import java.lang.invoke.MethodHandles; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -public class ConfigurationImplTest extends ServerTestBase { +public class ConfigurationImplTest extends AbstractConfigurationTestBase { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - protected Configuration conf; + @Override + protected Configuration createConfiguration() throws Exception { + return new ConfigurationImpl(); + } @Test public void testDefaults() { @@ -173,399 +169,22 @@ public class ConfigurationImplTest extends ServerTestBase { @Test public void testSetGetAttributes() throws Exception { - for (int j = 0; j < 100; j++) { - int i = RandomUtil.randomInt(); - conf.setScheduledThreadPoolMaxSize(i); - Assert.assertEquals(i, conf.getScheduledThreadPoolMaxSize()); - - long l = RandomUtil.randomLong(); - conf.setSecurityInvalidationInterval(l); - Assert.assertEquals(l, conf.getSecurityInvalidationInterval()); - - boolean b = RandomUtil.randomBoolean(); - conf.setSecurityEnabled(b); - Assert.assertEquals(b, conf.isSecurityEnabled()); - - String s = RandomUtil.randomString(); - conf.setBindingsDirectory(s); - Assert.assertEquals(s, conf.getBindingsDirectory()); - - b = RandomUtil.randomBoolean(); - conf.setCreateBindingsDir(b); - Assert.assertEquals(b, conf.isCreateBindingsDir()); - - s = RandomUtil.randomString(); - conf.setJournalDirectory(s); - Assert.assertEquals(s, conf.getJournalDirectory()); - - b = RandomUtil.randomBoolean(); - conf.setCreateJournalDir(b); - Assert.assertEquals(b, conf.isCreateJournalDir()); - - i = RandomUtil.randomInt() % 2; - JournalType journal = i == 0 ? JournalType.ASYNCIO : JournalType.NIO; - conf.setJournalType(journal); - Assert.assertEquals(journal, conf.getJournalType()); - - b = RandomUtil.randomBoolean(); - conf.setJournalSyncTransactional(b); - Assert.assertEquals(b, conf.isJournalSyncTransactional()); - - b = RandomUtil.randomBoolean(); - conf.setJournalSyncNonTransactional(b); - Assert.assertEquals(b, conf.isJournalSyncNonTransactional()); - - i = RandomUtil.randomInt(); - conf.setJournalFileSize(i); - Assert.assertEquals(i, conf.getJournalFileSize()); - - i = RandomUtil.randomInt(); - conf.setJournalMinFiles(i); - Assert.assertEquals(i, conf.getJournalMinFiles()); - - i = RandomUtil.randomInt(); - conf.setJournalMaxIO_AIO(i); - Assert.assertEquals(i, conf.getJournalMaxIO_AIO()); - - i = RandomUtil.randomInt(); - conf.setJournalMaxIO_NIO(i); - Assert.assertEquals(i, conf.getJournalMaxIO_NIO()); - - s = RandomUtil.randomString(); - conf.setManagementAddress(new SimpleString(s)); - Assert.assertEquals(s, conf.getManagementAddress().toString()); - - l = RandomUtil.randomLong(); - conf.setMessageExpiryScanPeriod(l); - Assert.assertEquals(l, conf.getMessageExpiryScanPeriod()); - - b = RandomUtil.randomBoolean(); - conf.setPersistDeliveryCountBeforeDelivery(b); - Assert.assertEquals(b, conf.isPersistDeliveryCountBeforeDelivery()); - - b = RandomUtil.randomBoolean(); - conf.setEnabledAsyncConnectionExecution(b); - Assert.assertEquals(b, conf.isAsyncConnectionExecutionEnabled()); - - b = RandomUtil.randomBoolean(); - conf.setPersistenceEnabled(b); - Assert.assertEquals(b, conf.isPersistenceEnabled()); - - b = RandomUtil.randomBoolean(); - conf.setJMXManagementEnabled(b); - Assert.assertEquals(b, conf.isJMXManagementEnabled()); - - l = RandomUtil.randomLong(); - conf.setFileDeployerScanPeriod(l); - Assert.assertEquals(l, conf.getFileDeployerScanPeriod()); - - l = RandomUtil.randomLong(); - conf.setConnectionTTLOverride(l); - Assert.assertEquals(l, conf.getConnectionTTLOverride()); - - i = RandomUtil.randomInt(); - conf.setThreadPoolMaxSize(i); - Assert.assertEquals(i, conf.getThreadPoolMaxSize()); - - SimpleString ss = RandomUtil.randomSimpleString(); - conf.setManagementNotificationAddress(ss); - Assert.assertEquals(ss, conf.getManagementNotificationAddress()); - - s = RandomUtil.randomString(); - conf.setClusterUser(s); - Assert.assertEquals(s, conf.getClusterUser()); - - i = RandomUtil.randomInt(); - conf.setIDCacheSize(i); - Assert.assertEquals(i, conf.getIDCacheSize()); - - b = RandomUtil.randomBoolean(); - conf.setPersistIDCache(b); - Assert.assertEquals(b, conf.isPersistIDCache()); - - i = RandomUtil.randomInt(); - conf.setJournalCompactMinFiles(i); - Assert.assertEquals(i, conf.getJournalCompactMinFiles()); - - i = RandomUtil.randomInt(); - conf.setJournalCompactPercentage(i); - Assert.assertEquals(i, conf.getJournalCompactPercentage()); - - l = RandomUtil.randomLong(); - conf.setJournalLockAcquisitionTimeout(l); - Assert.assertEquals(l, conf.getJournalLockAcquisitionTimeout()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferSize_AIO(i); - Assert.assertEquals(i, conf.getJournalBufferSize_AIO()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferTimeout_AIO(i); - Assert.assertEquals(i, conf.getJournalBufferTimeout_AIO()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferSize_NIO(i); - Assert.assertEquals(i, conf.getJournalBufferSize_NIO()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferTimeout_NIO(i); - Assert.assertEquals(i, conf.getJournalBufferTimeout_NIO()); - - b = RandomUtil.randomBoolean(); - conf.setLogJournalWriteRate(b); - Assert.assertEquals(b, conf.isLogJournalWriteRate()); - - l = RandomUtil.randomLong(); - conf.setServerDumpInterval(l); - Assert.assertEquals(l, conf.getServerDumpInterval()); - - s = RandomUtil.randomString(); - conf.setPagingDirectory(s); - Assert.assertEquals(s, conf.getPagingDirectory()); - - s = RandomUtil.randomString(); - conf.setLargeMessagesDirectory(s); - Assert.assertEquals(s, conf.getLargeMessagesDirectory()); - - l = RandomUtil.randomLong(); - conf.setTransactionTimeout(l); - Assert.assertEquals(l, conf.getTransactionTimeout()); - - b = RandomUtil.randomBoolean(); - conf.setMessageCounterEnabled(b); - Assert.assertEquals(b, conf.isMessageCounterEnabled()); - - l = RandomUtil.randomPositiveLong(); - conf.setMessageCounterSamplePeriod(l); - Assert.assertEquals(l, conf.getMessageCounterSamplePeriod()); - - i = RandomUtil.randomInt(); - conf.setMessageCounterMaxDayHistory(i); - Assert.assertEquals(i, conf.getMessageCounterMaxDayHistory()); - - l = RandomUtil.randomLong(); - conf.setTransactionTimeoutScanPeriod(l); - Assert.assertEquals(l, conf.getTransactionTimeoutScanPeriod()); - - s = RandomUtil.randomString(); - conf.setClusterPassword(s); - Assert.assertEquals(s, conf.getClusterPassword()); - - i = RandomUtil.randomInt(); - conf.setPageSyncTimeout(i); - Assert.assertEquals(i, conf.getPageSyncTimeout()); - } + doSetGetAttributesTestImpl(conf); } @Test public void testGetSetInterceptors() { - final String name1 = "uqwyuqywuy"; - final String name2 = "yugyugyguyg"; - - conf.getIncomingInterceptorClassNames().add(name1); - conf.getIncomingInterceptorClassNames().add(name2); - - Assert.assertTrue(conf.getIncomingInterceptorClassNames().contains(name1)); - Assert.assertTrue(conf.getIncomingInterceptorClassNames().contains(name2)); - Assert.assertFalse(conf.getIncomingInterceptorClassNames().contains("iijij")); + doGetSetInterceptorsTestImpl(conf); } @Test public void testSerialize() throws Exception { - boolean b = RandomUtil.randomBoolean(); + doSerializeTestImpl(conf); + } - conf.setHAPolicyConfiguration(new PrimaryOnlyPolicyConfiguration()); - - int i = RandomUtil.randomInt(); - conf.setScheduledThreadPoolMaxSize(i); - Assert.assertEquals(i, conf.getScheduledThreadPoolMaxSize()); - - long l = RandomUtil.randomLong(); - conf.setSecurityInvalidationInterval(l); - Assert.assertEquals(l, conf.getSecurityInvalidationInterval()); - - b = RandomUtil.randomBoolean(); - conf.setSecurityEnabled(b); - Assert.assertEquals(b, conf.isSecurityEnabled()); - - String s = RandomUtil.randomString(); - conf.setBindingsDirectory(s); - Assert.assertEquals(s, conf.getBindingsDirectory()); - - b = RandomUtil.randomBoolean(); - conf.setCreateBindingsDir(b); - Assert.assertEquals(b, conf.isCreateBindingsDir()); - - s = RandomUtil.randomString(); - conf.setJournalDirectory(s); - Assert.assertEquals(s, conf.getJournalDirectory()); - - b = RandomUtil.randomBoolean(); - conf.setCreateJournalDir(b); - Assert.assertEquals(b, conf.isCreateJournalDir()); - - i = RandomUtil.randomInt() % 2; - JournalType journal = i == 0 ? JournalType.ASYNCIO : JournalType.NIO; - conf.setJournalType(journal); - Assert.assertEquals(journal, conf.getJournalType()); - - b = RandomUtil.randomBoolean(); - conf.setJournalSyncTransactional(b); - Assert.assertEquals(b, conf.isJournalSyncTransactional()); - - b = RandomUtil.randomBoolean(); - conf.setJournalSyncNonTransactional(b); - Assert.assertEquals(b, conf.isJournalSyncNonTransactional()); - - i = RandomUtil.randomInt(); - conf.setJournalFileSize(i); - Assert.assertEquals(i, conf.getJournalFileSize()); - - i = RandomUtil.randomInt(); - conf.setJournalMinFiles(i); - Assert.assertEquals(i, conf.getJournalMinFiles()); - - i = RandomUtil.randomInt(); - conf.setJournalMaxIO_AIO(i); - Assert.assertEquals(i, conf.getJournalMaxIO_AIO()); - - i = RandomUtil.randomInt(); - conf.setJournalMaxIO_NIO(i); - Assert.assertEquals(i, conf.getJournalMaxIO_NIO()); - - s = RandomUtil.randomString(); - conf.setManagementAddress(new SimpleString(s)); - Assert.assertEquals(s, conf.getManagementAddress().toString()); - - l = RandomUtil.randomLong(); - conf.setMessageExpiryScanPeriod(l); - Assert.assertEquals(l, conf.getMessageExpiryScanPeriod()); - - b = RandomUtil.randomBoolean(); - conf.setPersistDeliveryCountBeforeDelivery(b); - Assert.assertEquals(b, conf.isPersistDeliveryCountBeforeDelivery()); - - b = RandomUtil.randomBoolean(); - conf.setEnabledAsyncConnectionExecution(b); - Assert.assertEquals(b, conf.isAsyncConnectionExecutionEnabled()); - - b = RandomUtil.randomBoolean(); - conf.setPersistenceEnabled(b); - Assert.assertEquals(b, conf.isPersistenceEnabled()); - - b = RandomUtil.randomBoolean(); - conf.setJMXManagementEnabled(b); - Assert.assertEquals(b, conf.isJMXManagementEnabled()); - - l = RandomUtil.randomLong(); - conf.setFileDeployerScanPeriod(l); - Assert.assertEquals(l, conf.getFileDeployerScanPeriod()); - - l = RandomUtil.randomLong(); - conf.setConnectionTTLOverride(l); - Assert.assertEquals(l, conf.getConnectionTTLOverride()); - - i = RandomUtil.randomInt(); - conf.setThreadPoolMaxSize(i); - Assert.assertEquals(i, conf.getThreadPoolMaxSize()); - - SimpleString ss = RandomUtil.randomSimpleString(); - conf.setManagementNotificationAddress(ss); - Assert.assertEquals(ss, conf.getManagementNotificationAddress()); - - s = RandomUtil.randomString(); - conf.setClusterUser(s); - Assert.assertEquals(s, conf.getClusterUser()); - - i = RandomUtil.randomInt(); - conf.setIDCacheSize(i); - Assert.assertEquals(i, conf.getIDCacheSize()); - - b = RandomUtil.randomBoolean(); - conf.setPersistIDCache(b); - Assert.assertEquals(b, conf.isPersistIDCache()); - - i = RandomUtil.randomInt(); - conf.setJournalCompactMinFiles(i); - Assert.assertEquals(i, conf.getJournalCompactMinFiles()); - - i = RandomUtil.randomInt(); - conf.setJournalCompactPercentage(i); - Assert.assertEquals(i, conf.getJournalCompactPercentage()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferSize_AIO(i); - Assert.assertEquals(i, conf.getJournalBufferSize_AIO()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferTimeout_AIO(i); - Assert.assertEquals(i, conf.getJournalBufferTimeout_AIO()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferSize_NIO(i); - Assert.assertEquals(i, conf.getJournalBufferSize_NIO()); - - i = RandomUtil.randomInt(); - conf.setJournalBufferTimeout_NIO(i); - Assert.assertEquals(i, conf.getJournalBufferTimeout_NIO()); - - b = RandomUtil.randomBoolean(); - conf.setLogJournalWriteRate(b); - Assert.assertEquals(b, conf.isLogJournalWriteRate()); - - l = RandomUtil.randomLong(); - conf.setServerDumpInterval(l); - Assert.assertEquals(l, conf.getServerDumpInterval()); - - s = RandomUtil.randomString(); - conf.setPagingDirectory(s); - Assert.assertEquals(s, conf.getPagingDirectory()); - - s = RandomUtil.randomString(); - conf.setLargeMessagesDirectory(s); - Assert.assertEquals(s, conf.getLargeMessagesDirectory()); - - b = RandomUtil.randomBoolean(); - conf.setWildcardRoutingEnabled(b); - Assert.assertEquals(b, conf.isWildcardRoutingEnabled()); - - l = RandomUtil.randomLong(); - conf.setTransactionTimeout(l); - Assert.assertEquals(l, conf.getTransactionTimeout()); - - b = RandomUtil.randomBoolean(); - conf.setMessageCounterEnabled(b); - Assert.assertEquals(b, conf.isMessageCounterEnabled()); - - l = RandomUtil.randomPositiveLong(); - conf.setMessageCounterSamplePeriod(l); - Assert.assertEquals(l, conf.getMessageCounterSamplePeriod()); - - i = RandomUtil.randomInt(); - conf.setMessageCounterMaxDayHistory(i); - Assert.assertEquals(i, conf.getMessageCounterMaxDayHistory()); - - l = RandomUtil.randomLong(); - conf.setTransactionTimeoutScanPeriod(l); - Assert.assertEquals(l, conf.getTransactionTimeoutScanPeriod()); - - s = RandomUtil.randomString(); - conf.setClusterPassword(s); - Assert.assertEquals(s, conf.getClusterPassword()); - - i = RandomUtil.randomInt(); - conf.setPageSyncTimeout(i); - Assert.assertEquals(i, conf.getPageSyncTimeout()); - - conf.registerBrokerPlugin(new LoggingActiveMQServerPlugin()); - Assert.assertEquals("ensure one plugin registered", 1, conf.getBrokerPlugins().size()); - Assert.assertEquals("ensure one connection plugin registered", 1, conf.getBrokerConnectionPlugins().size()); - - - // This will use serialization to perform a deep copy of the object - Configuration conf2 = conf.copy(); - - Assert.assertTrue(conf.equals(conf2)); + @Test + public void testSetConnectionRoutersPolicyConfiguration() throws Throwable { + doSetConnectionRoutersPolicyConfigurationTestImpl(new ConfigurationImpl()); } @Test @@ -718,61 +337,6 @@ public class ConfigurationImplTest extends ServerTestBase { Assert.assertEquals(4321, configuration.getGlobalMaxSize()); } - @Test - public void testSetConnectionRoutersPolicyConfiguration() throws Throwable { - testSetConnectionRoutersPolicyConfiguration(new ConfigurationImpl()); - } - - @Test - public void testSetConnectionRoutersPolicyFileConfiguration() throws Throwable { - testSetConnectionRoutersPolicyConfiguration(new FileConfiguration()); - } - - private void testSetConnectionRoutersPolicyConfiguration(ConfigurationImpl configuration) throws Throwable { - Properties insertionOrderedProperties = new ConfigurationImpl.InsertionOrderedProperties(); - insertionOrderedProperties.put("connectionRouters.autoShard.localTargetFilter", "NULL|$STATEFUL_SET_ORDINAL"); - insertionOrderedProperties.put("connectionRouters.autoShard.keyType", KeyType.CLIENT_ID); - insertionOrderedProperties.put("connectionRouters.autoShard.policyConfiguration", ConsistentHashModuloPolicy.NAME); - insertionOrderedProperties.put("connectionRouters.autoShard.policyConfiguration.properties." + ConsistentHashModuloPolicy.MODULO, 2); - - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.keyType", KeyType.CLIENT_ID); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.keyFilter", "^.{3}"); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.policyConfiguration", ConsistentHashPolicy.NAME); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.username", "guest-username"); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.password", "guest-password"); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.quorumSize", "2"); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.localTargetEnabled", Boolean.TRUE.toString()); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.poolConfiguration.discoveryGroupName", "discovery-group-1"); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.cacheConfiguration.persisted", Boolean.TRUE.toString()); - insertionOrderedProperties.put("connectionRouters.symmetricRedirect.cacheConfiguration.timeout", "1234"); - - configuration.parsePrefixedProperties(insertionOrderedProperties, null); - - Assert.assertEquals(2, configuration.getConnectionRouters().size()); - - ConnectionRouterConfiguration autoShardConfig = configuration.getConnectionRouters().stream().filter( - connectionRouterConfig -> "autoShard".equals(connectionRouterConfig.getName())).findFirst().get(); - Assert.assertEquals(KeyType.CLIENT_ID, autoShardConfig.getKeyType()); - Assert.assertEquals("2", autoShardConfig.getPolicyConfiguration().getProperties().get(ConsistentHashModuloPolicy.MODULO)); - Assert.assertNull(autoShardConfig.getCacheConfiguration()); - Assert.assertNull(autoShardConfig.getPoolConfiguration()); - - ConnectionRouterConfiguration symmetricRedirectConfig = configuration.getConnectionRouters().stream().filter( - connectionRouterConfig -> "symmetricRedirect".equals(connectionRouterConfig.getName())).findFirst().get(); - Assert.assertEquals(KeyType.CLIENT_ID, symmetricRedirectConfig.getKeyType()); - Assert.assertEquals("^.{3}", symmetricRedirectConfig.getKeyFilter()); - Assert.assertEquals(ConsistentHashPolicy.NAME, symmetricRedirectConfig.getPolicyConfiguration().getName()); - Assert.assertNotNull(symmetricRedirectConfig.getPoolConfiguration()); - Assert.assertEquals("guest-username", symmetricRedirectConfig.getPoolConfiguration().getUsername()); - Assert.assertEquals("guest-password", symmetricRedirectConfig.getPoolConfiguration().getPassword()); - Assert.assertEquals(2, symmetricRedirectConfig.getPoolConfiguration().getQuorumSize()); - Assert.assertEquals(Boolean.TRUE, symmetricRedirectConfig.getPoolConfiguration().isLocalTargetEnabled()); - Assert.assertEquals("discovery-group-1", symmetricRedirectConfig.getPoolConfiguration().getDiscoveryGroupName()); - Assert.assertNotNull(symmetricRedirectConfig.getCacheConfiguration()); - Assert.assertEquals(Boolean.TRUE, symmetricRedirectConfig.getCacheConfiguration().isPersisted()); - Assert.assertEquals(1234, symmetricRedirectConfig.getCacheConfiguration().getTimeout()); - } - @Test public void testAMQPConnectionsConfiguration() throws Throwable { testAMQPConnectionsConfiguration(true); @@ -2743,17 +2307,4 @@ public class ConfigurationImplTest extends ServerTestBase { return this; } } - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - conf = createConfiguration(); - } - - protected Configuration createConfiguration() throws Exception { - return new ConfigurationImpl(); - } - } diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DefaultsFileConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DefaultsFileConfigurationTest.java index 4bed395d56..4e0c62e10d 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DefaultsFileConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/DefaultsFileConfigurationTest.java @@ -26,12 +26,20 @@ import org.apache.activemq.artemis.core.config.ha.PrimaryOnlyPolicyConfiguration import org.junit.Assert; import org.junit.Test; -public class DefaultsFileConfigurationTest extends ConfigurationImplTest { +public class DefaultsFileConfigurationTest extends AbstractConfigurationTestBase { @Override + protected Configuration createConfiguration() throws Exception { + FileConfiguration fc = new FileConfiguration(); + FileDeploymentManager deploymentManager = new FileDeploymentManager("ConfigurationTest-defaults.xml"); + deploymentManager.addDeployable(fc); + deploymentManager.readConfiguration(); + + return fc; + } + @Test public void testDefaults() { - Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), conf.getScheduledThreadPoolMaxSize()); Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultThreadPoolMaxSize(), conf.getThreadPoolMaxSize()); @@ -150,16 +158,4 @@ public class DefaultsFileConfigurationTest extends ConfigurationImplTest { Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultLoggingMetrics(), conf.getMetricsConfiguration().isLogging()); } - - // Protected --------------------------------------------------------------------------------------------- - - @Override - protected Configuration createConfiguration() throws Exception { - FileConfiguration fc = new FileConfiguration(); - FileDeploymentManager deploymentManager = new FileDeploymentManager("ConfigurationTest-defaults.xml"); - deploymentManager.addDeployable(fc); - deploymentManager.readConfiguration(); - - return fc; - } } diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationBrokerConnectionEncryptedTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationBrokerConnectionEncryptedTest.java index ab70a0049d..b86bea406f 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationBrokerConnectionEncryptedTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationBrokerConnectionEncryptedTest.java @@ -24,16 +24,19 @@ import org.apache.activemq.artemis.core.config.amqpBrokerConnectivity.AMQPBroker import org.junit.Assert; import org.junit.Test; -public class FileConfigurationBrokerConnectionEncryptedTest extends ConfigurationImplTest { +public class FileConfigurationBrokerConnectionEncryptedTest extends AbstractConfigurationTestBase { protected String getConfigurationName() { return "ConfigurationTest-broker-connection-encrypted-config.xml"; } @Override - @Test - public void testDefaults() { - // empty + protected Configuration createConfiguration() throws Exception { + FileConfiguration fc = new FileConfiguration(); + FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName()); + deploymentManager.addDeployable(fc); + deploymentManager.readConfiguration(); + return fc; } @Test @@ -71,16 +74,25 @@ public class FileConfigurationBrokerConnectionEncryptedTest extends Configuratio Assert.assertTrue("enc-test configuration is not present", encTest); Assert.assertTrue("plain-test configuration is not present", plainTest); Assert.assertTrue("empty-test configuration is not present", emptyTest); - } - @Override - protected Configuration createConfiguration() throws Exception { - FileConfiguration fc = new FileConfiguration(); - FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName()); - deploymentManager.addDeployable(fc); - deploymentManager.readConfiguration(); - return fc; + @Test + public void testSetGetAttributes() throws Exception { + doSetGetAttributesTestImpl(conf); } + @Test + public void testGetSetInterceptors() { + doGetSetInterceptorsTestImpl(conf); + } + + @Test + public void testSerialize() throws Exception { + doSerializeTestImpl(conf); + } + + @Test + public void testSetConnectionRoutersPolicyConfiguration() throws Throwable { + doSetConnectionRoutersPolicyConfigurationTestImpl((ConfigurationImpl) conf); + } } diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationDbEncryptedPassTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationDbEncryptedPassTest.java index cad1f638b6..d281d00156 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationDbEncryptedPassTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationDbEncryptedPassTest.java @@ -22,24 +22,12 @@ import org.apache.activemq.artemis.utils.SensitiveDataCodec; import org.junit.Assert; import org.junit.Test; -public class FileConfigurationDbEncryptedPassTest extends ConfigurationImplTest { - +public class FileConfigurationDbEncryptedPassTest extends AbstractConfigurationTestBase { protected String getConfigurationName() { return "ConfigurationTest-db-encrypted-pass-config.xml"; } - @Override - @Test - public void testDefaults() { - // empty - } - - @Test - public void testJdbcPasswordWithCustomCodec() { - Assert.assertTrue(MySensitiveStringCodec.decoded); - } - @Override protected Configuration createConfiguration() throws Exception { FileConfiguration fc = new FileConfiguration(); @@ -49,6 +37,31 @@ public class FileConfigurationDbEncryptedPassTest extends ConfigurationImplTest return fc; } + @Test + public void testJdbcPasswordWithCustomCodec() { + Assert.assertTrue(MySensitiveStringCodec.decoded); + } + + @Test + public void testSetGetAttributes() throws Exception { + doSetGetAttributesTestImpl(conf); + } + + @Test + public void testGetSetInterceptors() { + doGetSetInterceptorsTestImpl(conf); + } + + @Test + public void testSerialize() throws Exception { + doSerializeTestImpl(conf); + } + + @Test + public void testSetConnectionRoutersPolicyConfiguration() throws Throwable { + doSetConnectionRoutersPolicyConfigurationTestImpl((ConfigurationImpl) conf); + } + public static class MySensitiveStringCodec implements SensitiveDataCodec { public static boolean decoded = false; diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationSecurityPluginTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationSecurityPluginTest.java index b3a8b5742d..693b22bf78 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationSecurityPluginTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationSecurityPluginTest.java @@ -29,22 +29,12 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class FileConfigurationSecurityPluginTest extends ConfigurationImplTest { - +public class FileConfigurationSecurityPluginTest extends AbstractConfigurationTestBase { protected String getConfigurationName() { return "ConfigurationTest-security-plugin-config.xml"; } - @Override - @Test - public void testDefaults() { - List securitySettingPlugins = conf.getSecuritySettingPlugins(); - Assert.assertEquals(1, securitySettingPlugins.size()); - Assert.assertEquals("secret", MyPlugin.options.get("setting1")); - Assert.assertEquals("hello", MyPlugin.options.get("setting2")); - } - @Override protected Configuration createConfiguration() throws Exception { FileConfiguration fc = new FileConfiguration(); @@ -54,6 +44,35 @@ public class FileConfigurationSecurityPluginTest extends ConfigurationImplTest { return fc; } + @Test + public void testDefaults() { + List securitySettingPlugins = conf.getSecuritySettingPlugins(); + Assert.assertEquals(1, securitySettingPlugins.size()); + Assert.assertEquals("secret", MyPlugin.options.get("setting1")); + Assert.assertEquals("hello", MyPlugin.options.get("setting2")); + } + + @Test + public void testSetGetAttributes() throws Exception { + doSetGetAttributesTestImpl(conf); + } + + @Test + public void testGetSetInterceptors() { + doGetSetInterceptorsTestImpl(conf); + } + + @Test + public void testSerialize() throws Exception { + doSerializeTestImpl(conf); + } + + @Test + public void testSetConnectionRoutersPolicyConfiguration() throws Throwable { + doSetConnectionRoutersPolicyConfigurationTestImpl((ConfigurationImpl) conf); + } + + // Referenced by the configuration file public static class MyPlugin implements SecuritySettingPlugin { private static Map options; diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java index 84a3273ad9..214b6e7b65 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationTest.java @@ -84,7 +84,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @RunWith(Parameterized.class) -public class FileConfigurationTest extends ConfigurationImplTest { +public class FileConfigurationTest extends AbstractConfigurationTestBase { @BeforeClass public static void setupProperties() { @@ -116,8 +116,18 @@ public class FileConfigurationTest extends ConfigurationImplTest { } @Override + protected Configuration createConfiguration() throws Exception { + // This may be set for the entire testsuite, but on this test we need this out + System.clearProperty("brokerconfig.maxDiskUsage"); + FileConfiguration fc = new FileConfiguration(); + FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName()); + deploymentManager.addDeployable(fc); + deploymentManager.readConfiguration(); + return fc; + } + @Test - public void testDefaults() { + public void testFileConfiguration() { // Check they match the values from the test file Assert.assertEquals("SomeNameForUseOnTheApplicationServer", conf.getName()); Assert.assertEquals(false, conf.isPersistenceEnabled()); @@ -927,15 +937,24 @@ public class FileConfigurationTest extends ConfigurationImplTest { assertEquals("value3", metricPluginOptions.get("key3")); } - @Override - protected Configuration createConfiguration() throws Exception { - // This may be set for the entire testsuite, but on this test we need this out - System.clearProperty("brokerconfig.maxDiskUsage"); - FileConfiguration fc = new FileConfiguration(); - FileDeploymentManager deploymentManager = new FileDeploymentManager(getConfigurationName()); - deploymentManager.addDeployable(fc); - deploymentManager.readConfiguration(); - return fc; + @Test + public void testSetGetAttributes() throws Exception { + doSetGetAttributesTestImpl(conf); + } + + @Test + public void testGetSetInterceptors() { + doGetSetInterceptorsTestImpl(conf); + } + + @Test + public void testSerialize() throws Exception { + doSerializeTestImpl(conf); + } + + @Test + public void testSetConnectionRoutersPolicyConfiguration() throws Throwable { + doSetConnectionRoutersPolicyConfigurationTestImpl(new FileConfiguration()); } private Configuration createConfiguration(String filename) throws Exception { diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeConfigurationTest.java index 8206ba91f9..8422d9fd7d 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeConfigurationTest.java @@ -22,6 +22,11 @@ import org.junit.BeforeClass; public class FileXIncludeConfigurationTest extends FileConfigurationTest { + @Override + protected String getConfigurationName() { + return "ConfigurationTest-xinclude-config.xml"; + } + public FileXIncludeConfigurationTest(boolean xxeEnabled) { super(xxeEnabled); Assume.assumeTrue(xxeEnabled); @@ -44,9 +49,4 @@ public class FileXIncludeConfigurationTest extends FileConfigurationTest { System.clearProperty("trueProp"); System.clearProperty("ninetyTwoProp"); } - - @Override - protected String getConfigurationName() { - return "ConfigurationTest-xinclude-config.xml"; - } } \ No newline at end of file diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeSchemaConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeSchemaConfigurationTest.java index 87b9de6488..a45e64c73a 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeSchemaConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileXIncludeSchemaConfigurationTest.java @@ -20,9 +20,15 @@ import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerBasePlugin; import org.junit.AfterClass; import org.junit.Assume; import org.junit.BeforeClass; +import org.junit.Test; public class FileXIncludeSchemaConfigurationTest extends FileConfigurationTest { + @Override + protected String getConfigurationName() { + return "ConfigurationTest-xinclude-schema-config.xml"; + } + public FileXIncludeSchemaConfigurationTest(boolean xxeEnabled) { super(xxeEnabled); Assume.assumeTrue(xxeEnabled); @@ -47,10 +53,11 @@ public class FileXIncludeSchemaConfigurationTest extends FileConfigurationTest { } @Override + @Test public void testSerialize() throws Exception { - // ConfigurationImplTest#testSerialize() assumes the one plugin it registers is the only one in the configuration. + // super#testSerialize() assumes the one plugin it registers is the only one in the configuration. - // Check the expected 2 from the include file are present + // Check the expected 2 plugins from the include file are present assertEquals("included broker plugins are not present", 2, conf.getBrokerPlugins().size()); // Clear the list @@ -61,9 +68,4 @@ public class FileXIncludeSchemaConfigurationTest extends FileConfigurationTest { // Allow the test to proceed super.testSerialize(); } - - @Override - protected String getConfigurationName() { - return "ConfigurationTest-xinclude-schema-config.xml"; - } }