Better test setup

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@365280 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2006-01-02 02:50:00 +00:00
parent 6bdfbf3d73
commit ef64a25b9f
1 changed files with 3 additions and 34 deletions

View File

@ -16,24 +16,13 @@
*/
package org.apache.activemq.broker.store;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
import junit.framework.Test;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.BrokerTest;
import org.apache.activemq.store.DefaultPersistenceAdapterFactory;
import org.apache.activemq.store.PersistenceAdapter;
import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
import org.apache.activemq.store.journal.JournalPersistenceAdapter;
/**
* Once the wire format is completed we can test against real persistence storage.
@ -45,29 +34,9 @@ public class DefaultStoreBrokerTest extends BrokerTest {
protected BrokerService createBroker() throws Exception {
return BrokerFactory.createBroker(new URI("broker://()/localhost?deleteAllMessagesOnStartup=true"));
}
protected PersistenceAdapter createPersistenceAdapter(boolean clean) throws IOException {
File dataDir = new File("test-data");
if( clean ) {
recursiveDelete(new File(dataDir, "journal"));
}
DefaultPersistenceAdapterFactory factory = new DefaultPersistenceAdapterFactory();
factory.setDataDirectory(dataDir);
// Use a smaller journal so that tests are quicker.
factory.setJournalLogFileSize(1024*64);
PersistenceAdapter adapter = factory.createPersistenceAdapter();
if( clean ) {
DataSource ds = ((JDBCPersistenceAdapter)((JournalPersistenceAdapter)adapter).getLongTermPersistence()).getDataSource();
try {
Connection c = ds.getConnection();
Statement s = c.createStatement();
try { s.executeUpdate("DROP TABLE ACTIVEMQ_MSGS");} catch (SQLException e) {}
try { s.executeUpdate("DROP TABLE ACTIVEMQ_TXS");} catch (SQLException e) {}
try { s.executeUpdate("DROP TABLE ACTIVEMQ_ACKS");} catch (SQLException e) {}
} catch (SQLException e) {
}
}
return adapter;
protected BrokerService createRestartedBroker() throws Exception {
return BrokerFactory.createBroker(new URI("broker://()/localhost"));
}
public static Test suite() {