From bd5124cf94ec50885a99ef4265a7396ab3e73f33 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Tue, 20 Mar 2012 14:06:37 +0000 Subject: [PATCH] Added config test for LevelDB - for https://issues.apache.org/jira/browse/AMQ-3772 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1302904 13f79535-47bb-0310-9956-ffa450edef68 --- .../store/leveldb/LevelDBConfigTest.java | 131 ++++++++++++++++++ .../apache/activemq/store/leveldb/leveldb.xml | 58 ++++++++ 2 files changed, 189 insertions(+) create mode 100755 activemq-core/src/test/java/org/apache/activemq/store/leveldb/LevelDBConfigTest.java create mode 100755 activemq-core/src/test/resources/org/apache/activemq/store/leveldb/leveldb.xml diff --git a/activemq-core/src/test/java/org/apache/activemq/store/leveldb/LevelDBConfigTest.java b/activemq-core/src/test/java/org/apache/activemq/store/leveldb/LevelDBConfigTest.java new file mode 100755 index 0000000000..00e0cf51cf --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/store/leveldb/LevelDBConfigTest.java @@ -0,0 +1,131 @@ +/** + * 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.store.leveldb; + +import java.io.File; + +import junit.framework.TestCase; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.command.ActiveMQTopic; +import org.apache.activemq.store.memory.MemoryPersistenceAdapter; +import org.apache.activemq.usage.SystemUsage; +import org.apache.activemq.xbean.BrokerFactoryBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +/** + * + */ +public class LevelDBConfigTest extends TestCase { + + + protected static final String CONF_ROOT = "src/test/resources/org/apache/activemq/store/leveldb/"; + private static final Logger LOG = LoggerFactory.getLogger(LevelDBConfigTest.class); + + + + + /* + * This tests configuring the different broker properties using + * xbeans-spring + */ + public void testBrokerConfig() throws Exception { + ActiveMQTopic dest; + BrokerService broker; + + + // Create broker from resource + // System.out.print("Creating broker... "); + broker = createBroker("org/apache/activemq/store/leveldb/leveldb.xml"); + LOG.info("Success"); + + try { + // Check broker configuration + // System.out.print("Checking broker configurations... "); + assertEquals("Broker Config Error (brokerName)", "brokerConfigTest", broker.getBrokerName()); + assertEquals("Broker Config Error (populateJMSXUserID)", false, broker.isPopulateJMSXUserID()); + assertEquals("Broker Config Error (useLoggingForShutdownErrors)", true, broker.isUseLoggingForShutdownErrors()); + assertEquals("Broker Config Error (useJmx)", true, broker.isUseJmx()); + assertEquals("Broker Config Error (persistent)", false, broker.isPersistent()); + assertEquals("Broker Config Error (useShutdownHook)", false, broker.isUseShutdownHook()); + assertEquals("Broker Config Error (deleteAllMessagesOnStartup)", true, broker.isDeleteAllMessagesOnStartup()); + LOG.info("Success"); + + // Check specific vm transport + // System.out.print("Checking vm connector... "); + assertEquals("Should have a specific VM Connector", "vm://javacoola", broker.getVmConnectorURI().toString()); + LOG.info("Success"); + + + // Check usage manager + // System.out.print("Checking memory manager configurations... "); + SystemUsage systemUsage = broker.getSystemUsage(); + assertTrue("Should have a SystemUsage", systemUsage != null); + assertEquals("SystemUsage Config Error (MemoryUsage.limit)", 1024 * 1024 * 10, systemUsage.getMemoryUsage().getLimit()); + assertEquals("SystemUsage Config Error (MemoryUsage.percentUsageMinDelta)", 20, systemUsage.getMemoryUsage().getPercentUsageMinDelta()); + assertEquals("SystemUsage Config Error (TempUsage.limit)", 1024 * 1024 * 100, systemUsage.getTempUsage().getLimit()); + assertEquals("SystemUsage Config Error (StoreUsage.limit)", 1024 * 1024 * 1024, systemUsage.getStoreUsage().getLimit()); + assertEquals("SystemUsage Config Error (StoreUsage.name)", "foo", systemUsage.getStoreUsage().getName()); + + assertNotNull(systemUsage.getStoreUsage().getStore()); + assertTrue(systemUsage.getStoreUsage().getStore() instanceof LevelDBPersistenceAdapter); + + LOG.info("Success"); + + } finally { + if (broker != null) { + broker.stop(); + } + } + } + + + + /* + * TODO: Create additional tests for forwarding bridges + */ + + protected static void recursiveDelete(File file) { + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + recursiveDelete(files[i]); + } + } + file.delete(); + } + + protected BrokerService createBroker(String resource) throws Exception { + return createBroker(new ClassPathResource(resource)); + } + + protected BrokerService createBroker(Resource resource) throws Exception { + BrokerFactoryBean factory = new BrokerFactoryBean(resource); + factory.afterPropertiesSet(); + + BrokerService broker = factory.getBroker(); + + assertTrue("Should have a broker!", broker != null); + + // Broker is already started by default when using the XML file + // broker.start(); + + return broker; + } +} diff --git a/activemq-core/src/test/resources/org/apache/activemq/store/leveldb/leveldb.xml b/activemq-core/src/test/resources/org/apache/activemq/store/leveldb/leveldb.xml new file mode 100755 index 0000000000..c45753cdca --- /dev/null +++ b/activemq-core/src/test/resources/org/apache/activemq/store/leveldb/leveldb.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +