[infinispan-commits] Infinispan SVN: r992 - trunk/core/src/test/java/org/infinispan/test.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Fri Oct 23 12:33:15 EDT 2009
Author: sannegrinovero
Date: 2009-10-23 12:33:14 -0400 (Fri, 23 Oct 2009)
New Revision: 992
Modified:
trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java
trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java
trunk/core/src/test/java/org/infinispan/test/TestingUtil.java
Log:
moving clearContent(CacheManager) to TestingUtil from abstract test base classes
Modified: trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java 2009-10-23 15:17:11 UTC (rev 991)
+++ trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java 2009-10-23 16:33:14 UTC (rev 992)
@@ -1,31 +1,20 @@
package org.infinispan.test;
-import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
-import org.infinispan.container.DataContainer;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.loaders.CacheLoaderManager;
import org.infinispan.manager.CacheManager;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.remoting.ReplicationQueue;
-import org.infinispan.remoting.transport.Address;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
-import javax.transaction.TransactionManager;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
/**
* Base class for {@link org.infinispan.test.SingleCacheManagerTest} and {@link org.infinispan.test.MultipleCacheManagersTest}.
*
* @author Mircea.Markus at jboss.com
*/
-public class AbstractCacheTest extends AbstractInfinispanTest{
+public class AbstractCacheTest extends AbstractInfinispanTest {
protected final Log log = LogFactory.getLog(getClass());
@@ -35,81 +24,26 @@
protected CleanupPhase cleanup = CleanupPhase.AFTER_TEST;
+ /**
+ * use TestingUtil.clearContent(cacheManager);
+ */
+ @Deprecated
public void clearContent(CacheManager cacheManager) {
- if (cacheManager != null) {
- Set<Cache> runningCaches = getRunningCaches(cacheManager);
- for (Cache cache : runningCaches) {
- clearRunningTx(cache);
- }
- if (!cacheManager.getStatus().allowInvocations()) return;
- for (Cache cache : runningCaches) {
- removeInMemoryData(cache);
- clearCacheLoader(cache);
- clearReplicationQueues(cache);
- ((AdvancedCache) cache).getInvocationContextContainer().createInvocationContext();
- }
- }
+ TestingUtil.clearContent(cacheManager);
}
- private void clearReplicationQueues(Cache cache) {
- ReplicationQueue queue = TestingUtil.extractComponent(cache, ReplicationQueue.class);
- if (queue != null) queue.reset();
- }
-
- @SuppressWarnings(value = "unchecked")
+ /**
+ * use TestingUtil.getRunningCaches(cacheManager);
+ */
+ @Deprecated
protected Set<Cache> getRunningCaches(CacheManager cacheManager) {
- ConcurrentMap<String, Cache> caches = (ConcurrentMap<String, Cache>) TestingUtil.extractField(DefaultCacheManager.class, cacheManager, "caches");
- if (caches == null) return Collections.emptySet();
- Set<Cache> result = new HashSet<Cache>();
- for (Cache cache : caches.values()) {
- if (cache.getStatus() == ComponentStatus.RUNNING) result.add(cache);
- }
- return result;
- }
-
- private void clearCacheLoader(Cache cache) {
- CacheLoaderManager cacheLoaderManager = TestingUtil.extractComponent(cache, CacheLoaderManager.class);
- if (cacheLoaderManager != null && cacheLoaderManager.getCacheStore() != null) {
- try {
- cacheLoaderManager.getCacheStore().clear();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ return TestingUtil.getRunningCaches(cacheManager);
}
- private void removeInMemoryData(Cache cache) {
- CacheManager mgr = cache.getCacheManager();
- Address a = mgr.getAddress();
- String str;
- if (a == null)
- str = "a non-clustered cache manager";
- else
- str = "a cache manager at address " + a;
- log.debug("Cleaning data for cache '{0}' on {1}", cache.getName(), str);
- DataContainer dataContainer = TestingUtil.extractComponent(cache, DataContainer.class);
- log.debug("removeInMemoryData(): dataContainerBefore == {0}", dataContainer);
- dataContainer.clear();
- log.debug("removeInMemoryData(): dataContainerAfter == {0}", dataContainer);
- }
-
- private void clearRunningTx(Cache cache) {
- if (cache != null) {
- TransactionManager txm = TestingUtil.getTransactionManager(cache);
- if (txm == null) return;
- try {
- txm.rollback();
- }
- catch (Exception e) {
- // don't care
- }
- }
- }
-
/**
- * When multiple test merhods operate on same cluster, sync commit and rollback are mandatory. This is in order to
+ * When multiple test methods operate on same cluster, sync commit and rollback are mandatory. This is in order to
* make sure that an commit message will be dispatched in the same test method it was triggered and it will not
- * interfere with further log messages. This is a non-transactional configuraion.
+ * interfere with further log messages. This is a non-transactional configuration.
*/
protected Configuration getDefaultClusteredConfig(Configuration.CacheMode mode) {
return getDefaultClusteredConfig(mode, false);
@@ -124,7 +58,6 @@
return configuration;
}
-
protected boolean xor(boolean b1, boolean b2) {
return (b1 || b2) && !(b1 && b2);
}
Modified: trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2009-10-23 15:17:11 UTC (rev 991)
+++ trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2009-10-23 16:33:14 UTC (rev 992)
@@ -82,7 +82,7 @@
if (cacheManagers.isEmpty())
throw new IllegalStateException("No caches registered! Use registerCacheManager(Cache... caches) do that!");
for (CacheManager cacheManager : cacheManagers) {
- super.clearContent(cacheManager);
+ TestingUtil.clearContent(cacheManager);
}
} else {
TestingUtil.killCacheManagers(cacheManagers);
@@ -92,7 +92,7 @@
protected void assertSupportedConfig() {
for (CacheManager cm : cacheManagers) {
- for (Cache cache : getRunningCaches(cm)) {
+ for (Cache cache : TestingUtil.getRunningCaches(cm)) {
Configuration config = cache.getConfiguration();
try {
assert config.isSyncCommitPhase();
Modified: trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java 2009-10-23 15:17:11 UTC (rev 991)
+++ trunk/core/src/test/java/org/infinispan/test/SingleCacheManagerTest.java 2009-10-23 16:33:14 UTC (rev 992)
@@ -44,7 +44,7 @@
@AfterMethod(alwaysRun=true)
protected void clearContent() {
- if (cleanup == CleanupPhase.AFTER_TEST) super.clearContent(cacheManager);
+ if (cleanup == CleanupPhase.AFTER_TEST) TestingUtil.clearContent(cacheManager);
}
protected Configuration getDefaultStandaloneConfig(boolean transactional) {
Modified: trunk/core/src/test/java/org/infinispan/test/TestingUtil.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/TestingUtil.java 2009-10-23 15:17:11 UTC (rev 991)
+++ trunk/core/src/test/java/org/infinispan/test/TestingUtil.java 2009-10-23 16:33:14 UTC (rev 992)
@@ -24,8 +24,12 @@
import org.infinispan.loaders.CacheLoader;
import org.infinispan.loaders.CacheLoaderManager;
import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.remoting.ReplicationQueue;
import org.infinispan.remoting.transport.Address;
import org.infinispan.util.concurrent.locks.LockManager;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
import javax.transaction.TransactionManager;
import java.io.File;
@@ -33,14 +37,18 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
public class TestingUtil {
- private static Random random = new Random();
+
+ private static final Log log = LogFactory.getLog(TestingUtil.class);
+ private static final Random random = new Random();
public static final String TEST_PATH = "target" + File.separator + "tempFiles";
/**
@@ -63,7 +71,7 @@
field.set(owner, newValue);
}
catch (Exception e) {
- throw new RuntimeException(e);//just to simplify exception handeling
+ throw new RuntimeException(e);//just to simplify exception handling
}
}
@@ -386,6 +394,76 @@
public static void killCacheManagers(Collection<CacheManager> cacheManagers) {
killCacheManagers(cacheManagers.toArray(new CacheManager[cacheManagers.size()]));
}
+
+ public static void clearContent(CacheManager cacheManager) {
+ if (cacheManager != null) {
+ Set<Cache> runningCaches = getRunningCaches(cacheManager);
+ for (Cache cache : runningCaches) {
+ clearRunningTx(cache);
+ }
+ if (!cacheManager.getStatus().allowInvocations()) return;
+ for (Cache cache : runningCaches) {
+ removeInMemoryData(cache);
+ clearCacheLoader(cache);
+ clearReplicationQueues(cache);
+ ((AdvancedCache) cache).getInvocationContextContainer().createInvocationContext();
+ }
+ }
+ }
+
+ protected static Set<Cache> getRunningCaches(CacheManager cacheManager) {
+ ConcurrentMap<String, Cache> caches = (ConcurrentMap<String, Cache>) TestingUtil.extractField(DefaultCacheManager.class, cacheManager, "caches");
+ if (caches == null) return Collections.emptySet();
+ Set<Cache> result = new HashSet<Cache>();
+ for (Cache cache : caches.values()) {
+ if (cache.getStatus() == ComponentStatus.RUNNING) result.add(cache);
+ }
+ return result;
+ }
+
+ private static void clearRunningTx(Cache cache) {
+ if (cache != null) {
+ TransactionManager txm = TestingUtil.getTransactionManager(cache);
+ if (txm == null) return;
+ try {
+ txm.rollback();
+ }
+ catch (Exception e) {
+ // don't care
+ }
+ }
+ }
+
+ private static void clearReplicationQueues(Cache cache) {
+ ReplicationQueue queue = TestingUtil.extractComponent(cache, ReplicationQueue.class);
+ if (queue != null) queue.reset();
+ }
+
+ private static void clearCacheLoader(Cache cache) {
+ CacheLoaderManager cacheLoaderManager = TestingUtil.extractComponent(cache, CacheLoaderManager.class);
+ if (cacheLoaderManager != null && cacheLoaderManager.getCacheStore() != null) {
+ try {
+ cacheLoaderManager.getCacheStore().clear();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ private static void removeInMemoryData(Cache cache) {
+ CacheManager mgr = cache.getCacheManager();
+ Address a = mgr.getAddress();
+ String str;
+ if (a == null)
+ str = "a non-clustered cache manager";
+ else
+ str = "a cache manager at address " + a;
+ log.debug("Cleaning data for cache '{0}' on {1}", cache.getName(), str);
+ DataContainer dataContainer = TestingUtil.extractComponent(cache, DataContainer.class);
+ log.debug("removeInMemoryData(): dataContainerBefore == {0}", dataContainer);
+ dataContainer.clear();
+ log.debug("removeInMemoryData(): dataContainerAfter == {0}", dataContainer);
+ }
/**
* Kills a cache - stops it, clears any data in any cache loaders, and rolls back any associated txs
More information about the infinispan-commits
mailing list