[jboss-svn-commits] JBL Code SVN: r7979 - in labs/jbossesb/trunk: product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr qa/junit/src/org/jboss/soa/esb/actions

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 30 02:17:14 EST 2006


Author: kurt.stam at jboss.com
Date: 2006-11-30 02:17:11 -0500 (Thu, 30 Nov 2006)
New Revision: 7979

Modified:
   labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java
Log:
applying patch from Dave Dunkin

Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java	2006-11-30 06:58:55 UTC (rev 7978)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java	2006-11-30 07:17:11 UTC (rev 7979)
@@ -31,7 +31,6 @@
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.Priority;
-import org.drools.FactHandle;
 import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
 import org.drools.WorkingMemory;
@@ -50,7 +49,7 @@
  */
 public class JBossRulesRouter extends ContentBasedRouter 
 {
-	private static Map<String,WorkingMemory> workingMemories=new ConcurrentHashMap<String,WorkingMemory>();
+	private static Map<String,RuleBase> ruleBases=new ConcurrentHashMap<String,RuleBase>();
 	private static Logger logger = Logger.getLogger(JBossRulesRouter.class);
 	/**
 	 * Route the message, where the routing rules are supplied as part of
@@ -88,22 +87,19 @@
 	{
 		List<String> destinationServices = new ArrayList<String>();
 		try {
-			WorkingMemory workingMemory = workingMemories.get(ruleSet);
-			if (workingMemory==null) {
+			RuleBase ruleBase = ruleBases.get(ruleSet);
+			if (ruleBase==null) {
 			    logger.log(Priority.INFO, "Reading ruleSet from file=" + ruleSet);
-				RuleBase ruleBase = readRuleBase(ruleSet, ruleLanguage);
-				workingMemory = ruleBase.newWorkingMemory();
-				workingMemories.put(ruleSet, workingMemory);
+			    ruleBase = readRuleBase(ruleSet, ruleLanguage);
+				ruleBases.put(ruleSet, ruleBase);
 			}
+			WorkingMemory workingMemory = ruleBase.newWorkingMemory();
 			logger.log(Priority.DEBUG, "Obtained message=" + message + " with ruleSet=" + ruleSet);
-			synchronized(workingMemory) {
-				workingMemory.setGlobal("destinationServices", destinationServices);
-				FactHandle factHandle = workingMemory.assertObject(message);
-				logger.log(Priority.INFO, "Fire the JBossRules Engine");
-				workingMemory.fireAllRules();
-				workingMemory.retractObject(factHandle);
-			}
-			destinationServices = (List) workingMemory.getGlobal("destinationServices");
+			workingMemory.setGlobal("destinationServices", destinationServices);
+			workingMemory.assertObject(message);
+			logger.log(Priority.INFO, "Fire the JBossRules Engine");
+			workingMemory.fireAllRules();
+			destinationServices = (List) workingMemory.getGlobal("destinationServices");  // is this needed?
 			logger.log(Priority.DEBUG, "Destination Services List: " + destinationServices);
 			Boolean isDeliverMessages = (Boolean) message.getProperties().getProperty(MessageRouter.DELIVER_MESSAGES);
 			//Deliver the message to their desitinations unless told not to.
@@ -111,7 +107,7 @@
 				deliverMessages(destinationServices, message);
 			}
 		} catch (Exception e) {
-			logger.log(Priority.ERROR, e.getMessage() + ". Message is not routed.", e);
+			logger.log(Priority.ERROR, e.toString() + ". Message is not routed.", e);
 			//Route to /dev/null?
 		}
 		return destinationServices;

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java	2006-11-30 06:58:55 UTC (rev 7978)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java	2006-11-30 07:17:11 UTC (rev 7979)
@@ -1,219 +1,215 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY 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 along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.soa.esb.actions;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.InputStream;
-import java.sql.DriverManager;
-import java.sql.Statement;
-import java.util.Collection;
-import java.util.Properties;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
-import org.jboss.soa.esb.listeners.message.EsbListenerController;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
-import org.jboss.soa.esb.services.routing.MessageRouter;
-import org.jboss.soa.esb.testutils.FileUtil;
-import org.jboss.soa.esb.testutils.HsqldbUtil;
-import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Test CbrProxyAction class. First this test brings up a (hsqldb) database, and the registry. It them 
- * brings up the Content Based Router - defined in the CbrProxyActionUnitTest.xml. It then goes on to 
- * read the CbrProxyActionUnitTestFragment.xml, on which we perform the tests.
- * 
- * @author kurt.stam at redhat.com
- */
-public class CbrProxyActionUnitTest  
-{
-	private static Logger logger = Logger.getLogger(CbrProxyActionUnitTest.class);
-	private static EsbListenerController _proc = null;
-    private static String mDbDriver;
-	private static String mDbUrl;
-	private static String mDbUsername;
-	private static String mDbPassword;
-	
-	@Test
-    public void routeAndDeliver() 
-    {
-		try {
-			Message message = MessageFactory.getInstance().getMessage();
-			message.getBody().setContents("Body".getBytes());
-			ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("CbrProxyActionUnitTestFragment1.xml"));
-	        
-	        ActionProcessingPipeline chain = null;
-	    	
-			try	{ 
-				chain = new ActionProcessingPipeline(message,config); 
-			}catch (IllegalArgumentException e){
-				e.printStackTrace();
-			} catch (ConfigurationException e){
-				e.printStackTrace();
-			}
-			new Thread(chain).start();
-			//give the CBR some time to finish
-			Thread.sleep(5000);
-		} catch (Exception e) {
-			e.printStackTrace();
-			assertTrue(false);
-		}
-    }
-	
-	@Test
-    public void route()
-    {
-		try {
-			Message message = MessageFactory.getInstance().getMessage();
-			message.getBody().setContents("Body".getBytes());
-			ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("CbrProxyActionUnitTestFragment2.xml"));
-	        
-	        ActionProcessingPipeline chain = null;
-	    	
-			try	{ 
-				chain = new ActionProcessingPipeline(message,config); 
-			}catch (IllegalArgumentException e){
-				e.printStackTrace();
-			} catch (ConfigurationException e){
-				e.printStackTrace();
-			}
-			new Thread(chain).start();
-			Thread.sleep(5000);
-			//The message coming should have the Collection of destinationServices as a property.
-			Collection destinationServices = (Collection) chain.getMessage().getProperties().getProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST);
-			String firstDestination = (String) destinationServices.iterator().next();
-			logger.info("Destination=" + firstDestination);
-			assertEquals("test_category:JBOSS_XMLDestination",firstDestination);
-			
-			//give the CBR some time to finish
-			
-		} catch (Exception e) {
-			e.printStackTrace();
-			assertTrue(false);
-		}
-    }
-	
-	
-	
-	@BeforeClass
-	public static void runBeforeAllTests()
-	{
-		try {
-			DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product","../product") + "etc/test/resources/log4j.xml");
-			TestEnvironmentUtil.setESBPropertiesFileToUse("product","../product");
-			//Set the juddi properties file in System so juddi will pick it up later and use the test values.
-			String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-qatest.properties";
-			System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
-			//Read this properties file to get the db connection string
-			Properties props = new Properties();
-			InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
-			props.load(inStream);
-			mDbDriver    = props.getProperty("juddi.jdbcDriver");
-			mDbUrl       = props.getProperty("juddi.jdbcUrl");
-			mDbUsername  = props.getProperty("juddi.jdbcUsername");
-			mDbPassword  = props.getProperty("juddi.jdbcPassword");
-			
-			String database="not tested yet";
-			if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
-				database = "hsqldb";
-				//Bring up hsql on default port 9001
-				HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir("product","../product") + "build/hsqltestdb", "juddi");
-			} else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
-				database = "mysql";
-			} //add and test your own database..
-			
-			//Get the registry-schema create scripts
-			String sqlDir = TestEnvironmentUtil.getUserDir("product","../product") + "install/jUDDI-registry/sql/" + database + "/";
-			//Drop what is there now, if exists. We want to start fresh.
-			String sqlDropCmd      = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
-			String sqlCreateCmd    = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
-			String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
-			
-			try {
-				Class.forName(mDbDriver);
-			} catch (Exception e) {
-				System.out.println("ERROR: failed to load " + database + " JDBC driver.");
-				e.printStackTrace();
-				return;
-			}
-			java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
-			Statement stmnt = con.createStatement();
-			System.out.println("Dropping the schema if exist");
-			stmnt.execute(sqlDropCmd);
-			System.out.println("Creating the juddi-schema");
-			stmnt.execute(sqlCreateCmd);
-			System.out.println("Adding the jbossesb publisher");
-			stmnt.execute(sqlInsertPubCmd);
-			
-			//Now we can bring up the ContentBasedRouter
-			logger.info("Testing to see if we can instantiate one");
-			String deploymentConfigFile = TestEnvironmentUtil.getUserDir("qa") 
-				+ "junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml";
-			_proc = new EsbListenerController(deploymentConfigFile);
-			new Thread(_proc).start();
-			// give the listener time to register
-			Thread.sleep(5000);
-			
-		} catch (Throwable e) {
-			e.printStackTrace();
-			System.out.println("We should stop testing, since we don't have a db.");
-			assertTrue(false);
-		}
-	}
-	
-	/**
-	 * Shutdown the database
-	 * @throws Exception
-	 */
-	@AfterClass
-	public static void runAfterAllTests() throws Exception 
-	{
-		//Shutdown the CBR Service
-        //Increase Sleep for debugging
-		Thread.sleep(200);
-		_proc.requestEnd();
-        //Give the controller time to finish
-		Thread.sleep(2000);
-		EsbListenerController.State oS = _proc.getState();
-		System.out.println("Exit state = "+oS.toString());
-		if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
-			HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
-		}
-	}
-	
-	public static junit.framework.Test suite() {
-		return new JUnit4TestAdapter(CbrProxyActionUnitTest.class);
-	}
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.InputStream;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.Properties;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
+import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.routing.MessageRouter;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test CbrProxyAction class. First this test brings up a (hsqldb) database, and the registry. It them 
+ * brings up the Content Based Router - defined in the CbrProxyActionUnitTest.xml. It then goes on to 
+ * read the CbrProxyActionUnitTestFragment.xml, on which we perform the tests.
+ * 
+ * @author kurt.stam at redhat.com
+ */
+public class CbrProxyActionUnitTest  
+{
+	private static Logger logger = Logger.getLogger(CbrProxyActionUnitTest.class);
+	private static EsbListenerController _proc = null;
+    private static String mDbDriver;
+	private static String mDbUrl;
+	private static String mDbUsername;
+	private static String mDbPassword;
+	
+	@Test
+    public void routeAndDeliver() throws Exception
+    {
+		Message message = MessageFactory.getInstance().getMessage();
+		message.getBody().setContents("Body".getBytes());
+		ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("CbrProxyActionUnitTestFragment1.xml"));
+        
+        ActionProcessingPipeline chain = null;
+    	
+		try	{ 
+			chain = new ActionProcessingPipeline(message,config); 
+		}catch (IllegalArgumentException e){
+			e.printStackTrace();
+			fail(e.toString());
+		} catch (ConfigurationException e){
+			e.printStackTrace();
+			fail(e.toString());
+		}
+		Thread t = new Thread(chain);
+		t.start();
+		//give the CBR some time to finish
+		t.join(5000);
+    }
+	
+	@Test
+    public void route() throws Exception
+    {
+		Message message = MessageFactory.getInstance().getMessage();
+		message.getBody().setContents("Body".getBytes());
+		ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("CbrProxyActionUnitTestFragment2.xml"));
+        
+        ActionProcessingPipeline chain = null;
+    	
+		try	{ 
+			chain = new ActionProcessingPipeline(message,config); 
+		}catch (IllegalArgumentException e){
+			e.printStackTrace();
+			fail(e.toString());
+		} catch (ConfigurationException e){
+			e.printStackTrace();
+			fail(e.toString());
+		}
+		Thread t = new Thread(chain);
+		t.start();
+		//give the CBR some time to finish
+		t.join(5000);
+		//The message coming should have the Collection of destinationServices as a property.
+		Collection destinationServices = (Collection) chain.getMessage().getProperties().getProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST);
+		assertNotNull("Destination service list is null", destinationServices);
+		String firstDestination = (String) destinationServices.iterator().next();
+		logger.info("Destination=" + firstDestination);
+		assertEquals("test_category:JBOSS_XMLDestination",firstDestination);
+    }
+	
+	
+	
+	@BeforeClass
+	public static void runBeforeAllTests()
+	{
+		try {
+			DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product","../product") + "etc/test/resources/log4j.xml");
+			TestEnvironmentUtil.setESBPropertiesFileToUse("product","../product");
+			//Set the juddi properties file in System so juddi will pick it up later and use the test values.
+			String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-qatest.properties";
+			System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
+			//Read this properties file to get the db connection string
+			Properties props = new Properties();
+			InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
+			props.load(inStream);
+			mDbDriver    = props.getProperty("juddi.jdbcDriver");
+			mDbUrl       = props.getProperty("juddi.jdbcUrl");
+			mDbUsername  = props.getProperty("juddi.jdbcUsername");
+			mDbPassword  = props.getProperty("juddi.jdbcPassword");
+			
+			String database="not tested yet";
+			if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+				database = "hsqldb";
+				//Bring up hsql on default port 9001
+				HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir("product","../product") + "build/hsqltestdb", "juddi");
+			} else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
+				database = "mysql";
+			} //add and test your own database..
+			
+			//Get the registry-schema create scripts
+			String sqlDir = TestEnvironmentUtil.getUserDir("product","../product") + "install/jUDDI-registry/sql/" + database + "/";
+			//Drop what is there now, if exists. We want to start fresh.
+			String sqlDropCmd      = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
+			String sqlCreateCmd    = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
+			String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
+			
+			try {
+				Class.forName(mDbDriver);
+			} catch (Exception e) {
+				System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+				e.printStackTrace();
+				return;
+			}
+			java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+			Statement stmnt = con.createStatement();
+			System.out.println("Dropping the schema if exist");
+			stmnt.execute(sqlDropCmd);
+			System.out.println("Creating the juddi-schema");
+			stmnt.execute(sqlCreateCmd);
+			System.out.println("Adding the jbossesb publisher");
+			stmnt.execute(sqlInsertPubCmd);
+			
+			//Now we can bring up the ContentBasedRouter
+			logger.info("Testing to see if we can instantiate one");
+			String deploymentConfigFile = TestEnvironmentUtil.getUserDir("qa") 
+				+ "junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml";
+			_proc = new EsbListenerController(deploymentConfigFile);
+			new Thread(_proc).start();
+			// give the listener time to register
+			Thread.sleep(5000);
+			
+		} catch (Throwable e) {
+			e.printStackTrace();
+			System.out.println("We should stop testing, since we don't have a db.");
+			fail(e.toString());
+		}
+	}
+	
+	/**
+	 * Shutdown the database
+	 * @throws Exception
+	 */
+	@AfterClass
+	public static void runAfterAllTests() throws Exception 
+	{
+		//Shutdown the CBR Service
+        //Increase Sleep for debugging
+		Thread.sleep(200);
+		_proc.requestEnd();
+        //Give the controller time to finish
+		Thread.sleep(2000);
+		EsbListenerController.State oS = _proc.getState();
+		System.out.println("Exit state = "+oS.toString());
+		if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+			HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+		}
+	}
+	
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(CbrProxyActionUnitTest.class);
+	}
+}




More information about the jboss-svn-commits mailing list