[infinispan-commits] Infinispan SVN: r1540 - in trunk: core/src/test/java/org/infinispan/api/mvcc and 9 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Feb 24 06:42:06 EST 2010
Author: mircea.markus
Date: 2010-02-24 06:42:04 -0500 (Wed, 24 Feb 2010)
New Revision: 1540
Added:
trunk/core/src/test/java/org/infinispan/test/fwk/DebuggingUnitTestNGListener.java
trunk/core/src/test/java/org/infinispan/test/fwk/SuiteResourcesAndLogTest.java
trunk/core/src/test/java/org/infinispan/test/fwk/UnitTestTestNGListener.java
Removed:
trunk/core/src/test/java/org/infinispan/test/testng/
Modified:
trunk/core/src/main/java/org/infinispan/jmx/CacheJmxRegistration.java
trunk/core/src/test/java/org/infinispan/api/mvcc/LockTestBase.java
trunk/core/src/test/java/org/infinispan/api/mvcc/read_committed/CacheAPIMVCCTest.java
trunk/core/src/test/java/org/infinispan/atomic/APITest.java
trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java
trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java
trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java
trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java
trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java
trunk/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java
trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
trunk/core/src/test/java/org/infinispan/test/TestingUtil.java
trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
trunk/core/src/test/java/org/infinispan/tx/OnePhaseXATest.java
trunk/parent/pom.xml
Log:
ISPN-314 Enhance test fwk to report when a resource was not properly cleaned by a test
Modified: trunk/core/src/main/java/org/infinispan/jmx/CacheJmxRegistration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/jmx/CacheJmxRegistration.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/main/java/org/infinispan/jmx/CacheJmxRegistration.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -95,7 +95,11 @@
Configuration config = cache.getConfiguration();
if (config.isExposeJmxStatistics()) {
// Only unregister the non cache MBean so that it can be restarted
- unregisterMBeans(nonCacheComponents);
+ try {
+ unregisterMBeans(nonCacheComponents);
+ } catch (Exception e) {
+ log.warn("Problems un-registering MBeans", e);
+ }
log.trace("MBeans were successfully unregistered from the mbean server.");
}
Modified: trunk/core/src/test/java/org/infinispan/api/mvcc/LockTestBase.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/mvcc/LockTestBase.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/api/mvcc/LockTestBase.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -28,6 +28,7 @@
private Log log = LogFactory.getLog(LockTestBase.class);
protected boolean repeatableRead = true;
protected boolean lockParentForChildInsertRemove = false;
+ private CacheManager cm;
protected class LockTestBaseTL {
public Cache<String, String> cache;
@@ -45,7 +46,7 @@
Configuration defaultCfg = new Configuration();
defaultCfg.setIsolationLevel(repeatableRead ? IsolationLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED);
defaultCfg.setLockAcquisitionTimeout(200); // 200 ms
- CacheManager cm = TestCacheManagerFactory.createCacheManager(defaultCfg, true);
+ cm = TestCacheManagerFactory.createCacheManager(defaultCfg, true);
tl.cache = cm.getCache();
tl.lockManager = TestingUtil.extractComponentRegistry(tl.cache).getComponent(LockManager.class);
tl.icc = TestingUtil.extractComponentRegistry(tl.cache).getComponent(InvocationContextContainer.class);
@@ -57,7 +58,7 @@
public void tearDown() {
LockTestBaseTL tl = threadLocal.get();
log.debug("**** - STARTING TEARDOWN - ****");
- TestingUtil.killCaches(tl.cache);
+ TestingUtil.killCacheManagers(cm);
threadLocal.set(null);
}
Modified: trunk/core/src/test/java/org/infinispan/api/mvcc/read_committed/CacheAPIMVCCTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/mvcc/read_committed/CacheAPIMVCCTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/api/mvcc/read_committed/CacheAPIMVCCTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -2,6 +2,7 @@
import org.infinispan.api.CacheAPITest;
import org.infinispan.util.concurrent.IsolationLevel;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
@Test(groups = "functional", testName = "api.mvcc.read_committed.CacheAPIMVCCTest")
Modified: trunk/core/src/test/java/org/infinispan/atomic/APITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/APITest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/atomic/APITest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -25,6 +25,7 @@
import static org.infinispan.atomic.AtomicHashMapTestAssertions.assertIsEmpty;
import static org.infinispan.atomic.AtomicHashMapTestAssertions.assertIsEmptyMap;
import org.infinispan.config.Configuration;
+import org.infinispan.manager.CacheManager;
import org.infinispan.test.AbstractInfinispanTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
@@ -42,18 +43,20 @@
Cache<String, Object> cache;
TransactionManager tm;
+ private CacheManager cacheManager;
@BeforeTest
public void setUp() {
Configuration c = new Configuration();
c.setInvocationBatchingEnabled(true);
- cache = TestCacheManagerFactory.createCacheManager(c, true).getCache();
+ cacheManager = TestCacheManagerFactory.createCacheManager(c, true);
+ cache = cacheManager.getCache();
tm = TestingUtil.getTransactionManager(cache);
}
@AfterTest
public void tearDown() {
- TestingUtil.killCaches(cache);
+ TestingUtil.killCacheManagers(cacheManager);
cache =null;
tm = null;
}
Modified: trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -26,6 +26,7 @@
public static final String KEY = "key";
Cache<String, Object> cache;
TransactionManager tm;
+ private CacheManager cm;
enum Operation {
PUT,
@@ -40,7 +41,7 @@
c.setLockAcquisitionTimeout(500);
// these 2 need to be set to use the AtomicMapCache
c.setInvocationBatchingEnabled(true);
- CacheManager cm = TestCacheManagerFactory.createCacheManager(c, true);
+ cm = TestCacheManagerFactory.createCacheManager(c, true);
cache = cm.getCache();
tm = TestingUtil.getTransactionManager(cache);
}
@@ -51,6 +52,7 @@
tm.rollback();
} catch (Exception e) {
}
+ TestingUtil.killCacheManagers(cm);
}
public void testConcurrentCreate() throws Exception {
Modified: trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -23,6 +23,7 @@
private static final Log log = LogFactory.getLog(AtomicMapFunctionalTest.class);
Cache<String, Object> cache;
TransactionManager tm;
+ private CacheManager cm;
@BeforeMethod
@SuppressWarnings("unchecked")
@@ -30,14 +31,14 @@
Configuration c = new Configuration();
// these 2 need to be set to use the AtomicMapCache
c.setInvocationBatchingEnabled(true);
- CacheManager cm = TestCacheManagerFactory.createCacheManager(c, true);
+ cm = TestCacheManagerFactory.createCacheManager(c, true);
cache = cm.getCache();
tm = TestingUtil.getTransactionManager(cache);
}
@AfterMethod
public void tearDown() {
- TestingUtil.killCaches(cache);
+ TestingUtil.killCacheManagers(cm);
cache = null;
tm = null;
}
Modified: trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/jmx/CacheMBeanTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -116,12 +116,18 @@
assert false : "Failure expected, " + JMX_DOMAIN + " is a duplicate!";
} catch (CacheException e) {
assert e.getCause().getCause() instanceof JmxDomainConflictException;
+ } finally {
+ otherManager.stop();
}
}
public void testMalformedCacheName(Method m) throws Exception {
final String otherJmxDomain = JMX_DOMAIN + '.' + m.getName();
CacheManager otherManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(otherJmxDomain);
- otherManager.getCache("persistence.unit:unitName=#helloworld.MyRegion");
+ try {
+ otherManager.getCache("persistence.unit:unitName=#helloworld.MyRegion");
+ } finally {
+ otherManager.stop();
+ }
}
}
Modified: trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -13,6 +13,7 @@
import org.infinispan.test.AbstractInfinispanTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
@@ -49,7 +50,7 @@
tm = TestingUtil.getTransactionManager(cache);
}
- @AfterTest
+ @AfterClass
public void tearDown() {
TestingUtil.killCacheManagers(cm);
cache = null;
Modified: trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -10,6 +10,7 @@
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import javax.transaction.TransactionManager;
Modified: trunk/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -25,6 +25,7 @@
import java.lang.reflect.Modifier;
import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterTest;
/**
* AbstractInfinispanTest is a superclass of all Infinispan tests.
@@ -34,7 +35,7 @@
*/
public class AbstractInfinispanTest {
- @AfterClass(alwaysRun=true)
+ @AfterTest(alwaysRun=true)
protected void nullifyInstanceFields() {
for(Class<?> current = this.getClass();current.getSuperclass() != null; current = current.getSuperclass()) {
Field[] fields = current.getDeclaredFields();
Modified: trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -46,7 +46,7 @@
protected List<CacheManager> cacheManagers = new ArrayList<CacheManager>();
private IdentityHashMap<Cache, ReplListener> listeners = new IdentityHashMap<Cache, ReplListener>();
- @BeforeClass
+ @BeforeClass (alwaysRun = true)
public void createBeforeClass() throws Throwable {
if (cleanup == CleanupPhase.AFTER_TEST) callCreateCacheManagers();
}
@@ -66,11 +66,11 @@
if (cleanup == CleanupPhase.AFTER_METHOD) callCreateCacheManagers();
}
- @AfterClass
+ @AfterClass(alwaysRun = true)
protected void destroy() {
if (cleanup == CleanupPhase.AFTER_TEST) TestingUtil.killCacheManagers(cacheManagers);
- cacheManagers.clear();
- listeners.clear();
+ cacheManagers.clear();
+ listeners.clear();
}
@AfterMethod(alwaysRun=true)
Modified: trunk/core/src/test/java/org/infinispan/test/TestingUtil.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/TestingUtil.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/test/TestingUtil.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -390,14 +390,11 @@
f.delete();
}
- public static void killCaches(Collection caches) {
- if (caches != null) killCaches((Cache[]) caches.toArray(new Cache[]{}));
- }
-
public static void killCacheManagers(CacheManager... cacheManagers) {
if (cacheManagers != null) {
for (CacheManager cm : cacheManagers) {
- if (cm != null) cm.stop();
+ if (cm != null)
+ cm.stop();
}
}
}
Copied: trunk/core/src/test/java/org/infinispan/test/fwk/DebuggingUnitTestNGListener.java (from rev 1532, trunk/core/src/test/java/org/infinispan/test/testng/DebuggingUnitTestNGListener.java)
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/fwk/DebuggingUnitTestNGListener.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/test/fwk/DebuggingUnitTestNGListener.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.infinispan.test.fwk;
+
+import java.util.Set;
+
+import org.infinispan.config.Configuration;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.util.concurrent.ConcurrentHashSet;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.ITestContext;
+
+/**
+ * DebuggingUnitTestNGListener is a slower version of UnitTestTestNGListener
+ * containing some additional sanity checks of the tests themselves.
+ * It will verify any clustered CacheManager created by the test was properly killed,
+ * if not a message is output.
+ *
+ * NOTE: The test WILL NOT FAIL when not cleaning up, you'll have to check for these messages in logs.
+ *
+ * @author Sanne Grinovero
+ * @since 4.0
+ */
+public class DebuggingUnitTestNGListener extends UnitTestTestNGListener {
+
+ private static final Log log = LogFactory.getLog(DebuggingUnitTestNGListener.class);
+
+ private static final Set<String> failedTestDescriptions = new ConcurrentHashSet<String>();
+
+ @Override
+ public void onFinish(ITestContext testCxt) {
+ super.onFinish(testCxt);
+ checkCleanedUp(testCxt);
+ }
+
+ private void checkCleanedUp(ITestContext testCxt) {
+ CacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(new Configuration());
+ try {
+ cm.start();
+ try {
+ TestingUtil.blockUntilViewReceived(cm.getCache(), 1, 2000, true);
+ } catch (RuntimeException re) {
+ failedTestDescriptions.add(
+ "CacheManagers alive after test! - " + testCxt.getName() + " " + re.getMessage()
+ );
+ }
+ }
+ finally {
+ TestingUtil.killCacheManagers(cm);
+ }
+ }
+
+ public static void describeErrorsIfAny() {
+ if ( ! failedTestDescriptions.isEmpty() ) {
+ log("~~~~~~~~~~~~~~~~~~~~~~~~~ TEST HEALTH INFO ~~~~~~~~~~~~~~~~~~~~~~~~~~");
+ log("Some tests didn't properly shutdown the CacheManager:");
+ for (String errorMsg : failedTestDescriptions) {
+ System.out.println( "\t" + errorMsg);
+ }
+ log("~~~~~~~~~~~~~~~~~~~~~~~~~ TEST HEALTH INFO ~~~~~~~~~~~~~~~~~~~~~~~~~~");
+ }
+ }
+
+ private static void log(String s) {
+ System.out.println(s);
+ log.info(s);
+ }
+
+}
Property changes on: trunk/core/src/test/java/org/infinispan/test/fwk/DebuggingUnitTestNGListener.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/core/src/test/java/org/infinispan/test/fwk/SuiteResourcesAndLogTest.java (from rev 1532, trunk/core/src/test/java/org/infinispan/test/testng/SuiteResourcesAndLogTest.java)
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/fwk/SuiteResourcesAndLogTest.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/test/fwk/SuiteResourcesAndLogTest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -0,0 +1,49 @@
+package org.infinispan.test.fwk;
+
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+/**
+ * This class makes sure that all files are being deleted after each test run. It also logs testsuite information.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @author Galder Zamarreño
+ */
+ at Test(groups = "functional", testName = "test.testng.SuiteResourcesAndLogTest", alwaysRun=true)
+public class SuiteResourcesAndLogTest {
+
+ private static Log log = LogFactory.getLog(SuiteResourcesAndLogTest.class);
+
+ @BeforeSuite
+ @AfterSuite
+ public void printEnvInformation() {
+ log("~~~~~~~~~~~~~~~~~~~~~~~~~ ENVIRONMENT INFO ~~~~~~~~~~~~~~~~~~~~~~~~~~");
+ log("jgroups.bind_addr = " + System.getProperty("jgroups.bind_addr"));
+ log("bind.address = " + System.getProperty("bind.address"));
+ log("java.runtime.version = " + System.getProperty("java.runtime.version"));
+ log("java.runtime.name =" + System.getProperty("java.runtime.name"));
+ log("java.vm.version = " + System.getProperty("java.vm.version"));
+ log("java.vm.vendor = " + System.getProperty("java.vm.vendor"));
+ log("os.name = " + System.getProperty("os.name"));
+ log("os.version = " + System.getProperty("os.version"));
+ log("sun.arch.data.model = " + System.getProperty("sun.arch.data.model"));
+ log("sun.cpu.endian = " + System.getProperty("sun.cpu.endian"));
+ log("protocol.stack = " + System.getProperty("protocol.stack"));
+// log("infinispan.marshaller.class = " + System.getProperty("infinispan.marshaller.class"));
+ String preferIpV4 = System.getProperty("java.net.preferIPv4Stack");
+ log("java.net.preferIPv4Stack = " + preferIpV4);
+ log("java.net.preferIPv6Stack = " + System.getProperty("java.net.preferIPv6Stack"));
+ log("MAVEN_OPTS = " + System.getProperty("MAVEN_OPTS"));
+ log("~~~~~~~~~~~~~~~~~~~~~~~~~ ENVIRONMENT INFO ~~~~~~~~~~~~~~~~~~~~~~~~~~");
+
+ DebuggingUnitTestNGListener.describeErrorsIfAny();
+ }
+
+ private void log(String s) {
+ System.out.println(s);
+ log.info(s);
+ }
+}
Property changes on: trunk/core/src/test/java/org/infinispan/test/fwk/SuiteResourcesAndLogTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/test/fwk/TestCacheManagerFactory.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -14,6 +14,9 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
@@ -33,12 +36,18 @@
public static final String MARSHALLER = System.getProperties().getProperty("infinispan.marshaller.class");
private static Log log = LogFactory.getLog(TestCacheManagerFactory.class);
+ private static ThreadLocal<PerThreadCacheManagers> perThreadCacheManagers = new ThreadLocal<PerThreadCacheManagers>() {
+ @Override
+ protected PerThreadCacheManagers initialValue() {
+ return new PerThreadCacheManagers();
+ }
+ };
+
private static DefaultCacheManager newDefaultCacheManager(GlobalConfiguration gc, Configuration c, boolean keepJmxDomain) {
if (!keepJmxDomain) {
gc.setJmxDomain("infinispan" + jmxDomainPostfix.incrementAndGet());
}
- DefaultCacheManager defaultCacheManager = new DefaultCacheManager(gc, c);
- return defaultCacheManager;
+ return newDefaultCacheManager(gc, c);
}
public static CacheManager fromXml(String xmlFile, boolean allowDupeDomains) throws IOException {
@@ -72,7 +81,7 @@
minimizeThreads(gc);
- CacheManager cm = new DefaultCacheManager(gc, c, false);
+ CacheManager cm = newDefaultCacheManager(gc, c, false);
for (Map.Entry<String, Configuration> e: named.entrySet()) cm.defineConfiguration(e.getKey(), e.getValue());
cm.start();
return cm;
@@ -248,4 +257,55 @@
}
}
}
+
+ private static DefaultCacheManager newDefaultCacheManager(GlobalConfiguration gc, Configuration c) {
+ DefaultCacheManager defaultCacheManager = new DefaultCacheManager(gc, c, true);
+ PerThreadCacheManagers threadCacheManagers = perThreadCacheManagers.get();
+ String methodName = extractMethodName();
+ threadCacheManagers.add(methodName, defaultCacheManager);
+ return defaultCacheManager;
+ }
+
+ private static String extractMethodName() {
+ StackTraceElement[] stack = Thread.currentThread().getStackTrace();
+ if (stack.length == 0) return null;
+ for (int i = stack.length - 1; i > 0; i--)
+ {
+ StackTraceElement e = stack[i];
+ String className = e.getClassName();
+ if ((className.indexOf("org.infinispan") != -1) && className.indexOf("org.infinispan.test") < 0)
+ return e.toString();
+ }
+ return null;
+ }
+
+ static void testFinished(String testName) {
+ perThreadCacheManagers.get().checkManagersClosed(testName);
+ }
+
+ private static class PerThreadCacheManagers {
+ HashMap<String, CacheManager> cacheManagers = new HashMap<String, CacheManager>();
+
+ public void checkManagersClosed(String testName) {
+ for (String cmName : cacheManagers.keySet()) {
+ CacheManager cm = cacheManagers.get(cmName);
+ if (cm.getStatus().allowInvocations()) {
+ String thName = Thread.currentThread().getName();
+ String errorMessage = '\n' +
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" +
+ "!!!!!! (" + thName + ") Exiting because " + testName + " has NOT shut down all the cache managers it has started !!!!!!!\n" +
+ "!!!!!! (" + thName + ") The still-running cacheManager was created here: " + cmName + " !!!!!!!\n" +
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
+ log.error(errorMessage);
+ System.err.println(errorMessage);
+ System.exit(9);
+ }
+ }
+ cacheManagers.clear();
+ }
+
+ public void add(String methodName, DefaultCacheManager cm) {
+ cacheManagers.put(methodName, cm);
+ }
+ }
}
Copied: trunk/core/src/test/java/org/infinispan/test/fwk/UnitTestTestNGListener.java (from rev 1532, trunk/core/src/test/java/org/infinispan/test/testng/UnitTestTestNGListener.java)
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/fwk/UnitTestTestNGListener.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/test/fwk/UnitTestTestNGListener.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -0,0 +1,77 @@
+package org.infinispan.test.fwk;
+
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.IClass;
+import org.testng.ITestContext;
+import org.testng.ITestListener;
+import org.testng.ITestResult;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author dpospisi at redhat.com
+ * @author Mircea.Markus at jboss.com
+ */
+public class UnitTestTestNGListener implements ITestListener {
+
+ /**
+ * Holds test classes actually running in all threads.
+ */
+ private ThreadLocal<IClass> threadTestClass = new ThreadLocal<IClass>();
+ private static final Log log = LogFactory.getLog(UnitTestTestNGListener.class);
+
+ private AtomicInteger failed = new AtomicInteger(0);
+ private AtomicInteger succeeded = new AtomicInteger(0);
+ private AtomicInteger skipped = new AtomicInteger(0);
+
+ public void onTestStart(ITestResult res) {
+ log.info("Starting test " + getTestDesc(res));
+ threadTestClass.set(res.getTestClass());
+ }
+
+ synchronized public void onTestSuccess(ITestResult arg0) {
+ System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " succeeded.");
+ log.info("Test succeeded " + getTestDesc(arg0) + ".");
+ succeeded.incrementAndGet();
+ printStatus();
+ }
+
+ synchronized public void onTestFailure(ITestResult arg0) {
+ System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " failed.");
+ if (arg0.getThrowable() != null) log.error("Test failed " + getTestDesc(arg0), arg0.getThrowable());
+ failed.incrementAndGet();
+ printStatus();
+ }
+
+ synchronized public void onTestSkipped(ITestResult arg0) {
+ System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " skipped.");
+ log.info(" Test " + getTestDesc(arg0) + " skipped.");
+ if (arg0.getThrowable() != null) log.error("Test skipped : " + arg0.getThrowable(), arg0.getThrowable());
+ skipped.incrementAndGet();
+ printStatus();
+ }
+
+
+ public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
+ }
+
+ public void onStart(ITestContext arg0) {
+ }
+
+ public void onFinish(ITestContext arg0) {
+ TestCacheManagerFactory.testFinished(arg0.getName());
+ }
+
+ private String getThreadId() {
+ return "[" + Thread.currentThread().getName() + "]";
+ }
+
+ private String getTestDesc(ITestResult res) {
+ return res.getMethod().getMethodName() + "(" + res.getTestClass().getName() + ")";
+ }
+
+ private void printStatus() {
+ System.out.println("Test suite progress: tests succeeded: " + succeeded.get() + ", failed: " + failed.get() + ", skipped: " + skipped.get() + ".");
+ }
+}
Property changes on: trunk/core/src/test/java/org/infinispan/test/fwk/UnitTestTestNGListener.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/core/src/test/java/org/infinispan/tx/OnePhaseXATest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/tx/OnePhaseXATest.java 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/core/src/test/java/org/infinispan/tx/OnePhaseXATest.java 2010-02-24 11:42:04 UTC (rev 1540)
@@ -18,6 +18,7 @@
@Test(groups = "functional", testName = "tx.OnePhaseXATest", description = "See ISPN-156 for details.", enabled = false)
public class OnePhaseXATest extends AbstractInfinispanTest {
private List<Cache> caches;
+ private List<CacheManager> cacheManagers;
public static final int CACHES_NUM = 2;
public void testMultipleCaches() throws Exception {
@@ -44,12 +45,13 @@
@BeforeTest
public void setUp() throws Exception {
caches = new ArrayList<Cache>();
+ cacheManagers = new ArrayList<CacheManager>();
for (int i = 0; i < CACHES_NUM; i++) caches.add(getCache());
}
@AfterTest
public void tearDown() {
- if (caches != null) TestingUtil.killCaches(caches);
+ if (caches != null) TestingUtil.killCacheManagers(cacheManagers);
}
private Cache getCache() {
@@ -63,6 +65,7 @@
c.setUseLockStriping(false);
c.setSyncCommitPhase(true);
CacheManager manager = TestCacheManagerFactory.createCacheManager(gc, c, true);
+ cacheManagers.add(manager);
return manager.getCache("TestCache");
}
}
\ No newline at end of file
Modified: trunk/parent/pom.xml
===================================================================
--- trunk/parent/pom.xml 2010-02-23 14:41:27 UTC (rev 1539)
+++ trunk/parent/pom.xml 2010-02-24 11:42:04 UTC (rev 1540)
@@ -65,7 +65,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<defaultTestGroup>functional,unit</defaultTestGroup>
- <testNGListener>org.infinispan.test.testng.UnitTestTestNGListener</testNGListener>
+ <testNGListener>org.infinispan.test.fwk.UnitTestTestNGListener</testNGListener>
<scala.version>2.7.7</scala.version>
</properties>
@@ -410,7 +410,7 @@
<profile>
<id>debug-tests</id>
<properties>
- <testNGListener>org.infinispan.test.testng.DebuggingUnitTestNGListener</testNGListener>
+ <testNGListener>org.infinispan.test.fwk.DebuggingUnitTestNGListener</testNGListener>
<protocol.stack>tcp</protocol.stack>
</properties>
</profile>
More information about the infinispan-commits
mailing list