summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src/test
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2013-04-29 14:44:11 +0000
committerAlex Rudyy <orudyy@apache.org>2013-04-29 14:44:11 +0000
commitdb2d21bb4d665ed394f1e6bec363418c808c9a4b (patch)
tree4409a0b7fcdb909bebc1c34f4c099ae993a81dc3 /qpid/java/broker/src/test
parentb00b9f5a671149845a25955e9bae6d1eca2a49ee (diff)
downloadqpid-python-db2d21bb4d665ed394f1e6bec363418c808c9a4b.tar.gz
QPID-4639: Improve functionality to delete store on virtual host deletion
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1477110 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src/test')
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java93
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java82
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java149
3 files changed, 324 insertions, 0 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java
new file mode 100644
index 0000000000..065d6408de
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTestCase.java
@@ -0,0 +1,93 @@
+/*
+ *
+ * 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.store;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.qpid.server.store.ConfigurationRecoveryHandler.BindingRecoveryHandler;
+import org.apache.qpid.server.store.ConfigurationRecoveryHandler.ExchangeRecoveryHandler;
+import org.apache.qpid.server.store.ConfigurationRecoveryHandler.QueueRecoveryHandler;
+import org.apache.qpid.server.store.MessageStoreRecoveryHandler.StoredMessageRecoveryHandler;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public abstract class MessageStoreTestCase extends QpidTestCase
+{
+ private ConfigurationRecoveryHandler _recoveryHandler;
+ private QueueRecoveryHandler _queueRecoveryHandler;
+ private ExchangeRecoveryHandler _exchangeRecoveryHandler;
+ private BindingRecoveryHandler _bindingRecoveryHandler;
+ private MessageStoreRecoveryHandler _messageStoreRecoveryHandler;
+ private StoredMessageRecoveryHandler _storedMessageRecoveryHandler;
+ private TransactionLogRecoveryHandler _logRecoveryHandler;
+ private TransactionLogRecoveryHandler.QueueEntryRecoveryHandler _queueEntryRecoveryHandler;
+ private TransactionLogRecoveryHandler.DtxRecordRecoveryHandler _dtxRecordRecoveryHandler;
+
+ private MessageStore _store;
+ private Configuration _storeConfiguration;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ _recoveryHandler = mock(ConfigurationRecoveryHandler.class);
+ _queueRecoveryHandler = mock(QueueRecoveryHandler.class);
+ _exchangeRecoveryHandler = mock(ExchangeRecoveryHandler.class);
+ _bindingRecoveryHandler = mock(BindingRecoveryHandler.class);
+ _storedMessageRecoveryHandler = mock(StoredMessageRecoveryHandler.class);
+ _logRecoveryHandler = mock(TransactionLogRecoveryHandler.class);
+ _messageStoreRecoveryHandler = mock(MessageStoreRecoveryHandler.class);
+ _queueEntryRecoveryHandler = mock(TransactionLogRecoveryHandler.QueueEntryRecoveryHandler.class);
+ _dtxRecordRecoveryHandler = mock(TransactionLogRecoveryHandler.DtxRecordRecoveryHandler.class);
+
+ when(_messageStoreRecoveryHandler.begin()).thenReturn(_storedMessageRecoveryHandler);
+ when(_recoveryHandler.begin(isA(MessageStore.class))).thenReturn(_exchangeRecoveryHandler);
+ when(_exchangeRecoveryHandler.completeExchangeRecovery()).thenReturn(_queueRecoveryHandler);
+ when(_queueRecoveryHandler.completeQueueRecovery()).thenReturn(_bindingRecoveryHandler);
+ when(_logRecoveryHandler.begin(any(MessageStore.class))).thenReturn(_queueEntryRecoveryHandler);
+ when(_queueEntryRecoveryHandler.completeQueueEntryRecovery()).thenReturn(_dtxRecordRecoveryHandler);
+
+ _storeConfiguration = new PropertiesConfiguration();
+ setUpStoreConfiguration(_storeConfiguration);
+
+ _store = createMessageStore();
+ _store.configureConfigStore(getTestName(), _recoveryHandler, _storeConfiguration);
+ _store.configureMessageStore(getTestName(), _messageStoreRecoveryHandler, _logRecoveryHandler, _storeConfiguration);
+ }
+
+ protected abstract void setUpStoreConfiguration(Configuration storeConfiguration) throws Exception;
+
+ protected abstract MessageStore createMessageStore();
+
+ public MessageStore getStore()
+ {
+ return _store;
+ }
+
+ public Configuration getStoreConfiguration()
+ {
+ return _storeConfiguration;
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java
new file mode 100644
index 0000000000..1747588bf1
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreTest.java
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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.store.derby;
+
+import java.io.File;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreTestCase;
+import org.apache.qpid.util.FileUtils;
+
+public class DerbyMessageStoreTest extends MessageStoreTestCase
+{
+ private String _storeLocation;
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ deleteStoreIfExists();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testOnDelete() throws Exception
+ {
+ File location = new File(_storeLocation);
+ assertTrue("Store does not exist at " + _storeLocation, location.exists());
+
+ getStore().close();
+ assertTrue("Store does not exist at " + _storeLocation, location.exists());
+
+ getStore().onDelete();
+ assertFalse("Store exists at " + _storeLocation, location.exists());
+ }
+
+ @Override
+ protected void setUpStoreConfiguration(Configuration storeConfiguration) throws Exception
+ {
+ _storeLocation = TMP_FOLDER + File.separator + getTestName();
+ storeConfiguration.setProperty("environment-path", _storeLocation);
+ deleteStoreIfExists();
+ }
+
+ private void deleteStoreIfExists()
+ {
+ File location = new File(_storeLocation);
+ if (location.exists())
+ {
+ FileUtils.delete(location, true);
+ }
+ }
+
+ @Override
+ protected MessageStore createMessageStore()
+ {
+ return new DerbyMessageStore();
+ }
+
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java
new file mode 100644
index 0000000000..bb118eaaf7
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java
@@ -0,0 +1,149 @@
+/*
+ *
+ * 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.store.jdbc;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreTestCase;
+import org.apache.qpid.server.store.derby.DerbyMessageStore;
+
+public class JDBCMessageStoreTest extends MessageStoreTestCase
+{
+ private String _connectionURL;
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ shutdownDerby();
+ }
+ finally
+ {
+ super.tearDown();
+ }
+ }
+
+ public void testOnDelete() throws Exception
+ {
+ String[] expectedTables = JDBCMessageStore.ALL_TABLES;
+ assertTablesExist(expectedTables, true);
+ getStore().close();
+ assertTablesExist(expectedTables, true);
+ getStore().onDelete();
+ assertTablesExist(expectedTables, false);
+ }
+
+ @Override
+ protected void setUpStoreConfiguration(Configuration storeConfiguration) throws Exception
+ {
+ _connectionURL = "jdbc:derby:memory:/" + getTestName() + ";create=true";
+ storeConfiguration.addProperty("connectionUrl", _connectionURL);
+ }
+
+ @Override
+ protected MessageStore createMessageStore()
+ {
+ return new JDBCMessageStore();
+ }
+
+ private void assertTablesExist(String[] expectedTables, boolean exists) throws SQLException
+ {
+ Set<String> existingTables = getTableNames();
+ for (String tableName : expectedTables)
+ {
+ assertEquals("Table " + tableName + (exists ? " is not found" : " actually exist"), exists,
+ existingTables.contains(tableName));
+ }
+ }
+
+ private Set<String> getTableNames() throws SQLException
+ {
+ Set<String> tableNames = new HashSet<String>();
+ Connection conn = null;
+ try
+ {
+ conn = openConnection();
+ DatabaseMetaData metaData = conn.getMetaData();
+ ResultSet tables = metaData.getTables(null, null, null, new String[] { "TABLE" });
+ try
+ {
+ while (tables.next())
+ {
+ tableNames.add(tables.getString("TABLE_NAME"));
+ }
+ }
+ finally
+ {
+ tables.close();
+ }
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ return tableNames;
+ }
+
+ private Connection openConnection() throws SQLException
+ {
+ return DriverManager.getConnection(_connectionURL);
+ }
+
+
+ private void shutdownDerby() throws SQLException
+ {
+ Connection connection = null;
+ try
+ {
+ connection = DriverManager.getConnection("jdbc:derby:memory:/" + getTestName() + ";shutdown=true");
+ }
+ catch(SQLException e)
+ {
+ if (e.getSQLState().equalsIgnoreCase(DerbyMessageStore.DERBY_SINGLE_DB_SHUTDOWN_CODE))
+ {
+ //expected and represents a clean shutdown of this database only, do nothing.
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}