[jboss-svn-commits] JBL Code SVN: r11863 - in labs/jbossesb/workspace/dbevenius/product/core/listeners: tests/src/org/jboss/soa/esb/listeners/gateway and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue May 15 13:37:56 EDT 2007


Author: beve
Date: 2007-05-15 13:37:55 -0400 (Tue, 15 May 2007)
New Revision: 11863

Added:
   labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListener.java
   labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListenerTest.java
   labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTestUtil.java
Modified:
   labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java
   labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener_ReadOnlyStrategyUnitTest.java
   labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategyTest.java
   labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTest.java
   labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/ftpfile_cache_test.xml
Log:
Added a TreeCacheListenern implementation that will remove the nodes data upon eviction. This is a work in progress
and the listener is currently not used. I need to add tests to verify what happens if all nodes in the cache cluster
go down. Will the eviction period start over. I'll document my findings. Mainly checking this in as I want to merge 
in changes from main into my workspace


Added: labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListener.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListener.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListener.java	2007-05-15 17:37:55 UTC (rev 11863)
@@ -0,0 +1,82 @@
+/*
+ * 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.listeners.gateway.remotestrategies.cache;
+
+import org.apache.log4j.Logger;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.TreeCache;
+import org.jboss.cache.TreeCacheListener;
+import org.jgroups.View;
+
+/**
+ * This listener will upon node eviction events delete the 
+ * node from the cache. 
+ * This listener should be used in combination with a cache loader 
+ * so that it is possible to set an eviction policy and when nodes
+ * are evicted they are also deleted from the cache loaders store
+ * 
+ * @author Daniel Bevenius
+ *
+ */
+public class DeleteOnEvictTreeCacheListener implements TreeCacheListener
+{
+	private Logger log = Logger .getLogger( DeleteOnEvictTreeCacheListener.class );
+	
+	private TreeCache treeCache;
+	
+	public DeleteOnEvictTreeCacheListener( TreeCache treeCache ) 
+	{
+		if ( treeCache == null )
+			throw new IllegalArgumentException( "treeCache must not be null" );
+		
+		this.treeCache = treeCache;
+	}
+
+
+	/**
+	 * Will remove from the passed in fqn upon being
+	 * evicted from the cache.
+	 */
+	public void nodeEvicted( Fqn fqn ) 
+	{
+		try
+		{
+			treeCache.removeData( fqn );
+			log.debug( "removed fqn : " + fqn );
+		} 
+		catch (CacheException e)
+		{
+			log.error( "Exception while trying to remove data for fqn : " + fqn , e );
+		}
+	}
+	
+	public void cacheStarted(TreeCache arg0) {}
+	public void cacheStopped(TreeCache arg0) {}
+	public void nodeCreated(Fqn arg0) {}
+	public void nodeLoaded(Fqn arg0) {}
+	public void nodeModified(Fqn arg0) {}
+	public void nodeRemoved(Fqn arg0) {}
+	public void nodeVisited(Fqn arg0) {}
+	public void viewChange(View arg0) {}
+
+}

Modified: labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java	2007-05-15 17:24:25 UTC (rev 11862)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java	2007-05-15 17:37:55 UTC (rev 11863)
@@ -11,6 +11,7 @@
 import org.jboss.cache.CacheException;
 import org.jboss.cache.PropertyConfigurator;
 import org.jboss.cache.TreeCache;
+import org.jboss.cache.TreeCacheListener;
 
 /**
  * Implements a cache of file names which can be replicated in a cluster. 
@@ -216,5 +217,14 @@
 			log.warn( "Error while trying to close Closable", e);
 		}
 	}
+
+	public void addCacheListener( TreeCacheListener listener )
+	{
+		if ( listener == null )
+			return;
+		
+		treeCache.addTreeCacheListener( listener );
+	}
+
 }
 

Modified: labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener_ReadOnlyStrategyUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener_ReadOnlyStrategyUnitTest.java	2007-05-15 17:24:25 UTC (rev 11862)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener_ReadOnlyStrategyUnitTest.java	2007-05-15 17:37:55 UTC (rev 11863)
@@ -39,6 +39,7 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.gateway.remotestrategies.ReadOnlyRemoteFileSystemStrategy;
 import org.jboss.soa.esb.listeners.gateway.remotestrategies.RemoteFileSystemStrategy;
+import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.FtpFileCacheTestUtil;
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
 import org.jboss.soa.esb.services.registry.RegistryException;
 import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
@@ -177,8 +178,8 @@
 	public static ConfigTree createConfigTree()
 	{
 		ConfigTree configTree = RemoteGatewayListenerUnitTest.createConfigTree();
-		configTree.setAttribute( RemoteGatewayListener.REMOTE_FILE_SYSTEM_STRATEGY_CLASS, ReadOnlyRemoteFileSystemStrategy.class.getName());
-		configTree.setAttribute( RemoteGatewayListener.REMOTE_FILE_SYSTEM_STRATEGY_CONFIG_FILE, getJBossCacheConfigFile() );
+		configTree.setAttribute( RemoteGatewayListener.REMOTE_FILE_SYSTEM_STRATEGY_CLASS, ReadOnlyRemoteFileSystemStrategy.class.getName() );
+		configTree.setAttribute( RemoteGatewayListener.REMOTE_FILE_SYSTEM_STRATEGY_CONFIG_FILE, FtpFileCacheTestUtil.getCacheConfigFile() );
 		return configTree;
 	}
 	
@@ -189,29 +190,6 @@
 		return ftpServer;
 	}
 	
-	private static String getJBossCacheConfigFile()
-	{
-		String configFile = TestEnvironmentUtil.getBaseDir() + File.separator + 
-							"core" + File.separator + 
-							"listeners" + File.separator + 
-							"tests" + File.separator + 
-							"src" + File.separator + 
-							"org" + File.separator + 
-							"jboss" + File.separator + 
-							"soa" + File.separator + 
-							"esb" + File.separator + 
-							"listeners" + File.separator + 
-							"gateway" + File.separator + 
-							"remotestrategies" + File.separator + 
-							"cache" + File.separator + 
-							"ftpfile_cache_test.xml";
-		
-		if ( ! new File ( configFile ).exists() )
-			fail( "Could not locate the jboss cache config file: " +  configFile );
-		
-		return configFile;
-	}
-	
 	/*
 	 * Just here to help Ant to find annotated test.
 	 */

Modified: labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategyTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategyTest.java	2007-05-15 17:24:25 UTC (rev 11862)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategyTest.java	2007-05-15 17:37:55 UTC (rev 11863)
@@ -9,6 +9,7 @@
 import org.apache.log4j.Logger;
 import org.jboss.cache.CacheException;
 import org.jboss.soa.esb.listeners.gateway.GatewayException;
+import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.FtpFileCacheTestUtil;
 import org.jboss.soa.esb.testutils.HsqldbUtil;
 import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
 import org.junit.AfterClass;
@@ -107,10 +108,10 @@
 		HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir() + "build" + File.separator + "hsqltestdb", "ftpcache");
 		
 		strategy = new ReadOnlyRemoteFileSystemStrategy();
-		strategy.init( getConfigFile() );
+		strategy.init( FtpFileCacheTestUtil.getCacheConfigFile() );
 		
 		strategy2 = new ReadOnlyRemoteFileSystemStrategy();
-		strategy2.init( getConfigFile() );
+		strategy2.init( FtpFileCacheTestUtil.getCacheConfigFile() );
 	}
 		
 	private static void registerHsqlDriver()
@@ -132,27 +133,4 @@
 		strategy2.stop();
 	}
 	
-	private static String getConfigFile()
-	{
-		String configFile = TestEnvironmentUtil.getBaseDir() + File.separator + 
-							"core" + File.separator + 
-							"listeners" + File.separator + 
-							"tests" + File.separator + 
-							"src" + File.separator + 
-							"org" + File.separator + 
-							"jboss" + File.separator + 
-							"soa" + File.separator + 
-							"esb" + File.separator + 
-							"listeners" + File.separator + 
-							"gateway" + File.separator + 
-							"remotestrategies" + File.separator + 
-							"cache" + File.separator + 
-							"ftpfile_cache_test.xml";
-		
-		if ( ! new File ( configFile ).exists() )
-			fail( "Could not locate the jboss cache config file: " +  configFile );
-		
-		return configFile;
-	}
-	
 }

Added: labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListenerTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListenerTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/DeleteOnEvictTreeCacheListenerTest.java	2007-05-15 17:37:55 UTC (rev 11863)
@@ -0,0 +1,88 @@
+/*
+ * 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.listeners.gateway.remotestrategies.cache;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.TreeCache;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * 
+ * @author Daniel Bevenius
+ *
+ */
+public class DeleteOnEvictTreeCacheListenerTest 
+{
+	private static DeleteOnEvictTreeCacheListener listener;
+	private static TreeCache treeCache;
+	
+	private static final String FQN = "test/junit";
+	
+	@Test( expected=IllegalArgumentException.class )
+	public void constructor()
+	{
+		new DeleteOnEvictTreeCacheListener( null );
+	}
+	
+	@Test
+	public void nodeEvict() throws CacheException
+	{
+		String key = "testKey";
+		String value = "testValue";
+		Fqn fqnTest = new Fqn ( new String[] { FQN, key, value} );
+		
+		treeCache.put( FQN, key, value );
+		Node node = treeCache.get( fqnTest );
+		assertTrue( "The value should have been added!",  treeCache.exists( FQN, key ) );
+		
+		listener.nodeEvicted( fqnTest );
+		node = treeCache.get( fqnTest );
+		assertFalse( "The value should have been removed upon eviction!",  treeCache.exists( fqnTest ) );
+		
+		node = treeCache.get( fqnTest );
+		assertNull ( "The node should have been removed from the cache store", node );
+	}
+	
+	@BeforeClass
+	public static void classSetup() throws Exception
+	{
+		treeCache = new TreeCache();
+		listener = new DeleteOnEvictTreeCacheListener( treeCache );
+		treeCache.addTreeCacheListener( listener );
+		FtpFileCacheTestUtil.createTreeCache( treeCache, FtpFileCacheTestUtil.getCacheConfigFile() );
+		treeCache.start();
+	}
+	
+	public static junit.framework.Test suite() 
+	{
+		return new JUnit4TestAdapter( FtpFileCacheTest.class );
+	}
+	
+}

Modified: labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTest.java	2007-05-15 17:24:25 UTC (rev 11862)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTest.java	2007-05-15 17:37:55 UTC (rev 11863)
@@ -30,9 +30,6 @@
 {
 	private static Logger log = Logger.getLogger(FtpFileCacheTest.class);
 	
-	@SuppressWarnings("unused")
-	private static String configFile;
-	
 	private static FtpFileCache ftpfileCache;
 
 	@Test
@@ -67,6 +64,19 @@
 		}
 	}
 	
+	@Test 
+	public void addCacheListenerNegative()
+	{
+		try
+		{
+			ftpfileCache.addCacheListener( null );
+		}
+		catch ( Exception e )
+		{
+			fail("Should be ok to pass a null listener! Exception was : "+ e.getMessage() ); 
+		}
+	}
+	
 	@Test
 	public void fileExists() throws CacheException
 	{
@@ -91,12 +101,11 @@
 	@BeforeClass
 	public static void classSetup() throws Exception
 	{
-		configFile = getJBossCacheConfigFile();
 		
 		registerHsqlDriver();
 		HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir() + "build" + File.separator + "hsqltestdb", "ftpcache");
 		
-		ftpfileCache = new FtpFileCache ( getJBossCacheConfigFile() );
+		ftpfileCache = new FtpFileCache ( FtpFileCacheTestUtil.getCacheConfigFile() );
 		ftpfileCache.start();
 	}
 	
@@ -112,29 +121,6 @@
 		}
 	}
 	
-	private static String getJBossCacheConfigFile()
-	{
-		String configFile = TestEnvironmentUtil.getBaseDir() + File.separator + 
-							"core" + File.separator + 
-							"listeners" + File.separator + 
-							"tests" + File.separator + 
-							"src" + File.separator + 
-							"org" + File.separator + 
-							"jboss" + File.separator + 
-							"soa" + File.separator + 
-							"esb" + File.separator + 
-							"listeners" + File.separator + 
-							"gateway" + File.separator + 
-							"remotestrategies" + File.separator + 
-							"cache" + File.separator + 
-							"ftpfile_cache_test.xml";
-		
-		if ( ! new File ( configFile ).exists() )
-			fail( "Could not locate the jboss cache config file: " +  configFile );
-		
-		return configFile;
-	}
-
 	@AfterClass
 	public static void classTearDown() throws Exception 
 	{

Added: labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTestUtil.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTestUtil.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheTestUtil.java	2007-05-15 17:37:55 UTC (rev 11863)
@@ -0,0 +1,72 @@
+/*
+ * 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.listeners.gateway.remotestrategies.cache;
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+import org.jboss.cache.ConfigureException;
+import org.jboss.cache.PropertyConfigurator;
+import org.jboss.cache.TreeCache;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+
+/**
+ * Simple helper class with util method for getting a cache config
+ * file.
+ * Only created this to save duplicating the getCacheConfigFile method.
+ * 
+ * @author Daniel Bevenius				
+ *
+ */
+public class FtpFileCacheTestUtil
+{
+	public static String getCacheConfigFile()
+	{
+		String configFile = TestEnvironmentUtil.getBaseDir() + File.separator + 
+							"core" + File.separator + 
+							"listeners" + File.separator + 
+							"tests" + File.separator + 
+							"src" + File.separator + 
+							"org" + File.separator + 
+							"jboss" + File.separator + 
+							"soa" + File.separator + 
+							"esb" + File.separator + 
+							"listeners" + File.separator + 
+							"gateway" + File.separator + 
+							"remotestrategies" + File.separator + 
+							"cache" + File.separator + 
+							"ftpfile_cache_test.xml";
+		
+		if ( ! new File ( configFile ).exists() )
+			fail( "Could not locate the jboss cache config file: " +  configFile );
+		
+		return configFile;
+	}
+	
+	public static void createTreeCache( TreeCache treeCache, String pathToConfigFile ) throws ConfigureException
+	{
+		PropertyConfigurator configurator = new PropertyConfigurator();
+		configurator.configure( treeCache, pathToConfigFile );
+	}
+
+}

Modified: labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/ftpfile_cache_test.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/ftpfile_cache_test.xml	2007-05-15 17:24:25 UTC (rev 11862)
+++ labs/jbossesb/workspace/dbevenius/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/ftpfile_cache_test.xml	2007-05-15 17:37:55 UTC (rev 11863)
@@ -98,7 +98,7 @@
 		<attribute name="CacheLoaderConfiguration">
 	        <config>
 				<!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
-				<passivation>false</passivation>
+				<passivation>true</passivation>
 				
 				<!-- comma delimited FQNs to preload -->
 				<preload>/ftp/cache</preload>




More information about the jboss-svn-commits mailing list