Author: manik.surtani(a)jboss.com
Date: 2007-08-15 06:43:05 -0400 (Wed, 15 Aug 2007)
New Revision: 4287
Added:
cacheloader_migration/trunk/README.txt
cacheloader_migration/trunk/assembly.xml
cacheloader_migration/trunk/pom.xml
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
cacheloader_migration/trunk/src/test/java/org/jboss/cache/misc/
cacheloader_migration/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
cacheloader_migration/trunk/src/test/resources/
cacheloader_migration/trunk/src/test/resources/cache-jdbc.properties
cacheloader_migration/trunk/src/test/resources/log4j.xml
Modified:
cacheloader_migration/trunk/src/main/java/org/jboss/cache/loader/TransformingJDBCCacheLoader.java
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingCacheLoaderTestBase.java
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingFileCacheLoaderTest.java
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingJDBCCacheLoaderTest.java
Log:
Moved to standalone module
Added: cacheloader_migration/trunk/README.txt
===================================================================
--- cacheloader_migration/trunk/README.txt (rev 0)
+++ cacheloader_migration/trunk/README.txt 2007-08-15 10:43:05 UTC (rev 4287)
@@ -0,0 +1,7 @@
+Usage
+
+mvn compile - to compile srcs
+mvn test - to run tests
+mvn package - to build the distribution
+mvn install - to install to local repository
+mvn deploy - to deploy this to public repositories
Added: cacheloader_migration/trunk/assembly.xml
===================================================================
--- cacheloader_migration/trunk/assembly.xml (rev 0)
+++ cacheloader_migration/trunk/assembly.xml 2007-08-15 10:43:05 UTC (rev 4287)
@@ -0,0 +1,55 @@
+<assembly>
+ <id>all</id>
+
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <includeBaseDirectory>true</includeBaseDirectory>
+
+ <fileSets>
+
+ <!-- code -->
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory/>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+
+ <!-- examples -->
+ <fileSet>
+ <directory>src/examples</directory>
+ <outputDirectory>examples</outputDirectory>
+ </fileSet>
+
+ <!-- srcs -->
+ <fileSet>
+ <directory>src/main/java</directory>
+ <outputDirectory>src</outputDirectory>
+ </fileSet>
+
+ <!-- tests -->
+ <fileSet>
+ <directory>src/test/java</directory>
+ <outputDirectory>test</outputDirectory>
+ </fileSet>
+
+ <!-- test resources -->
+ <fileSet>
+ <directory>src/test/resources</directory>
+ <outputDirectory>test</outputDirectory>
+ </fileSet>
+
+ </fileSets>
+
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>lib</outputDirectory>
+
<outputFileNameMapping>${artifactId}.${extension}</outputFileNameMapping>
+ <unpack>false</unpack>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
Added: cacheloader_migration/trunk/pom.xml
===================================================================
--- cacheloader_migration/trunk/pom.xml (rev 0)
+++ cacheloader_migration/trunk/pom.xml 2007-08-15 10:43:05 UTC (rev 4287)
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <properties>
+ <jbosscache-core-version>2.0.0</jbosscache-core-version>
+ </properties>
+ <parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-common-parent</artifactId>
+ <version>1.0</version>
+ </parent>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-cacheloader-migration</artifactId>
+ <version>${jbosscache-core-version}</version>
+ <name>JBoss Cache - CacheLoader Migration</name>
+ <description>JBoss Cache - CacheLoader Migration utility package for migrating
data stores from JBoss Cache 1.x
+ format to 2.x format.
+ </description>
+ <packaging>jar</packaging>
+ <dependencies>
+ <!-- dependency on just JBoss Cache 2.0.0 - perhaps we should change this to
2.1.0 as soon as we can. -->
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-cache</artifactId>
+ <version>2.0.0.GA</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-1</version>
+ <executions>
+ <execution>
+ <id>assemble</id>
+ <phase>install</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly.xml</descriptor>
+ </descriptors>
+
<finalName>${artifactId}-${jbosscache-core-version}</finalName>
+ <outputDirectory>target/distribution</outputDirectory>
+ <workDirectory>target/assembly/work</workDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Modified:
cacheloader_migration/trunk/src/main/java/org/jboss/cache/loader/TransformingJDBCCacheLoader.java
===================================================================
---
cacheloader_migration/trunk/src/main/java/org/jboss/cache/loader/TransformingJDBCCacheLoader.java 2007-08-15
09:26:13 UTC (rev 4286)
+++
cacheloader_migration/trunk/src/main/java/org/jboss/cache/loader/TransformingJDBCCacheLoader.java 2007-08-15
10:43:05 UTC (rev 4287)
@@ -6,10 +6,10 @@
*/
package org.jboss.cache.loader;
-import org.jboss.invocation.MarshalledValue;
+import org.jboss.aop.util.MarshalledValue;
+import java.io.InputStream;
import java.io.ObjectInputStream;
-import java.io.InputStream;
import java.rmi.MarshalledObject;
/**
@@ -27,11 +27,11 @@
Object marshalledNode = ois.readObject();
// de-marshall value if possible
- if(marshalledNode instanceof MarshalledValue)
+ if (marshalledNode instanceof MarshalledValue)
{
return ((MarshalledValue) marshalledNode).get();
}
- else if(marshalledNode instanceof MarshalledObject)
+ else if (marshalledNode instanceof MarshalledObject)
{
return ((MarshalledObject) marshalledNode).get();
}
Added:
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
===================================================================
---
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
(rev 0)
+++
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java 2007-08-15
10:43:05 UTC (rev 4287)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+package org.jboss.cache.loader;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.xml.XmlHelper;
+import org.w3c.dom.Element;
+
+/**
+ * Very basic test case that provides methods to create a cache loader config.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
+ */
+public abstract class AbstractCacheLoaderTestBase
+{
+ protected final Log log = LogFactory.getLog(getClass());
+
+ protected CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String
cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean
shared) throws Exception
+ {
+ return getSingleCacheLoaderConfig(preload, cacheloaderClass, properties, async,
fetchPersistentState, shared, false);
+ }
+
+ protected CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String
cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean
shared, boolean purgeOnStartup) throws Exception
+ {
+ return getSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties,
async, fetchPersistentState, shared, purgeOnStartup);
+ }
+
+ protected CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String
preload, String cacheloaderClass, String properties, boolean async, boolean
fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
+ {
+ String xml = "<config>\n" +
+ "<passivation>" + passivation +
"</passivation>\n" +
+ "<preload>" + preload + "</preload>\n"
+
+ "<cacheloader>\n" +
+ "<class>" + cacheloaderClass +
"</class>\n" +
+ "<properties>" + properties +
"</properties>\n" +
+ "<async>" + async + "</async>\n" +
+ "<shared>" + shared + "</shared>\n" +
+ "<fetchPersistentState>" + fetchPersistentState +
"</fetchPersistentState>\n" +
+ "<purgeOnStartup>" + purgeOnStartup +
"</purgeOnStartup>\n" +
+ "</cacheloader>\n" +
+ "</config>";
+ Element element = XmlHelper.stringToElement(xml);
+ return XmlConfigurationParser.parseCacheLoaderConfig(element);
+ }
+}
Modified:
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingCacheLoaderTestBase.java
===================================================================
---
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingCacheLoaderTestBase.java 2007-08-15
09:26:13 UTC (rev 4286)
+++
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingCacheLoaderTestBase.java 2007-08-15
10:43:05 UTC (rev 4287)
@@ -23,7 +23,7 @@
private static final String CURRENCY = "currency";
private static final String POPULATION = "population";
private static final String AREA = "area";
- private static final String EUROPE_NODE = "Europe";
+ private static final String EUROPE_NODE = "Europe";
protected CacheImpl createCache() throws Exception
{
@@ -65,22 +65,22 @@
protected void checkData(CacheImpl cache) throws Exception
{
- assertEquals("Vienna", cache.get("Europe/Austria", CAPITAL));
- assertEquals("Euro", cache.get("Europe/Austria", CURRENCY));
- assertEquals(8184691, cache.get("Europe/Austria", POPULATION));
+ assert "Vienna".equals(cache.get("Europe/Austria", CAPITAL));
+ assert "Euro".equals(cache.get("Europe/Austria", CURRENCY));
+ assert cache.get("Europe/Austria", POPULATION).equals(8184691);
- assertEquals("London", cache.get("Europe/England", CAPITAL));
- assertEquals("British Pound", cache.get("Europe/England",
CURRENCY));
- assertEquals(60441457, cache.get("Europe/England", POPULATION));
+ assert "London".equals(cache.get("Europe/England", CAPITAL));
+ assert "British Pound".equals(cache.get("Europe/England",
CURRENCY));
+ assert cache.get("Europe/England", POPULATION).equals(60441457);
- assertEquals("Tirana", cache.get("Europe/Albania", CAPITAL));
- assertEquals("Lek", cache.get("Europe/Albania", CURRENCY));
- assertEquals(3563112, cache.get("Europe/Albania", POPULATION));
- assertEquals(28748, cache.get("Europe/Albania", AREA));
+ assert "Tirana".equals(cache.get("Europe/Albania", CAPITAL));
+ assert "Lek".equals(cache.get("Europe/Albania", CURRENCY));
+ assert cache.get("Europe/Albania", POPULATION).equals(3563112);
+ assert cache.get("Europe/Albania", AREA).equals(28748);
- assertEquals("Budapest", cache.get("Europe/Hungary",
CAPITAL));
- assertEquals("Forint", cache.get("Europe/Hungary", CURRENCY));
- assertEquals(10006835, cache.get("Europe/Hungary", POPULATION));
- assertEquals(93030, cache.get("Europe/Hungary", AREA));
+ assert "Budapest".equals(cache.get("Europe/Hungary",
CAPITAL));
+ assert "Forint".equals(cache.get("Europe/Hungary", CURRENCY));
+ assert cache.get("Europe/Hungary", POPULATION).equals(10006835);
+ assert cache.get("Europe/Hungary", AREA).equals(93030);
}
}
Modified:
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingFileCacheLoaderTest.java
===================================================================
---
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingFileCacheLoaderTest.java 2007-08-15
09:26:13 UTC (rev 4286)
+++
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingFileCacheLoaderTest.java 2007-08-15
10:43:05 UTC (rev 4287)
@@ -6,58 +6,52 @@
*/
package org.jboss.cache.loader;
-import junit.framework.TestCase;
-
-import java.io.FileOutputStream;
-import java.io.File;
-import java.io.ObjectOutputStream;
-import java.io.IOException;
-import java.io.FileInputStream;
-import java.nio.channels.FileChannel;
-import java.util.HashMap;
-
-import org.jboss.cache.marshall.ObjectSerializationFactory;
import org.jboss.cache.CacheImpl;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.config.Configuration;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
+
/**
* Unit tests for TransformingFileCacheLoader
*
* @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
*/
+@Test
public class TransformingFileCacheLoaderTest extends TransformingCacheLoaderTestBase
{
private CacheImpl cache;
private String targetLoc;
- @Override
+ @BeforeTest
protected void setUp() throws Exception
{
- super.setUp(); //To change body of overridden methods use File | Settings | File
Templates.
-
String targetDir = System.getProperty("java.io.tmpdir",
"/tmp");
targetLoc = targetDir + "/filecacheloader-1x";
cache = createCache();
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
-
"org.jboss.cache.loader.TransformingFileCacheLoaderTest$LegacyFileCacheLoader",
- "location=" + targetLoc, false, true, false));
+
"org.jboss.cache.loader.TransformingFileCacheLoaderTest$LegacyFileCacheLoader",
+
"location=" + targetLoc, false, true, false));
- TestingUtil.recursiveFileRemove(targetLoc);
+ TestingUtil.recursiveFileRemove(targetLoc);
}
- @Override
+ @AfterTest
protected void tearDown() throws Exception
{
cache.stop();
cache.destroy();
- TestingUtil.recursiveFileRemove(targetLoc);
+ TestingUtil.recursiveFileRemove(targetLoc);
}
+ @Test
public void testPutGetData() throws Exception
{
cache.start();
@@ -79,5 +73,5 @@
output.writeObject(obj);
out.close();
}
- }
+ }
}
Modified:
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingJDBCCacheLoaderTest.java
===================================================================
---
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingJDBCCacheLoaderTest.java 2007-08-15
09:26:13 UTC (rev 4286)
+++
cacheloader_migration/trunk/src/test/java/org/jboss/cache/loader/TransformingJDBCCacheLoaderTest.java 2007-08-15
10:43:05 UTC (rev 4287)
@@ -6,30 +6,30 @@
*/
package org.jboss.cache.loader;
+import org.jboss.aop.util.MarshalledValue;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
-import org.jboss.invocation.MarshalledValue;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
-import java.util.Properties;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
+import java.util.Properties;
/**
* Unit tests for TransformingJDBCCacheLoader
*
* @author <a href="mailto:galder.zamarreno@jboss.com">Galder
Zamarreno</a>
*/
+@Test
public class TransformingJDBCCacheLoaderTest extends TransformingCacheLoaderTestBase
{
private CacheImpl cache;
- @Override
+ @BeforeTest
protected void setUp() throws Exception
{
- super.setUp();
-
cache = createCache();
Properties prop = getProperties();
@@ -37,32 +37,33 @@
String cacheJdbcUrl = changeDbName(prop.getProperty("cache.jdbc.url"));
String props = "cache.jdbc.driver =" +
prop.getProperty("cache.jdbc.driver") + "\n" +
- "cache.jdbc.url=" + cacheJdbcUrl + "\n" +
- "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user")
+ "\n" +
- "cache.jdbc.password=" +
prop.getProperty("cache.jdbc.password") + "\n" +
- "cache.jdbc.node.type=" +
prop.getProperty("cache.jdbc.node.type") + "\n" +
- "cache.jdbc.sql-concat=" +
prop.getProperty("cache.jdbc.sql-concat");
+ "cache.jdbc.url=" + cacheJdbcUrl + "\n" +
+ "cache.jdbc.user=" +
prop.getProperty("cache.jdbc.user") + "\n" +
+ "cache.jdbc.password=" +
prop.getProperty("cache.jdbc.password") + "\n" +
+ "cache.jdbc.node.type=" +
prop.getProperty("cache.jdbc.node.type") + "\n" +
+ "cache.jdbc.sql-concat=" +
prop.getProperty("cache.jdbc.sql-concat");
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
-
"org.jboss.cache.loader.TransformingJDBCCacheLoaderTest$LegacyJDBCCacheLoader",
props, false, true, false));
+
"org.jboss.cache.loader.TransformingJDBCCacheLoaderTest$LegacyJDBCCacheLoader",
props, false, true, false));
}
- @Override
+ @AfterTest
protected void tearDown() throws Exception
{
cache.stop();
cache.destroy();
}
+ @Test
public void testPutGetData() throws Exception
{
cache.start();
-
+
loadCache(cache);
cache.evict(Fqn.fromString("/"), true);
- checkData(cache);
+ checkData(cache);
}
protected Properties getProperties() throws Exception
Added: cacheloader_migration/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- cacheloader_migration/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
(rev 0)
+++
cacheloader_migration/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2007-08-15
10:43:05 UTC (rev 4287)
@@ -0,0 +1,385 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at
gnu.org.
+ */
+
+package org.jboss.cache.misc;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.util.CachePrinter;
+
+import java.io.File;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * Utilities for unit testing JBossCache.
+ *
+ * @author <a href="mailto://brian.stansberry@jboss.com">Brian
Stansberry</a>
+ * @version $Revision$
+ */
+public class TestingUtil
+{
+
+ private static Random random = new Random();
+ public static final Object ALWAYS_EQUALS_OBJECT = new Object()
+ {
+ public boolean equals()
+ {
+ return true;
+ }
+ };
+
+ public static <T extends Interceptor> T findInterceptor(CacheSPI<?, ?>
cache, Class<T> interceptorToFind)
+ {
+ for (Interceptor i : cache.getInterceptorChain())
+ {
+ if (interceptorToFind.isInstance(i)) return interceptorToFind.cast(i);
+ }
+ return null;
+ }
+
+ /**
+ * Injects an interceptor after a specified interceptor in a running cache. Your new
interceptor need not be
+ * initialised with pointers to the next interceptor, etc. as this method does all
that for you, including calling
+ * setCache().
+ *
+ * @param cache running cache instance
+ * @param interceptorToInject interceptor instance to inject.
+ * @param interceptorAfterWhichToInject class of interceptor to search for in the
chain and after which to add your interceptor
+ */
+ public static void injectInterceptor(CacheSPI<?, ?> cache, Interceptor
interceptorToInject, Class<? extends Interceptor> interceptorAfterWhichToInject)
+ {
+ System.out.println("Old interceptor chain: " +
CachePrinter.printCacheInterceptors(cache));
+ interceptorToInject.setCache(cache);
+ int index = -1;
+ for (Interceptor i : cache.getInterceptorChain())
+ {
+ index++;
+ if (interceptorAfterWhichToInject.isInstance(i)) break;
+ }
+
+ cache.addInterceptor(interceptorToInject, index + 1);
+ System.out.println("New interceptor chain: " +
CachePrinter.printCacheInterceptors(cache));
+ }
+
+ /**
+ * Loops, continually calling {@link #areCacheViewsComplete(org.jboss.cache.Cache[])}
+ * until it either returns true or <code>timeout</code> ms have elapsed.
+ *
+ * @param caches caches which must all have consistent views
+ * @param timeout max number of ms to loop
+ * @throws RuntimeException if <code>timeout</code> ms have elapse
without
+ * all caches having the same number of members.
+ */
+ public static void blockUntilViewsReceived(Cache[] caches, long timeout)
+ {
+ long failTime = System.currentTimeMillis() + timeout;
+
+ while (System.currentTimeMillis() < failTime)
+ {
+ sleepThread(100);
+ if (areCacheViewsComplete(caches))
+ {
+ return;
+ }
+ }
+
+ throw new RuntimeException("timed out before caches had complete
views");
+ }
+
+ /**
+ * Version of blockUntilViewsReceived that uses varargs
+ */
+ public static void blockUntilViewsReceived(long timeout, Cache... caches)
+ {
+ blockUntilViewsReceived(caches, timeout);
+ }
+
+ /**
+ * Loops, continually calling {@link #areCacheViewsComplete(CacheImpl[])}
+ * until it either returns true or <code>timeout</code> ms have elapsed.
+ *
+ * @param caches caches which must all have consistent views
+ * @param timeout max number of ms to loop
+ * @throws RuntimeException if <code>timeout</code> ms have elapse
without
+ * all caches having the same number of members.
+ */
+ public static void blockUntilViewsReceived(CacheImpl[] caches, long timeout)
+ {
+ long failTime = System.currentTimeMillis() + timeout;
+
+ while (System.currentTimeMillis() < failTime)
+ {
+ sleepThread(100);
+ if (areCacheViewsComplete(caches))
+ {
+ return;
+ }
+ }
+
+ throw new RuntimeException("timed out before caches had complete
views");
+ }
+
+ /**
+ * An overloaded version of {@link
#blockUntilViewsReceived(long,org.jboss.cache.Cache[])} that allows for
'shrinking' clusters.
+ * I.e., the usual method barfs if there are more members than expected. This one
takes a param (barfIfTooManyMembers) which,
+ * if false, will NOT barf but will wait until the cluster 'shrinks' to the
desired size. Useful if in tests, you kill
+ * a member and want to wait until this fact is known across the cluster.
+ *
+ * @param timeout
+ * @param barfIfTooManyMembers
+ * @param caches
+ */
+ public static void blockUntilViewsReceived(long timeout, boolean barfIfTooManyMembers,
Cache... caches)
+ {
+ long failTime = System.currentTimeMillis() + timeout;
+
+ while (System.currentTimeMillis() < failTime)
+ {
+ sleepThread(100);
+ if (areCacheViewsComplete(caches, barfIfTooManyMembers))
+ {
+ return;
+ }
+ }
+
+ throw new RuntimeException("timed out before caches had complete
views");
+ }
+
+ /**
+ * Loops, continually calling {@link #areCacheViewsComplete(CacheImpl[])}
+ * until it either returns true or <code>timeout</code> ms have elapsed.
+ *
+ * @param groupSize number of caches expected in the group
+ * @param timeout max number of ms to loop
+ * @throws RuntimeException if <code>timeout</code> ms have elapse
without
+ * all caches having the same number of members.
+ */
+ public static void blockUntilViewReceived(CacheSPI cache, int groupSize, long
timeout)
+ {
+ long failTime = System.currentTimeMillis() + timeout;
+
+ while (System.currentTimeMillis() < failTime)
+ {
+ sleepThread(100);
+ if (isCacheViewComplete(cache, groupSize))
+ {
+ return;
+ }
+ }
+
+ throw new RuntimeException("timed out before caches had complete
views");
+ }
+
+ /**
+ * Loops, continually calling {@link #areCacheViewsComplete(CacheImpl[])}
+ * until it either returns true or <code>timeout</code> ms have elapsed.
+ *
+ * @param groupSize number of caches expected in the group
+ * @param timeout max number of ms to loop
+ * @throws RuntimeException if <code>timeout</code> ms have elapse
without
+ * all caches having the same number of members.
+ */
+ public static void blockUntilViewReceived(CacheImpl cache, int groupSize, long
timeout)
+ {
+ long failTime = System.currentTimeMillis() + timeout;
+
+ while (System.currentTimeMillis() < failTime)
+ {
+ sleepThread(100);
+ if (isCacheViewComplete(cache, groupSize))
+ {
+ return;
+ }
+ }
+
+ throw new RuntimeException("timed out before caches had complete
views");
+ }
+
+ /**
+ * Checks each cache to see if the number of elements in the array
+ * returned by {@link CacheSPI#getMembers()} matches the size of
+ * the <code>caches</code> parameter.
+ *
+ * @param caches caches that should form a View
+ * @return <code>true</code> if all caches have
+ * <code>caches.length</code> members; false otherwise
+ * @throws IllegalStateException if any of the caches have MORE view
+ * members than caches.length
+ */
+ public static boolean areCacheViewsComplete(Cache[] caches)
+ {
+ return areCacheViewsComplete(caches, true);
+ }
+
+ public static boolean areCacheViewsComplete(Cache[] caches, boolean
barfIfTooManyMembers)
+ {
+ int memberCount = caches.length;
+
+ for (int i = 0; i < memberCount; i++)
+ {
+ if (!isCacheViewComplete(caches[i], memberCount, barfIfTooManyMembers))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Checks each cache to see if the number of elements in the array
+ * returned by {@link CacheImpl#getMembers()} matches the size of
+ * the <code>caches</code> parameter.
+ *
+ * @param caches caches that should form a View
+ * @return <code>true</code> if all caches have
+ * <code>caches.length</code> members; false otherwise
+ * @throws IllegalStateException if any of the caches have MORE view
+ * members than caches.length
+ */
+ public static boolean areCacheViewsComplete(CacheImpl[] caches)
+ {
+ if (caches == null) throw new NullPointerException("Cache impl array is
null");
+ Cache[] c = new Cache[caches.length];
+ for (int i = 0; i < caches.length; i++) c[i] = caches[i];
+ return areCacheViewsComplete(c);
+ }
+
+ /**
+ * @param cache
+ * @param memberCount
+ */
+ public static boolean isCacheViewComplete(CacheImpl cache, int memberCount)
+ {
+ List members = cache.getMembers();
+ if (members == null || memberCount > members.size())
+ {
+ return false;
+ }
+ else if (memberCount < members.size())
+ {
+ // This is an exceptional condition
+ StringBuffer sb = new StringBuffer("Cache at address ");
+ sb.append(cache.getLocalAddress());
+ sb.append(" had ");
+ sb.append(members.size());
+ sb.append(" members; expecting ");
+ sb.append(memberCount);
+ sb.append(". Members were (");
+ for (int j = 0; j < members.size(); j++)
+ {
+ if (j > 0)
+ {
+ sb.append(", ");
+ }
+ sb.append(members.get(j));
+ }
+ sb.append(')');
+
+ throw new IllegalStateException(sb.toString());
+ }
+
+ return true;
+ }
+
+ /**
+ * @param c
+ * @param memberCount
+ */
+ public static boolean isCacheViewComplete(Cache c, int memberCount)
+ {
+ return isCacheViewComplete(c, memberCount, true);
+ }
+
+ public static boolean isCacheViewComplete(Cache c, int memberCount, boolean
barfIfTooManyMembers)
+ {
+ CacheSPI cache = (CacheSPI) c;
+ List members = cache.getMembers();
+ if (members == null || memberCount > members.size())
+ {
+ return false;
+ }
+ else if (memberCount < members.size())
+ {
+ if (barfIfTooManyMembers)
+ {
+ // This is an exceptional condition
+ StringBuffer sb = new StringBuffer("Cache at address ");
+ sb.append(cache.getLocalAddress());
+ sb.append(" had ");
+ sb.append(members.size());
+ sb.append(" members; expecting ");
+ sb.append(memberCount);
+ sb.append(". Members were (");
+ for (int j = 0; j < members.size(); j++)
+ {
+ if (j > 0)
+ {
+ sb.append(", ");
+ }
+ sb.append(members.get(j));
+ }
+ sb.append(')');
+
+ throw new IllegalStateException(sb.toString());
+ }
+ else return false;
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Puts the current thread to sleep for the desired number of ms, suppressing
+ * any exceptions.
+ *
+ * @param sleeptime number of ms to sleep
+ */
+ public static void sleepThread(long sleeptime)
+ {
+ try
+ {
+ Thread.sleep(sleeptime);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+
+ public static void sleepRandom(int maxTime)
+ {
+ sleepThread(random.nextInt(maxTime));
+ }
+
+ public static void recursiveFileRemove(String directoryName)
+ {
+ File file = new File(directoryName);
+ if (file.exists())
+ {
+ System.out.println("Deleting file " + file);
+ recursivedelete(file);
+ }
+ }
+
+ private static void recursivedelete(File f)
+ {
+ if (f.isDirectory())
+ {
+ File[] files = f.listFiles();
+ for (File file : files)
+ {
+ recursivedelete(file);
+ }
+ }
+ //System.out.println("File " + f.toURI() + " deleted = " +
f.delete());
+ f.delete();
+ }
+}
Added: cacheloader_migration/trunk/src/test/resources/cache-jdbc.properties
===================================================================
--- cacheloader_migration/trunk/src/test/resources/cache-jdbc.properties
(rev 0)
+++ cacheloader_migration/trunk/src/test/resources/cache-jdbc.properties 2007-08-15
10:43:05 UTC (rev 4287)
@@ -0,0 +1,65 @@
+##
+# Standard JBC table properties
+cache.jdbc.table.name=jbosscache
+cache.jdbc.table.create=true
+cache.jdbc.table.drop=false
+cache.jdbc.table.primarykey=jbosscache_pk
+cache.jdbc.fqn.column=fqn
+cache.jdbc.fqn.type=varchar(255)
+cache.jdbc.node.column=node
+cache.jdbc.node.type=blob
+cache.jdbc.parent.column=parent
+# Specify your DBMS's string concatenation function syntax in the following manner:
concat(1 , 2) -> '12'.
+# This syntax should work an most popular DBMS like oracle, db2, mssql, mysql,
PostgreSQL. Derby - on which
+#the tests are run does not support 'concat', but '1 || 2' . If no value
is sepcified then concat(1 , 2) is used by default.
+cache.jdbc.sql-concat=1 || 2
+
+# JBoss Cache Table properties for Hypersonic, just overrides
+#cache.jdbc.node.type=OBJECT
+
+##
+# DataSource
+#cache.jdbc.datasource=DefaultDS
+
+##
+# JDBC driver specific properties
+
+# Hypersonic
+#cache.jdbc.node.type=OBJECT
+
+## MySql
+#cache.jdbc.driver=com.mysql.jdbc.Driver
+#cache.jdbc.url=jdbc:mysql://localhost:3306/jbossdb
+#cache.jdbc.user=root
+#cache.jdbc.password=admin
+
+## Oracle
+#cache.jdbc.driver=oracle.jdbc.OracleDriver
+#cache.jdbc.url=jdbc:oracle:thin:@192.168.0.100:1521:JBOSSDB
+#cache.jdbc.user=jboss
+#cache.jdbc.password=sa
+
+## MS Sql Server
+#cache.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
+#cache.jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jbossdb;SelectMethod=cursor
+#cache.jdbc.user=sa
+#cache.jdbc.password=
+#cache.jdbc.node.type=image
+
+## Pointbase
+#cache.jdbc.driver=com.pointbase.jdbc.jdbcUniversalDriver
+#cache.jdbc.url=jdbc:pointbase:server://localhost:9092/jboss,new
+#cache.jdbc.user=PBPUBLIC
+#cache.jdbc.password=PBPUBLIC
+
+## PostgreSQL
+#cache.jdbc.driver = org.postgresql.Driver
+#cache.jdbc.url=jdbc:postgresql://192.168.0.100:5432/jbossdb
+#cache.jdbc.user=postgres
+#cache.jdbc.password=admin
+
+## Derby
+cache.jdbc.driver = org.apache.derby.jdbc.EmbeddedDriver
+cache.jdbc.url=jdbc:derby:jbossdb;create=true
+cache.jdbc.user=user1
+cache.jdbc.password=user1
\ No newline at end of file
Property changes on: cacheloader_migration/trunk/src/test/resources/cache-jdbc.properties
___________________________________________________________________
Name: svn:executable
+ *
Added: cacheloader_migration/trunk/src/test/resources/log4j.xml
===================================================================
--- cacheloader_migration/trunk/src/test/resources/log4j.xml (rev
0)
+++ cacheloader_migration/trunk/src/test/resources/log4j.xml 2007-08-15 10:43:05 UTC (rev
4287)
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 4263 2007-08-15 06:43:55Z manik.surtani(a)jboss.com $ -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite:
http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
+
+ <!-- ================================= -->
+ <!-- Preserve messages in a local file -->
+ <!-- ================================= -->
+
+ <!-- A time/date based rolling appender -->
+ <appender name="FILE"
class="org.apache.log4j.DailyRollingFileAppender">
+ <param name="File" value="output/jbosscache.log"/>
+ <param name="Append" value="true"/>
+
+ <!-- Rollover at midnight each day -->
+ <param name="DatePattern"
value="'.'yyyy-MM-dd"/>
+
+ <!-- Rollover at the top of each hour
+ <param name="DatePattern"
value="'.'yyyy-MM-dd-HH"/>
+ -->
+ <param name="Threshold" value="DEBUG"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d %-5p [%c] (%t)
%m%n"/>
+
+ <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
+ <param name="ConversionPattern" value="%d %-5r %-5p [%c]
(%t:%x) %m%n"/>
+ -->
+ </layout>
+ </appender>
+
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+
+ <appender name="CONSOLE"
class="org.apache.log4j.ConsoleAppender">
+ <param name="Threshold" value="TRACE"/>
+ <param name="Target" value="System.out"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d %-5p [%c{1}] (%t)
%m%n"/>
+ </layout>
+ </appender>
+
+
+ <!-- ================ -->
+ <!-- Limit categories -->
+ <!-- ================ -->
+
+ <!-- Limit JBoss categories to INFO
+ <category name="org.jboss">
+ <priority value="INFO"/>
+ </category>
+ -->
+
+ <category name="org.jboss.cache">
+ <priority value="INFO"/>
+ </category>
+
+ <category name="org.jboss.tm">
+ <priority value="ERROR"/>
+ </category>
+
+ <category name="org.jgroups">
+ <priority value="ERROR"/>
+ </category>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+
+ <root>
+ <priority value="ERROR"/>
+ <appender-ref ref="CONSOLE"/>
+ <!--<appender-ref ref="FILE"/>-->
+ </root>
+
+</log4j:configuration>