summaryrefslogtreecommitdiff
path: root/java/broker/src/test/java/org/apache/qpid/server/virtualhost
diff options
context:
space:
mode:
Diffstat (limited to 'java/broker/src/test/java/org/apache/qpid/server/virtualhost')
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java69
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java107
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java347
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java105
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java186
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java89
-rw-r--r--java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java294
7 files changed, 88 insertions, 1109 deletions
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
index 290c465785..1d99d99820 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
@@ -22,26 +22,18 @@ package org.apache.qpid.server.virtualhost;
import java.util.concurrent.ScheduledFuture;
import org.apache.qpid.server.binding.BindingFactory;
-import org.apache.qpid.server.configuration.BrokerConfig;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.VirtualHostConfig;
-import org.apache.qpid.server.configuration.VirtualHostConfigType;
import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.connection.IConnectionRegistry;
import org.apache.qpid.server.exchange.ExchangeFactory;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.federation.BrokerLink;
import org.apache.qpid.server.protocol.v1_0.LinkRegistry;
import org.apache.qpid.server.queue.QueueRegistry;
-import org.apache.qpid.server.registry.IApplicationRegistry;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.store.MessageStore;
import org.apache.qpid.server.txn.DtxRegistry;
-import java.util.Map;
import java.util.UUID;
public class MockVirtualHost implements VirtualHost
@@ -58,19 +50,8 @@ public class MockVirtualHost implements VirtualHost
}
- public void createBrokerConnection(String transport, String host, int port,
- String vhost, boolean durable, String authMechanism,
- String username, String password)
- {
-
- }
-
- public BrokerLink createBrokerConnection(final UUID id, final long createTime, final Map<String, String> arguments)
- {
- return null;
- }
-
- public IApplicationRegistry getApplicationRegistry()
+ @Override
+ public VirtualHostRegistry getVirtualHostRegistry()
{
return null;
}
@@ -85,16 +66,6 @@ public class MockVirtualHost implements VirtualHost
return null;
}
- public UUID getBrokerId()
- {
- return null;
- }
-
- public ConfigStore getConfigStore()
- {
- return null;
- }
-
public DtxRegistry getDtxRegistry()
{
return null;
@@ -160,12 +131,6 @@ public class MockVirtualHost implements VirtualHost
return null;
}
-
- public void removeBrokerConnection(BrokerLink brokerLink)
- {
-
- }
-
public LinkRegistry getLinkRegistry(String remoteContainerId)
{
return null;
@@ -186,25 +151,6 @@ public class MockVirtualHost implements VirtualHost
}
- public BrokerConfig getBroker()
- {
- return null;
- }
-
- public String getFederationTag()
- {
- return null;
- }
-
- public void setBroker(BrokerConfig brokerConfig)
- {
-
- }
-
- public VirtualHostConfigType getConfigType()
- {
- return null;
- }
public long getCreateTime()
{
@@ -216,17 +162,6 @@ public class MockVirtualHost implements VirtualHost
return null;
}
- @Override
- public UUID getQMFId()
- {
- return null;
- }
-
- public ConfiguredObject<VirtualHostConfigType, VirtualHostConfig> getParent()
- {
- return null;
- }
-
public boolean isDurable()
{
return false;
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
index b8ba76e43d..559a7f8aaf 100644
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
+++ b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/VirtualHostImplTest.java
@@ -20,15 +20,21 @@
*/
package org.apache.qpid.server.virtualhost;
+import static org.mockito.Mockito.mock;
+
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
-import org.apache.qpid.server.configuration.ServerConfiguration;
import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.MemoryMessageStore;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.test.utils.QpidTestCase;
import java.io.BufferedWriter;
@@ -38,15 +44,31 @@ import java.io.IOException;
public class VirtualHostImplTest extends QpidTestCase
{
- private ServerConfiguration _configuration;
- private ApplicationRegistry _registry;
+ private VirtualHostRegistry _virtualHostRegistry;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ }
@Override
public void tearDown() throws Exception
{
- super.tearDown();
+ try
+ {
+ if (_virtualHostRegistry != null)
+ {
+ _virtualHostRegistry.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
- ApplicationRegistry.remove();
}
/**
@@ -74,17 +96,23 @@ public class VirtualHostImplTest extends QpidTestCase
*/
public void testSpecifyingCustomBindingForDefaultExchangeThrowsException() throws Exception
{
- File config = writeConfigFile(getName(), getName(), null, false, new String[]{"custom-binding"});
+ final String queueName = getName();
+ final String customBinding = "custom-binding";
+ File config = writeConfigFile(queueName, queueName, null, false, new String[]{customBinding});
try
{
- createVirtualHost(getName(), config);
+ createVirtualHost(queueName, config);
fail("virtualhost creation should have failed due to illegal configuration");
}
catch (RuntimeException e)
{
+ assertNotNull(e.getCause());
+
assertEquals(ConfigurationException.class, e.getCause().getClass());
- //expected
+
+ Throwable configException = e.getCause();
+ assertEquals("Illegal attempt to bind queue '" + queueName + "' to the default exchange with a key other than the queue name: " + customBinding, configException.getMessage());
}
}
@@ -96,6 +124,14 @@ public class VirtualHostImplTest extends QpidTestCase
assertEquals(State.ACTIVE, vhost.getState());
}
+ public void testVirtualHostHavingStoreSetAsTypeBecomesActive() throws Exception
+ {
+ String virtualHostName = getName();
+ VirtualHost host = createVirtualHostUsingStoreType(virtualHostName);
+ assertNotNull(host);
+ assertEquals(State.ACTIVE, host.getState());
+ }
+
public void testVirtualHostBecomesStoppedOnClose() throws Exception
{
File config = writeConfigFile(getName(), getName(), getName() +".direct", false, new String[0]);
@@ -107,22 +143,39 @@ public class VirtualHostImplTest extends QpidTestCase
assertEquals(0, vhost.getHouseKeepingActiveCount());
}
+ public void testVirtualHostHavingStoreSetAsTypeBecomesStoppedOnClose() throws Exception
+ {
+ String virtualHostName = getName();
+ VirtualHost host = createVirtualHostUsingStoreType(virtualHostName);
+ assertNotNull(host);
+ assertEquals(State.ACTIVE, host.getState());
+ host.close();
+ assertEquals(State.STOPPED, host.getState());
+ assertEquals(0, host.getHouseKeepingActiveCount());
+ }
+
/**
* Tests that specifying an unknown exchange to bind the queue to results in failure to create the vhost
*/
public void testSpecifyingUnknownExchangeThrowsException() throws Exception
{
- File config = writeConfigFile(getName(), getName(), "made-up-exchange", true, new String[0]);
+ final String queueName = getName();
+ final String exchangeName = "made-up-exchange";
+ File config = writeConfigFile(queueName, queueName, exchangeName, true, new String[0]);
try
{
- createVirtualHost(getName(), config);
+ createVirtualHost(queueName, config);
fail("virtualhost creation should have failed due to illegal configuration");
}
catch (RuntimeException e)
{
+ assertNotNull(e.getCause());
+
assertEquals(ConfigurationException.class, e.getCause().getClass());
- //expected
+
+ Throwable configException = e.getCause();
+ assertEquals("Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName, configException.getMessage());
}
}
@@ -154,12 +207,14 @@ public class VirtualHostImplTest extends QpidTestCase
private VirtualHost createVirtualHost(String vhostName, File config) throws Exception
{
- _configuration = new ServerConfiguration(new XMLConfiguration(config));
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ _virtualHostRegistry = broker.getVirtualHostRegistry();
- _registry = new TestApplicationRegistry(_configuration);
- ApplicationRegistry.initialise(_registry);
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(vhostName, config, broker);
+ VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(null), configuration);
+ _virtualHostRegistry.registerVirtualHost(host);
- return _registry.getVirtualHostRegistry().getVirtualHost(vhostName);
+ return host;
}
/**
@@ -184,7 +239,6 @@ public class VirtualHostImplTest extends QpidTestCase
BufferedWriter writer = new BufferedWriter(fstream);
//extra outer tag to please Commons Configuration
- writer.write("<configuration>");
writer.write("<virtualhosts>");
writer.write(" <default>" + vhostName + "</default>");
@@ -222,8 +276,6 @@ public class VirtualHostImplTest extends QpidTestCase
writer.write(" </virtualhost>");
writer.write("</virtualhosts>");
- writer.write("</configuration>");
-
writer.flush();
writer.close();
}
@@ -234,4 +286,17 @@ public class VirtualHostImplTest extends QpidTestCase
return tmpFile;
}
+
+ private VirtualHost createVirtualHostUsingStoreType(String virtualHostName) throws ConfigurationException, Exception
+ {
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ _virtualHostRegistry = broker.getVirtualHostRegistry();
+
+ Configuration config = new PropertiesConfiguration();
+ config.setProperty("store.type", MemoryMessageStore.TYPE);
+ VirtualHostConfiguration configuration = new VirtualHostConfiguration(virtualHostName, config, broker);
+ VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class), new SecurityManager(null), configuration);
+ _virtualHostRegistry.registerVirtualHost(host);
+ return host;
+ }
}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java
deleted file mode 100644
index e2375c579b..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionConfigurationTest.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- *
- * 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.qpid.server.virtualhost.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionConfiguration;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Provide Unit Test coverage of the virtualhost SlowConsumer Configuration
- * This is what controls how often the plugin will execute
- */
-public class SlowConsumerDetectionConfigurationTest extends InternalBrokerBaseCase
-{
-
- /**
- * Default Testing:
- *
- * Provide a fully complete and valid configuration specifying 'delay' and
- * 'timeunit' and ensure that it is correctly processed.
- *
- * Ensure no exceptions are thrown and that we get the same values back that
- * were put into the configuration.
- */
- public void testConfigLoadingValidConfig()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- long DELAY=10;
- String TIMEUNIT=TimeUnit.MICROSECONDS.toString();
- xmlconfig.addProperty("delay", String.valueOf(DELAY));
- xmlconfig.addProperty("timeunit", TIMEUNIT);
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Delay not correctly returned.", DELAY, config.getDelay());
- assertEquals("TimeUnit not correctly returned.",
- TIMEUNIT, String.valueOf(config.getTimeUnit()));
- }
-
- /**
- * Default Testing:
- *
- * Test Missing TimeUnit value gets default.
- *
- * The TimeUnit value is optional and default to SECONDS.
- *
- * Test that if we do not specify a TimeUnit then we correctly get seconds.
- *
- * Also verify that relying on the default does not impact the setting of
- * the 'delay' value.
- *
- */
- public void testConfigLoadingMissingTimeUnitDefaults()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- long DELAY=10;
- xmlconfig.addProperty("delay", String.valueOf(DELAY));
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Delay not correctly returned.", DELAY, config.getDelay());
- assertEquals("Default TimeUnit incorrect", TimeUnit.SECONDS, config.getTimeUnit());
- }
-
- /**
- * Input Testing:
- *
- * TimeUnit parsing requires the String value be in UpperCase.
- * Ensure we can handle when the user doesn't know this.
- *
- * Same test as 'testConfigLoadingValidConfig' but checking that
- * the timeunit field is not case sensitive.
- * i.e. the toUpper is being correctly applied.
- */
- public void testConfigLoadingValidConfigStrangeTimeUnit()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- long DELAY=10;
-
- xmlconfig.addProperty("delay", DELAY);
- xmlconfig.addProperty("timeunit", "MiCrOsEcOnDs");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Delay not correctly returned.", DELAY, config.getDelay());
- assertEquals("TimeUnit not correctly returned.",
- TimeUnit.MICROSECONDS.toString(), String.valueOf(config.getTimeUnit()));
-
- }
-
- /**
- * Failure Testing:
- *
- * Test that delay must be long not a string value.
- * Provide a delay as a written value not a long. 'ten'.
- *
- * This should throw a configuration exception which is being trapped and
- * verified to be the right exception, a NumberFormatException.
- *
- */
- public void testConfigLoadingInValidDelayString()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "ten");
- xmlconfig.addProperty("timeunit", TimeUnit.MICROSECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- Throwable cause = e.getCause();
-
- assertEquals("Cause not correct", NumberFormatException.class, cause.getClass());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that negative delays are invalid.
- *
- * Delay must be a positive value as negative delay means doesn't make sense.
- *
- * Configuration exception with a useful message should be thrown here.
- *
- */
- public void testConfigLoadingInValidDelayNegative()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "-10");
- xmlconfig.addProperty("timeunit", TimeUnit.MICROSECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- Throwable cause = e.getCause();
-
- assertNotNull("Configuration Exception must not be null.", cause);
- assertEquals("Cause not correct",
- ConfigurationException.class, cause.getClass());
- assertEquals("Incorrect message.",
- "SlowConsumerDetectionConfiguration: 'delay' must be a Positive Long value.",
- cause.getMessage());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that delay cannot be 0.
- *
- * A zero delay means run constantly. This is not how VirtualHostTasks
- * are designed to be run so we dis-allow the use of 0 delay.
- *
- * Same test as 'testConfigLoadingInValidDelayNegative' but with a 0 value.
- *
- */
- public void testConfigLoadingInValidDelayZero()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "0");
- xmlconfig.addProperty("timeunit", TimeUnit.MICROSECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- Throwable cause = e.getCause();
-
- assertNotNull("Configuration Exception must not be null.", cause);
- assertEquals("Cause not correct",
- ConfigurationException.class, cause.getClass());
- assertEquals("Incorrect message.",
- "SlowConsumerDetectionConfiguration: 'delay' must be a Positive Long value.",
- cause.getMessage());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that missing delay fails.
- * If we have no delay then we do not pick a default. So a Configuration
- * Exception is thrown.
- *
- * */
- public void testConfigLoadingInValidMissingDelay()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("timeunit", TimeUnit.SECONDS.toString());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- assertEquals("Incorrect message.", "SlowConsumerDetectionConfiguration: unable to configure invalid delay:null", e.getMessage());
- }
- }
-
- /**
- * Failure Testing:
- *
- * Test that erroneous TimeUnit fails.
- *
- * Valid TimeUnit values vary based on the JVM version i.e. 1.6 added HOURS/DAYS etc.
- *
- * We don't test the values for TimeUnit are accepted other than MILLISECONDS in the
- * positive testing at the start.
- *
- * Here we ensure that an erroneous for TimeUnit correctly throws an exception.
- *
- * We test with 'foo', which will never be a TimeUnit
- *
- */
- public void testConfigLoadingInValidTimeUnit()
- {
- SlowConsumerDetectionConfiguration config = new SlowConsumerDetectionConfiguration();
-
- String TIMEUNIT = "foo";
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delay", "10");
- xmlconfig.addProperty("timeunit", TIMEUNIT);
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- try
- {
- config.setConfiguration("", composite);
- fail("Configuration should fail to validate");
- }
- catch (ConfigurationException e)
- {
- assertEquals("Incorrect message.", "Unable to configure Slow Consumer Detection invalid TimeUnit:" + TIMEUNIT, e.getMessage());
- }
- }
-
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java
deleted file mode 100644
index ea07632873..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionPolicyConfigurationTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- *
- * 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.qpid.server.virtualhost.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionPolicyConfiguration;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-/**
- * Test class to ensure that the policy configuration can be processed.
- */
-public class SlowConsumerDetectionPolicyConfigurationTest extends InternalBrokerBaseCase
-{
-
- /**
- * Input Testing:
- *
- * Test that a given String can be set and retrieved through the configuration
- *
- * No validation is being performed to ensure that the policy exists. Only
- * that a value can be set for the policy.
- *
- */
- public void testConfigLoadingValidConfig()
- {
- SlowConsumerDetectionPolicyConfiguration config = new SlowConsumerDetectionPolicyConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- String policyName = "TestPolicy";
- xmlconfig.addProperty("name", policyName);
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals("Policy name not retrieved as expected.",
- policyName, config.getPolicyName());
- }
-
- /**
- * Failure Testing:
- *
- * Test that providing a configuration section without the 'name' field
- * causes an exception to be thrown.
- *
- * An empty configuration is provided and the thrown exception message
- * is checked to confirm the right reason.
- *
- */
- public void testConfigLoadingInValidConfig()
- {
- SlowConsumerDetectionPolicyConfiguration config = new SlowConsumerDetectionPolicyConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("Config is invalid so won't validate.");
- }
- catch (ConfigurationException e)
- {
- e.printStackTrace();
- assertEquals("Exception message not as expected.", "No Slow consumer policy defined.", e.getMessage());
- }
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java
deleted file mode 100644
index 96e524acf2..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetectionQueueConfigurationTest.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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.qpid.server.virtualhost.plugins;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionQueueConfiguration;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-/**
- * Unit test the QueueConfiguration processing.
- *
- * This is slightly awkward as the {@link SlowConsumerDetectionQueueConfiguration}
- * requries that a policy be available.
- * <p>
- * So all the Valid test much catch the ensuing {@link ConfigurationException} and
- * validate that the error is due to a lack of a valid policy.
- */
-public class SlowConsumerDetectionQueueConfigurationTest extends InternalBrokerBaseCase
-{
- /**
- * Test a fully loaded configuration file.
- *
- * It is not an error to have all control values specified.
- * <p>
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingValidConfig()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("messageAge", "60000");
- xmlconfig.addProperty("depth", "1024");
- xmlconfig.addProperty("messageCount", "10");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-
- /**
- * When we do not specify any control value then a {@link ConfigurationException}
- * must be thrown to remind us.
- */
- public void testConfigLoadingMissingConfig()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
-
- assertEquals("At least one configuration property('messageAge','depth'" +
- " or 'messageCount') must be specified.", e.getMessage());
- }
- }
-
- /**
- * Setting messageAge on its own is enough to have a valid configuration
- *
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingMessageAgeOk()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("messageAge", "60000");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-
- /**
- * Setting depth on its own is enough to have a valid configuration.
- *
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingDepthOk()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("depth", "1024");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-
- /**
- * Setting messageCount on its own is enough to have a valid configuration.
- *
- * Here we need to catch the {@link ConfigurationException} that ensues due to lack
- * of a policy plugin.
- */
- public void testConfigLoadingMessageCountOk()
- {
- SlowConsumerDetectionQueueConfiguration config = new SlowConsumerDetectionQueueConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("messageCount", "10");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("", composite);
- fail("No Policies are avaialbe to load in a unit test");
- }
- catch (ConfigurationException e)
- {
- assertTrue("Exception message incorrect, was: " + e.getMessage(),
- e.getMessage().startsWith("No Slow Consumer Policy specified. Known Policies:["));
- }
- }
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java
deleted file mode 100644
index f034d05c37..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyConfigurationTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *
- * 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.qpid.server.virtualhost.plugins.policies;
-
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-
-/**
- * Test to ensure TopicDelete Policy configuration can be loaded.
- */
-public class TopicDeletePolicyConfigurationTest extends InternalBrokerBaseCase
-{
- /**
- * Test without any configuration being provided that the
- * deletePersistent option is disabled.
- */
- public void testNoConfigNoDeletePersistent()
- {
- TopicDeletePolicyConfiguration config = new TopicDeletePolicyConfiguration();
-
- assertFalse("TopicDelete Configuration with no config should not delete persistent queues.",
- config.deletePersistent());
- }
-
- /**
- * Test that with the correct configuration the deletePersistent option can
- * be enabled.
- *
- * Test creates a new Configuration object and passes in the xml snippet
- * that the ConfigurationPlugin would receive during normal execution.
- * This is the XML that would be matched for this plugin:
- * <topicdelete>
- * <delete-persistent>
- * <topicdelete>
- *
- * So it would be subset and passed in as just:
- * <delete-persistent>
- *
- *
- * The property should therefore be enabled.
- *
- */
- public void testConfigDeletePersistent()
- {
- TopicDeletePolicyConfiguration config = new TopicDeletePolicyConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
-
- xmlconfig.addProperty("delete-persistent","");
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
-
- try
- {
- config.setConfiguration("",composite);
- }
- catch (ConfigurationException e)
- {
- fail(e.getMessage());
- }
-
- assertTrue("A configured TopicDelete should delete persistent queues.",
- config.deletePersistent());
- }
-
-}
diff --git a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java b/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java
deleted file mode 100644
index aa8448b99d..0000000000
--- a/java/broker/src/test/java/org/apache/qpid/server/virtualhost/plugins/policies/TopicDeletePolicyTest.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- *
- * 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.qpid.server.virtualhost.plugins.policies;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.exchange.DirectExchange;
-import org.apache.qpid.server.exchange.TopicExchange;
-import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-import org.apache.qpid.server.queue.AMQQueue;
-import org.apache.qpid.server.queue.MockAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-
-public class TopicDeletePolicyTest extends InternalBrokerBaseCase
-{
-
- private TopicDeletePolicyConfiguration _config;
-
- private VirtualHost _defaultVhost;
- private InternalTestProtocolSession _connection;
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- _defaultVhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getDefaultVirtualHost();
-
- _connection = new InternalTestProtocolSession(_defaultVhost);
-
- _config = new TopicDeletePolicyConfiguration();
-
- XMLConfiguration config = new XMLConfiguration();
-
- _config.setConfiguration("", config);
- }
-
- private MockAMQQueue createOwnedQueue()
- {
- MockAMQQueue queue = new MockAMQQueue("testQueue");
-
- _defaultVhost.getQueueRegistry().registerQueue(queue);
-
- try
- {
- AMQChannel channel = new AMQChannel(_connection, 0, null);
- _connection.addChannel(channel);
-
- queue.setExclusiveOwningSession(channel);
- }
- catch (AMQException e)
- {
- fail("Unable to create Channel:" + e.getMessage());
- }
-
- return queue;
- }
-
- private void setQueueToAutoDelete(final AMQQueue queue)
- {
- ((MockAMQQueue) queue).setAutoDelete(true);
-
- queue.setDeleteOnNoConsumers(true);
- final AMQProtocolSession.Task deleteQueueTask =
- new AMQProtocolSession.Task()
- {
- public void doTask(AMQProtocolSession session) throws AMQException
- {
- queue.delete();
- }
- };
-
- ((AMQChannel) queue.getExclusiveOwningSession()).getProtocolSession().addSessionCloseTask(deleteQueueTask);
- }
-
- /** Check that a null queue passed in does not upset the policy. */
- public void testNullQueueParameter() throws ConfigurationException
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- try
- {
- policy.performPolicy(null);
- }
- catch (Exception e)
- {
- fail("Exception should not be thrown:" + e.getMessage());
- }
-
- }
-
- /**
- * Set a owning Session to null which means this is not an exclusive queue
- * so the queue should not be deleted
- */
- public void testNonExclusiveQueue()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.setExclusiveOwningSession(null);
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertFalse("Connection should not be closed", _connection.isClosed());
- }
-
- /**
- * Test that exclusive JMS Queues are not deleted.
- * Bind the queue to the direct exchange (so it is a JMS Queue).
- *
- * JMS Queues are not to be processed so this should not delete the queue.
- */
- public void testQueuesAreNotProcessed()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new DirectExchange(), null));
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertFalse("Connection should not be closed", _connection.isClosed());
- }
-
- /**
- * Give a non auto-delete queue is bound to the topic exchange the
- * TopicDeletePolicy will close the connection and delete the queue,
- */
- public void testNonAutoDeleteTopicIsNotClosed()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- queue.setAutoDelete(false);
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a auto-delete queue bound to the topic exchange the TopicDeletePolicy will
- * close the connection and delete the queue
- */
- public void testTopicIsClosed()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- final MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- setQueueToAutoDelete(queue);
-
- policy.performPolicy(queue);
-
- assertTrue("Queue should be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a queue bound to the topic exchange the TopicDeletePolicy will
- * close the connection and NOT delete the queue
- */
- public void testNonAutoDeleteTopicIsClosedNotDeleted()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a queue bound to the topic exchange the TopicDeletePolicy suitably
- * configured with the delete-persistent tag will close the connection
- * and delete the queue
- */
- public void testPersistentTopicIsClosedAndDeleted()
- {
- //Set the config to delete persistent queues
- _config.getConfig().addProperty("delete-persistent", "");
-
- TopicDeletePolicy policy = new TopicDeletePolicy();
- policy.configure(_config);
-
- assertTrue("Config was not updated to delete Persistent topics",
- _config.deletePersistent());
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- policy.performPolicy(queue);
-
- assertTrue("Queue should be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- /**
- * Give a queue bound to the topic exchange the TopicDeletePolicy not
- * configured to close a persistent queue
- */
- public void testPersistentTopicIsClosedAndDeletedNullConfig()
- {
- TopicDeletePolicy policy = new TopicDeletePolicy();
- // Explicity say we are not configuring the policy.
- policy.configure(null);
-
- MockAMQQueue queue = createOwnedQueue();
-
- queue.addBinding(new Binding(null, null, "bindingKey", queue, new TopicExchange(), null));
-
- policy.performPolicy(queue);
-
- assertFalse("Queue should not be deleted", queue.isDeleted());
- assertTrue("Connection should be closed", _connection.isClosed());
- }
-
- public void testNonExclusiveQueueNullConfig()
- {
- _config = null;
- testNonExclusiveQueue();
- }
-
- public void testQueuesAreNotProcessedNullConfig()
- {
- _config = null;
- testQueuesAreNotProcessed();
- }
-
- public void testNonAutoDeleteTopicIsNotClosedNullConfig()
- {
- _config = null;
- testNonAutoDeleteTopicIsNotClosed();
- }
-
- public void testTopicIsClosedNullConfig()
- {
- _config = null;
- testTopicIsClosed();
- }
-
- public void testNonAutoDeleteTopicIsClosedNotDeletedNullConfig() throws AMQException
- {
- _config = null;
- testNonAutoDeleteTopicIsClosedNotDeleted();
- }
-
-}