[jboss-svn-commits] JBL Code SVN: r6914 - in labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb: . messagestore
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 19 11:54:11 EDT 2006
Author: daniel.brum at jboss.com
Date: 2006-10-19 11:54:10 -0400 (Thu, 19 Oct 2006)
New Revision: 6914
Added:
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/HsqldbUtil.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java
Log:
Q/A tests for MessageStore
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/HsqldbUtil.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/HsqldbUtil.java 2006-10-19 15:43:13 UTC (rev 6913)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/HsqldbUtil.java 2006-10-19 15:54:10 UTC (rev 6914)
@@ -0,0 +1,66 @@
+package org.jboss.soa.esb.messagestore;
+
+import java.sql.DriverManager;
+import java.sql.Statement;
+
+import org.hsqldb.Server;
+/**
+ * Utility to start and stop a hsql Database.
+ *
+ * @author <a href="mailto:kurt.stam at jboss.com">Kurt Stam</a>
+ *
+ */
+public class HsqldbUtil
+{
+ final private static String THREAD_NAME = "hypersonic-unittest";
+ /**
+ * Starts the hsql database in it's own thread.
+ * Don't forget to shut it down when you're done.
+ *
+ * @param databaseFile - i.e. build/hsqltestdb
+ * @param databaseName - i.e. jbossesb
+ * @throws Exception
+ */
+ public static void startHsqldb(final String databaseFile,
+ final String databaseName) throws Exception
+ {
+ // Start DB in new thread, or else it will block us
+ Thread serverThread = new Thread(THREAD_NAME) {
+ public void run() {
+ try {
+ // Create startup arguments
+ String[] args = new String[4];
+ args[0] = "-database.0";
+ args[1] = databaseFile;
+ args[2] = "-dbname.0";
+ args[3] = databaseName;
+
+ System.out.println("creating db from this script: " + databaseFile);
+
+ // Start server
+ Server.main(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+// log.error("Failed to start database", e);
+ }
+ };
+ serverThread.run();
+ }
+ /**
+ *
+ * @param url
+ * @param username
+ * @param password
+ * @throws Exception
+ */
+ public static void stopHsqldb(String url, String username, String password) throws Exception {
+ java.sql.Connection connection = DriverManager.getConnection(
+ url, username, password);
+ Statement statement = connection.createStatement();
+ String shutdownCommand = "SHUTDOWN COMPACT";
+ statement.executeQuery(shutdownCommand);
+ }
+
+
+}
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java 2006-10-19 15:43:13 UTC (rev 6913)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java 2006-10-19 15:54:10 UTC (rev 6914)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.soa.esb.messagestore;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.persistence.MessageStore;
+import org.jboss.soa.esb.persistence.MessageStoreFactory;
+import org.jboss.soa.esb.persistence.format.MessageStoreType;
+
+import junit.framework.TestCase;
+
+/**
+ * @author dbrum
+ *
+ */
+public class MessageStoreTest extends TestCase {
+ private static Logger logger = Logger.getLogger(MessageStoreTest.class);
+
+ public void test() throws Exception {
+ int requestors = 1000; //number of persist calls to make
+ List<URI> uriList = new ArrayList<URI>();
+
+ TestUtil.setESBPropertiesFileToUse();
+ MessageStoreTest.runBeforeAllTests();
+
+ //get the database store
+ MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+
+ //messages to persist
+ Message msg[] = { MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML),
+ MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED)};
+
+ //set some content inside the Messages
+ for (int x=0; x<msg.length; x++) {
+ msg[x].getBody().setContents("TEST BODY".getBytes());
+ msg[x].getProperties().setProperty("prop"+x, "val"+x);
+ msg[x].getAttachment().addItem(new String("TEST ATTACHMENT"));
+ }
+
+ //loop through adding the messages
+
+ Random rndMsg = new Random();
+ for (int x=0; x<=requestors; x++) {
+ URI uid = store.addMessage(msg[rndMsg.nextInt(2)]);
+ uriList.add(uid);
+ }
+
+ logger.info("total messages persisted to db: " + (uriList.size()-1));
+
+ //loop back reading the messages from the db
+ List<Message> messages = new ArrayList<Message>();
+ for (int x=0; x<uriList.size(); x++) {
+ messages.add(store.getMessage(uriList.get(x)));
+ }
+ logger.info("total messages read from db: " + (messages.size()-1));
+
+ MessageStoreTest.runAfterAllTests();
+
+ }
+
+ protected static void runBeforeAllTests() throws Exception{
+
+ TestUtil.setESBPropertiesFileToUse();
+
+ if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+ HsqldbUtil.startHsqldb("home/dbrum/dev/jbossesb/trunk/product/install/message-store/sql/hsqldb/create_database.sql", "jbossesb");
+ }
+
+ }
+
+ private static void runAfterAllTests() throws Exception{
+
+ if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+ HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
+ Configuration.getStoreUser(),Configuration.getStorePwd() );
+ }
+ }
+
+ public static void main(String args[]) {
+ MessageStoreTest test = new MessageStoreTest();
+ try {
+ test.test();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+}
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java 2006-10-19 15:43:13 UTC (rev 6913)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java 2006-10-19 15:54:10 UTC (rev 6914)
@@ -0,0 +1,37 @@
+package org.jboss.soa.esb.messagestore;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+public class TestUtil
+{
+ private static Logger log = Logger.getLogger(TestUtil.class);
+ private static String _prefix=null;
+ /**
+ * When performing file system interaction, the user.dir may differ (i.e. running the
+ * tests from within eclipse).
+ */
+ public static String getPrefix()
+ {
+ if (_prefix==null) {
+ _prefix="";
+ String baseDir = System.getProperty("user.dir");
+ log.log(Priority.INFO, baseDir);
+ if (!baseDir.endsWith("product")) {
+ _prefix = "product/";
+ }
+ }
+ return _prefix;
+ }
+ /**
+ * Sets the jbossesb-properties.xml to use for test
+ */
+ public static void setESBPropertiesFileToUse()
+ {
+ //Set the jbossesb properties file in System, so we can pick up the one for testing
+ String jbossesbPropertiesFile = "jbossesb-unittest-properties.xml";
+// System.out.println("looking for prop file: " + jbossesbPropertiesFile);
+ System.setProperty("org.jboss.soa.esb.propertyFile", jbossesbPropertiesFile);
+ }
+
+}
More information about the jboss-svn-commits
mailing list