summaryrefslogtreecommitdiff
path: root/qpid/java/broker-plugins/jdbc-store/src/test
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2013-07-10 09:10:51 +0000
committerRobert Godfrey <rgodfrey@apache.org>2013-07-10 09:10:51 +0000
commiteaa8c11396b13c46c59c2030a23cc7763ecee9d7 (patch)
tree1035b7dd270a843436871ef4f321e956c5d220f3 /qpid/java/broker-plugins/jdbc-store/src/test
parent934d23d90cb12c820ff71e54f2220991fd72c081 (diff)
downloadqpid-python-eaa8c11396b13c46c59c2030a23cc7763ecee9d7.tar.gz
QPID-4983 : [Java Broker] Move store implementations to broker plugins
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1501682 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins/jdbc-store/src/test')
-rw-r--r--qpid/java/broker-plugins/jdbc-store/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java152
1 files changed, 152 insertions, 0 deletions
diff --git a/qpid/java/broker-plugins/jdbc-store/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java b/qpid/java/broker-plugins/jdbc-store/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java
new file mode 100644
index 0000000000..9c348383c6
--- /dev/null
+++ b/qpid/java/broker-plugins/jdbc-store/src/test/java/org/apache/qpid/server/store/jdbc/JDBCMessageStoreTest.java
@@ -0,0 +1,152 @@
+/*
+ *
+ * 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.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.MessageStoreTestCase;
+
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
+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(VirtualHost virtualHost) throws Exception
+ {
+ _connectionURL = "jdbc:derby:memory:/" + getTestName() + ";create=true";
+
+ when(virtualHost.getAttribute(eq("connectionURL"))).thenReturn(_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("08006"))
+ {
+ //expected and represents a clean shutdown of this database only, do nothing.
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}