[jboss-svn-commits] JBL Code SVN: r7146 - 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 26 11:24:14 EDT 2006


Author: daniel.brum at jboss.com
Date: 2006-10-26 11:24:12 -0400 (Thu, 26 Oct 2006)
New Revision: 7146

Added:
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreClient.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java
Log:


Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreClient.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreClient.java	2006-10-26 14:55:42 UTC (rev 7145)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreClient.java	2006-10-26 15:24:12 UTC (rev 7146)
@@ -0,0 +1,93 @@
+/*
+ * 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.Random;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+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;
+
+
+
+/**
+ * @author dbrum
+ *
+ */
+public class MessageStoreClient implements Runnable{
+	
+	private static Logger logger = Logger.getLogger(MessageStoreTest.class);
+
+	
+	public void run() {
+		long startTime=System.currentTimeMillis();
+		
+		int requestors = 1000;	//number of persist calls to make
+		Vector<URI> writeList = new Vector<URI>();
+		
+//		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)]);
+			if (uid != null)
+				writeList.add(uid);
+			else
+				System.out.println("null was found... not adding uid to list...");
+		}
+		
+		logger.info("total messages persisted to db: " + (writeList.size()));
+		
+		//loop back reading the messages from the db
+		Vector<Message> readList = new Vector<Message> ();
+		for (int x=0; x<writeList.size(); x++) {
+			try {
+				readList.add(store.getMessage(writeList.get(x)));				
+			} catch (Exception e) {
+				logger.error(e);
+			}
+		}
+		logger.info("total messages read from db: " + (readList.size()));		
+		logger.info("time to finish write/read for this client: " + (System.currentTimeMillis()-startTime) + " milliseconds.");
+
+	}
+}

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-26 14:55:42 UTC (rev 7145)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java	2006-10-26 15:24:12 UTC (rev 7146)
@@ -0,0 +1,152 @@
+/*
+ * 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 junit.framework.TestCase;
+
+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;
+
+/**
+ * @author dbrum
+ *
+ */
+public class MessageStoreTest extends TestCase {
+	private static Logger logger = Logger.getLogger(MessageStoreTest.class);
+	
+	public void testMultiClientLoad() throws Exception {
+		TestUtil.setESBPropertiesFileToUse();
+		MessageStoreTest.runBeforeAllTests();
+		int clients = 5;
+		
+		Thread[] xx = new Thread[clients];
+		for (int i=0; i<clients; i++) {
+			xx[i] = new Thread(new MessageStoreClient());
+		}
+		
+		for (int i=0; i<clients; i++) {
+			xx[i].start();
+		}
+		
+		//clean up the threads
+		for (int i=0; i<clients; i++) {
+			xx[i] = null;
+		}
+		
+	}
+	
+	public void testSingleLoad() throws Exception {
+		long startTime=System.currentTimeMillis();
+		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)]);	
+			if (uid == null) 
+				System.out.println("null returned from addMessage() call to uid");
+			else
+				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: " + (uriList.size()));
+		logger.info("time to finish write/read for this client: " + (System.currentTimeMillis() - startTime) + " milliseconds.");
+		
+		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[]) {
+//		//fire up the DB connections into the pool and give it 5 seconds to establish the connections
+//		DBConnectionManager2.getInstance();		
+//		
+//		MessageStoreTest test = new MessageStoreTest();
+//		try {
+////			test.testSingleLoad();
+//			test.testMultiClientLoad();
+//		} catch (Exception e) {
+//			// TODO Auto-generated catch block
+//			e.printStackTrace();
+//		}
+//	}
+	
+	
+}




More information about the jboss-svn-commits mailing list