JBoss Cache SVN: r7510 - core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-19 10:42:20 -0500 (Mon, 19 Jan 2009)
New Revision: 7510
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesNoPoolNoDataGravitationTest.java
Log:
use appropriate name for cache
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesNoPoolNoDataGravitationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesNoPoolNoDataGravitationTest.java 2009-01-19 13:18:35 UTC (rev 7509)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesNoPoolNoDataGravitationTest.java 2009-01-19 15:42:20 UTC (rev 7510)
@@ -1,12 +1,12 @@
package org.jboss.cache.buddyreplication.mvcc;
+import org.jboss.cache.config.Configuration;
import org.testng.annotations.Test;
-import org.jboss.cache.config.Configuration;
-/**
+/** //
* @author Mircea.Markus(a)jboss.com
*/
-@Test(groups = "functional", testName = "mvcc.buddyreplication.Buddy3NodesNoPoolNoDataGravitationTest")
+@Test(groups = "functional", testName = "buddyreplication.mvcc.Buddy3NodesNoPoolNoDataGravitationTest")
public class Buddy3NodesNoPoolNoDataGravitationTest extends org.jboss.cache.buddyreplication.Buddy3NodesNoPoolNoDataGravitationTest
{
@Override
17 years, 2 months
JBoss Cache SVN: r7509 - core/branches/flat/src/main/java/org/horizon/executors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-19 08:18:35 -0500 (Mon, 19 Jan 2009)
New Revision: 7509
Modified:
core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java
core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java
Log:
Updated default executors to use a queue size
Modified: core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java 2009-01-19 11:06:16 UTC (rev 7508)
+++ core/branches/flat/src/main/java/org/horizon/executors/DefaultExecutorFactory.java 2009-01-19 13:18:35 UTC (rev 7509)
@@ -4,8 +4,10 @@
import java.util.Properties;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -16,14 +18,21 @@
*/
public class DefaultExecutorFactory implements ExecutorFactory {
public ExecutorService getExecutor(Properties p) {
- TypedProperties tp = new TypedProperties(p);
+ TypedProperties tp = TypedProperties.toTypedProperties(p);
int maxThreads = tp.getIntProperty("maxThreads", 1);
+ int queueSize = tp.getIntProperty("queueSize", 100000);
final String threadNamePrefix = tp.getProperty("threadNamePrefix", "Thread");
final AtomicInteger counter = new AtomicInteger(0);
- return Executors.newFixedThreadPool(maxThreads, new ThreadFactory() {
+
+ ThreadFactory tf = new ThreadFactory() {
public Thread newThread(Runnable r) {
return new Thread(threadNamePrefix + "-" + counter.getAndIncrement());
}
- });
+ };
+
+ return new ThreadPoolExecutor(maxThreads, maxThreads,
+ 0L, TimeUnit.MILLISECONDS,
+ new LinkedBlockingQueue<Runnable>(queueSize),
+ tf);
}
}
Modified: core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java 2009-01-19 11:06:16 UTC (rev 7508)
+++ core/branches/flat/src/main/java/org/horizon/executors/DefaultScheduledExecutorFactory.java 2009-01-19 13:18:35 UTC (rev 7509)
@@ -1,7 +1,5 @@
package org.horizon.executors;
-import org.horizon.util.TypedProperties;
-
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -16,8 +14,7 @@
*/
public class DefaultScheduledExecutorFactory implements ScheduledExecutorFactory {
public ScheduledExecutorService getScheduledExecutor(Properties p) {
- TypedProperties tp = new TypedProperties(p);
- final String threadNamePrefix = tp.getProperty("threadNamePrefix", "ScheduledThread");
+ final String threadNamePrefix = p.getProperty("threadNamePrefix", "ScheduledThread");
final AtomicInteger counter = new AtomicInteger(0);
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
public Thread newThread(Runnable r) {
17 years, 2 months
JBoss Cache SVN: r7508 - core/trunk/src/main/java/org/jboss/cache/jmx.
by jbosscache-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2009-01-19 06:06:16 -0500 (Mon, 19 Jan 2009)
New Revision: 7508
Modified:
core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
Log:
[JBCACHE-1465] Removed unused import.
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2009-01-19 11:05:03 UTC (rev 7507)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2009-01-19 11:06:16 UTC (rev 7508)
@@ -36,7 +36,6 @@
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
/**
* Registers all the <b>MBean</b>s from an <b>Cache</b> instance to a <b>MBeanServer</b>.
17 years, 2 months
JBoss Cache SVN: r7507 - in core/trunk/src: test/java/org/jboss/cache/jmx and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2009-01-19 06:05:03 -0500 (Mon, 19 Jan 2009)
New Revision: 7507
Modified:
core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java
Log:
[JBCACHE-1465] LOCAL MBean name now uses identity hash code and added new tests for problematic thread names.
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2009-01-19 10:49:16 UTC (rev 7506)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2009-01-19 11:05:03 UTC (rev 7507)
@@ -36,6 +36,7 @@
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
/**
* Registers all the <b>MBean</b>s from an <b>Cache</b> instance to a <b>MBeanServer</b>.
@@ -55,6 +56,7 @@
* </p>
*
* @author Mircea.Markus(a)jboss.com
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
* @since 3.0
*/
public class JmxRegistrationManager
@@ -97,6 +99,7 @@
this.mBeanServer = mBeanServer;
this.cacheSpi = (CacheSPI) cache;
processBaseName(objectNameBase);
+ log.debug("Base name is: " + this.objectNameBase);
}
/**
@@ -110,6 +113,7 @@
try
{
processBaseName(new ObjectName(objectNameBase));
+ log.debug("Base name is: " + this.objectNameBase);
}
catch (MalformedObjectNameException e)
{
@@ -216,7 +220,8 @@
// CurrentTimeMillis is not good enaugh as an unique id generator. I am constantly
// getting conflicts in several parallel tests on my box. Maybe some more sofisticated
// unique id generator should be provided?
- objectNameBase = LOCAL_CACHE_PREFIX + Thread.currentThread().getName() + "-" + System.currentTimeMillis();
+ // For example: use identity hashcode in hex format.
+ objectNameBase = LOCAL_CACHE_PREFIX + Integer.toHexString(System.identityHashCode(cacheSpi));
}
else //the cache is clustered
{
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java 2009-01-19 10:49:16 UTC (rev 7506)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java 2009-01-19 11:05:03 UTC (rev 7507)
@@ -21,6 +21,8 @@
*/
package org.jboss.cache.jmx;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
@@ -40,11 +42,13 @@
* Tester class for {@link JmxRegistrationManager}.
*
* @author Mircea.Markus(a)jboss.com
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
* @since 3.0
*/
@Test (groups = "functional", testName = "jmx.JmxRegistrationManagerTest")
public class JmxRegistrationManagerTest
{
+ private static final Log log = LogFactory.getLog(JmxRegistrationManagerTest.class);
private UnitTestCacheFactory cacheFactory = new UnitTestCacheFactory();
private MBeanServer mBeanServer;
@@ -62,11 +66,33 @@
public void testRegisterLocalCache() throws Exception
{
- Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL);
+ registerLocalCache();
+ }
+
+ public void testRegisterLocalCacheWithDifferentThreadNames() throws Exception
+ {
+ String prevName = Thread.currentThread().getName();
+ try
+ {
+ Thread.currentThread().setName("onecolon:");
+ registerLocalCache();
+
+ Thread.currentThread().setName("twocolons::");
+ registerLocalCache();
+ }
+ finally
+ {
+ Thread.currentThread().setName(prevName);
+ }
+ }
+
+ public void testRegisterReplicatedCache() throws Exception
+ {
+ Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC);
localConfig.setExposeManagementStatistics(true);
Cache cache = cacheFactory.createCache(localConfig, getClass());
JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, cache, (ObjectName)null);
- assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.LOCAL_CACHE_PREFIX) == 0;
+ assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.REPLICATED_CACHE_PREFIX) == 0;
regManager.registerAllMBeans();
String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
assert mBeanServer.isRegistered(new ObjectName(name));
@@ -74,14 +100,14 @@
assert !mBeanServer.isRegistered(new ObjectName(name));
cache.stop();
}
-
- public void testRegisterReplicatedCache() throws Exception
+
+ protected void registerLocalCache() throws Exception
{
- Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC);
+ Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL);
localConfig.setExposeManagementStatistics(true);
Cache cache = cacheFactory.createCache(localConfig, getClass());
JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, cache, (ObjectName)null);
- assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.REPLICATED_CACHE_PREFIX) == 0;
+ assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.LOCAL_CACHE_PREFIX) == 0;
regManager.registerAllMBeans();
String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
assert mBeanServer.isRegistered(new ObjectName(name));
17 years, 2 months
JBoss Cache SVN: r7506 - core/trunk/src/test/java/org/jboss/cache/passivation.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-19 05:49:16 -0500 (Mon, 19 Jan 2009)
New Revision: 7506
Modified:
core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java
Log:
more strict replication control
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java 2009-01-19 09:42:32 UTC (rev 7505)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ReplAndStateTransferWithPassivationTest.java 2009-01-19 10:49:16 UTC (rev 7506)
@@ -22,7 +22,9 @@
package org.jboss.cache.passivation;
import org.jboss.cache.*;
+import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.cache.buddyreplication.BuddyReplicationTestsBase;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
@@ -31,12 +33,13 @@
import org.jboss.cache.factories.UnitTestConfigurationFactory;
import org.jboss.cache.loader.testloaders.DummySharedInMemoryCacheLoader;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.replicationlisteners.ReplicationListener;
import org.testng.annotations.Test;
import java.util.HashSet;
import java.util.Set;
-@Test(groups = "functional", sequential = true, testName = "passivation.ReplAndStateTransferWithPassivationTest")
+@Test(groups = "functional", testName = "passivation.ReplAndStateTransferWithPassivationTest")
public class ReplAndStateTransferWithPassivationTest
{
public void testStateTransferOfPassivatedState() throws Exception
@@ -142,13 +145,21 @@
cache1.evict(A);
cache2 = new UnitTestCacheFactory().createCache(buildConf(nls, "cache2", false, useBR, true), getClass());
+ TestingUtil.blockUntilViewReceived((CacheSPI)cache2, 2, 10000);
+
if (useBR)
{
+ BuddyReplicationTestsBase.waitForSingleBuddy(cache1, cache2);
Set backupNameSet = new HashSet(nameSet);
backupNameSet.remove(BuddyFqnTransformer.BUDDY_BACKUP_SUBTREE);
+
+ ReplicationListener replListener1 = ReplicationListener.getReplicationListener(cache1);
+ replListener1.expect(DataGravitationCleanupCommand.class);
cache2.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
Node backupNode = cache2.getNode(fqn);
- assert backupNode.getChildrenNames().equals(backupNameSet) : "Expecting " + backupNameSet + " but got " + backupNode.getChildrenNames();
+ replListener1.waitForReplicationToOccur();
+
+ assert backupNode.getChildrenNames().equals(backupNameSet) : "Expecting " + backupNameSet + " but got " + backupNode.getChildrenNames();
}
else
{
17 years, 2 months
JBoss Cache SVN: r7505 - core/trunk/src/test/java/org/jboss/cache/lock.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-19 04:42:32 -0500 (Mon, 19 Jan 2009)
New Revision: 7505
Modified:
core/trunk/src/test/java/org/jboss/cache/lock/ReadWriteLockWithUpgradeTest.java
Log:
more strict threading control
Modified: core/trunk/src/test/java/org/jboss/cache/lock/ReadWriteLockWithUpgradeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/ReadWriteLockWithUpgradeTest.java 2009-01-18 19:36:17 UTC (rev 7504)
+++ core/trunk/src/test/java/org/jboss/cache/lock/ReadWriteLockWithUpgradeTest.java 2009-01-19 09:42:32 UTC (rev 7505)
@@ -8,6 +8,7 @@
import java.util.Vector;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;
/**
@@ -82,183 +83,214 @@
* <p/>
* Each test case should also call cleanLockingResult() to reset
* result vector for the next test cases.
- *
- * @param caseNum Arbitrary string for the test case number.
- * @param name Arbitrary string for the calling thread name.
- * @param msecs Milliseconds that the thread should sleep after
- * acquiring the read lock.
- * @param errMsg Error msg to log in case of error.
- * @param secondOP Set to NO_MORE_OP if a 2nd lock request is not required.
- * Set to INVOKE_READ, INVOKE_READ or INVOKE_UPGRADE
- * respectively if the 2nd lock is a read, write or
- * upgrade request respectively.
*/
- protected Thread readThread(final String caseNum, final String name,
- final long msecs, final long sleepSecs,
- final String errMsg, final int secondOP)
+ class ReadThread extends Thread
{
- return new Thread(name)
- {
- public void run()
- {
- Lock rlock = lock_.readLock();
- try
- {
- if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
- {
- String str = caseNum + "-" + name + "-RL-0";
- postLockingResult(str);
- return;
- }
- // OK, read lock obtained, sleep and release it.
- String str = caseNum + "-" + name + "-RL-1";
- postLockingResult(str);
- TestingUtil.sleepThread(sleepSecs);
- if (secondOP == INVOKE_READ)
- {
- acquireReadLock(caseNum, name, msecs, errMsg);
- }
- else if (secondOP == INVOKE_WRITE)
- {
- acquireWriteLock(caseNum, name, msecs, errMsg);
- }
- else if (secondOP == INVOKE_UPGRADE)
- {
- acquireUpgradeLock(caseNum, name, msecs, errMsg);
- }
+ private String caseNum;
+ private String name;
+ volatile CountDownLatch notifyBeforeSecondOp = new CountDownLatch(1);
+ volatile CountDownLatch notifyBeforeFinish = new CountDownLatch(1);
+ volatile CountDownLatch waitLatch;
+ private String errMsg;
+ private int secondOP;
- rlock.unlock();
- }
- catch (Exception ex)
- {
- }
- }
- };
- }
+ ReadThread(String caseNum, String name, String errMsg, int secondOP, CountDownLatch waitLatch) {
+ this.caseNum = caseNum;
+ this.name = name;
+ this.errMsg = errMsg;
+ this.secondOP = secondOP;
+ this.waitLatch = waitLatch;
+ }
- /**
- * Creates a new thread and acquires a write lock with a timeout
- * value specified by the caller. Similar to {@link #readThread readThread()}
- * except it's used for write locks.
- *
- * @see #readThread readThread()
- */
- protected Thread writeThread(final String caseNum, final String name,
- final long msecs, final long sleepSecs,
- final String errMsg, final int secondOP)
- {
- return new Thread(name)
- {
- public void run()
- {
- try
- {
- Lock wlock = lock_.writeLock();
- if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
- {
- String str = caseNum + "-" + name + "-WL-0";
- postLockingResult(str);
- return;
- }
- // OK, write lock obtained, sleep and release it.
- String str = caseNum + "-" + name + "-WL-1";
- postLockingResult(str);
- TestingUtil.sleepThread(sleepSecs);
+ public void run()
+ {
+ Lock rlock = lock_.readLock();
+ try
+ {
+ if (!rlock.tryLock(0, TimeUnit.MILLISECONDS))
+ {
+ String str = caseNum + "-" + name + "-RL-0";
+ postLockingResult(str);
+ processNotifications();
+ return;
+ }
+ // OK, read lock obtained, sleep and release it.
+ String str = caseNum + "-" + name + "-RL-1";
+ postLockingResult(str);
+ processNotifications();
- if (secondOP == INVOKE_READ)
- {
- acquireReadLock(caseNum, name, msecs, errMsg);
- }
- else if (secondOP == INVOKE_WRITE)
- {
- acquireWriteLock(caseNum, name, msecs, errMsg);
- }
- else if (secondOP == INVOKE_UPGRADE)
- {
- acquireUpgradeLock(caseNum, name, msecs, errMsg);
- }
+ if (secondOP == INVOKE_READ)
+ {
+ acquireReadLock(caseNum, name, errMsg);
+ }
+ else if (secondOP == INVOKE_WRITE)
+ {
+ acquireWriteLock(caseNum, name, errMsg);
+ }
+ else if (secondOP == INVOKE_UPGRADE)
+ {
+ acquireUpgradeLock(caseNum, name, errMsg);
+ }
+ rlock.unlock();
+ notifyBeforeFinish.countDown();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
- wlock.unlock();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- };
+ private void processNotifications() throws InterruptedException {
+ notifyBeforeSecondOp.countDown();
+ if (waitLatch != null) waitLatch.await(10, TimeUnit.SECONDS);
+ }
}
- /**
- * Creates a new thread, acquires a read lock, sleeps for a while
- * and then tries to upgrade the read lock to a write one. Similar
- * to {@link #readThread readThread()} except it's used for upgrading
- * locks.
- *
- * @see #readThread readThread()
- */
- protected Thread upgradeThread(final String caseNum, final String name,
- final long msecs, final String errMsg)
- {
- return new Thread(name)
- {
- public void run()
- {
- try
- {
- Lock rlock = lock_.readLock();
- Lock wlock = null;
- if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
- {
- String str = caseNum + "-" + name + "-RL-0";
- postLockingResult(str);
- return;
- }
- // OK, read lock obtained, sleep and upgrade it later.
- TestingUtil.sleepThread(SLEEP_MSECS / 2);
- String str = caseNum + "-" + name + "-UL-";
- if ((wlock = lock_.upgradeLockAttempt(msecs)) == null)
- {
- str += "0";
- }
- else
- {
- str += "1";
- }
- postLockingResult(str);
- // Sleep again and then release the lock.
- TestingUtil.sleepThread(SLEEP_MSECS);
- if (wlock != null)
- {
- wlock.unlock();
- }
- rlock.unlock();
- }
- catch (Exception ex)
- {
- }
- }
- };
- }
+ private class WriteThread extends Thread
+ {
+ String caseNum;
+ String name;
+ volatile CountDownLatch notifyLatch = new CountDownLatch(1);
+ volatile CountDownLatch waitLatch;
+ String errMsg;
+ int secondOP;
+ WriteThread(String caseNum, String name, String errMsg, int secondOP, CountDownLatch waitLatch) {
+ this.caseNum = caseNum;
+ this.name = name;
+ this.errMsg = errMsg;
+ this.secondOP = secondOP;
+ this.waitLatch = waitLatch;
+ }
+
+
+ public void run()
+ {
+ try
+ {
+ Lock wlock = lock_.writeLock();
+ if (!wlock.tryLock(0, TimeUnit.MILLISECONDS))
+ {
+ String str = caseNum + "-" + name + "-WL-0";
+ postLockingResult(str);
+ processNotifications();
+ return;
+ }
+ // OK, write lock obtained, sleep and release it.
+ String str = caseNum + "-" + name + "-WL-1";
+ postLockingResult(str);
+
+ processNotifications();
+
+ if (secondOP == INVOKE_READ)
+ {
+ acquireReadLock(caseNum, name, errMsg);
+ }
+ else if (secondOP == INVOKE_WRITE)
+ {
+ acquireWriteLock(caseNum, name, errMsg);
+ }
+ else if (secondOP == INVOKE_UPGRADE)
+ {
+ acquireUpgradeLock(caseNum, name, errMsg);
+ }
+
+ wlock.unlock();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ private void processNotifications() throws InterruptedException {
+ notifyLatch.countDown();
+ if (waitLatch != null)
+ waitLatch.await(10, TimeUnit.SECONDS);
+ }
+ }
+
+ class UpgradeThread extends Thread
+ {
+ String caseNum;
+ String name;
+ private CountDownLatch notifyBeforeFinish = new CountDownLatch(1);
+ private CountDownLatch notifyBeforeSecondOp = new CountDownLatch(1);
+ private CountDownLatch beforeUpgrateWait;
+ private CountDownLatch beforeFinishWait;
+ String errMsg;
+ int secondOP;
+
+ UpgradeThread(String caseNum, String name, String errMsg, int secondOP, CountDownLatch beforeUpgrateWait) {
+ this.caseNum = caseNum;
+ this.name = name;
+ this.errMsg = errMsg;
+ this.secondOP = secondOP;
+ this.beforeUpgrateWait = beforeUpgrateWait;
+ }
+
+ public void run()
+ {
+ try
+ {
+ Lock rlock = lock_.readLock();
+ Lock wlock;
+ if (!rlock.tryLock(0, TimeUnit.MILLISECONDS))
+ {
+ String str = caseNum + "-" + name + "-RL-0";
+ postLockingResult(str);
+ notifyBeforeFinish.countDown();
+ if (beforeUpgrateWait != null) beforeUpgrateWait.await(10, TimeUnit.SECONDS);
+ return;
+ }
+ // OK, read lock obtained, sleep and upgrade it later.
+ notifyBeforeSecondOp.countDown();
+ if (beforeUpgrateWait != null) beforeUpgrateWait.await(10, TimeUnit.SECONDS);
+ String str = caseNum + "-" + name + "-UL-";
+ if ((wlock = lock_.upgradeLockAttempt(0)) == null)
+ {
+ str += "0";
+ }
+ else
+ {
+ str += "1";
+ }
+ postLockingResult(str);
+ // Sleep again and then release the lock.
+ TestingUtil.sleepThread(SLEEP_MSECS);
+ if (wlock != null)
+ {
+ wlock.unlock();
+ }
+ rlock.unlock();
+ notifyBeforeFinish.countDown();
+ if (beforeFinishWait != null) beforeFinishWait.await(10, TimeUnit.SECONDS);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ }
+
+
/***************************************************************/
/* Utility functions to acquire RL and WL (no thread) */
/***************************************************************/
/**
* This routine tries to acquire a read lock with a timeout value
- * passed in by the caller. Like {@link #readThread readThread()}
- * it then stores the locking result in the result vector depending
+ * passed in by the caller. It then stores the locking result in the result vector depending
* on the outcome of the request.
*/
protected void acquireReadLock(final String caseNum, final String name,
- final long msecs, final String errMsg)
+ final String errMsg)
{
try
{
Lock rlock = lock_.readLock();
- if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
+ if (!rlock.tryLock(0, TimeUnit.MILLISECONDS))
{
String str = caseNum + "-" + name + "-RL-0";
postLockingResult(str);
@@ -279,13 +311,12 @@
* Same as {@link #acquireReadLock acquireReadLock()} except
* it's for write lock request.
*/
- protected void acquireWriteLock(final String caseNum, final String name,
- final long msecs, final String errMsg)
+ protected void acquireWriteLock(final String caseNum, final String name, final String errMsg)
{
try
{
Lock wlock = lock_.writeLock();
- if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
+ if (!wlock.tryLock(0, TimeUnit.MILLISECONDS))
{
String str = caseNum + "-" + name + "-WL-0";
postLockingResult(str);
@@ -307,12 +338,12 @@
* it's for upgrade lock request.
*/
protected void acquireUpgradeLock(final String caseNum, final String name,
- final long msecs, final String errMsg)
+ final String errMsg)
{
try
{
Lock ulock = null;
- if ((ulock = lock_.upgradeLockAttempt(msecs)) == null)
+ if ((ulock = lock_.upgradeLockAttempt(0)) == null)
{
String str = caseNum + "-" + name + "-UL-0";
postLockingResult(str);
@@ -378,10 +409,8 @@
public void testWriteWithMultipleReaders() throws Exception
{
String caseNum = "10";
- Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS * 2,
- "1st read lock attempt failed", NO_MORE_OP);
- Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
- "2nd read lock attempt failed", INVOKE_WRITE);
+ ReadThread t1 = new ReadThread(caseNum, "t1", "1st read lock attempt failed", NO_MORE_OP, null);
+ ReadThread t2 = new ReadThread(caseNum, "t2", "2nd read lock attempt failed", INVOKE_WRITE, t1.notifyBeforeSecondOp);
t1.start();
t2.start();
@@ -404,10 +433,8 @@
public void testUpgradeWithMultipleReadersOn1() throws Exception
{
String caseNum = "11";
- Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
- "1st read lock attempt failed", INVOKE_WRITE);
- Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS * 2,
- "2nd read lock attempt failed", NO_MORE_OP);
+ ReadThread t1 = new ReadThread(caseNum, "t1", "1st read lock attempt failed", INVOKE_WRITE, null);
+ ReadThread t2 = new ReadThread(caseNum, "t2", "2nd read lock attempt failed", NO_MORE_OP, t1.notifyBeforeSecondOp);
t1.start();
t2.start();
@@ -430,8 +457,7 @@
public void testUpgradeReadLock() throws Exception
{
String caseNum = "2";
- Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
- "1st read lock attempt failed", INVOKE_UPGRADE);
+ Thread t1 = new ReadThread(caseNum, "t1", "1st read lock attempt failed", INVOKE_UPGRADE, null);
t1.start();
t1.join(3000);
@@ -443,12 +469,11 @@
/**
* Case #3 - T1 acquires RL followed by WL.
*/
-
public void testReadThenWrite() throws Exception
{
String caseNum = "3";
- acquireReadLock(caseNum, "t1", 0, "1st read lock attempt failed");
- acquireWriteLock(caseNum, "t1.1", 0, "2nd write lock attempt failed");
+ acquireReadLock(caseNum, "t1", "1st read lock attempt failed");
+ acquireWriteLock(caseNum, "t1.1", "2nd write lock attempt failed");
assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
checkLockingResult(caseNum + "-t1.1-WL-1"));
cleanLockingResult();
@@ -458,12 +483,11 @@
/**
* Case #5 - T1 acquires WL followed by RL.
*/
-
public void testWriteThenRead() throws Exception
{
String caseNum = "5";
- acquireWriteLock(caseNum, "t1", 0, "1st write lock attempt failed");
- acquireReadLock(caseNum, "t1.1", 0, "2nd read lock attempt failed");
+ acquireWriteLock(caseNum, "t1", "1st write lock attempt failed");
+ acquireReadLock(caseNum, "t1.1", "2nd read lock attempt failed");
assertTrue(checkLockingResult(caseNum + "-t1-WL-1") &&
checkLockingResult(caseNum + "-t1.1-RL-1"));
cleanLockingResult();
@@ -475,10 +499,8 @@
public void testMultipleReadlock() throws Exception
{
String caseNum = "6";
- Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
- "1st read lock attempt failed", NO_MORE_OP);
- Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
- "2nd read lock attempt failed", NO_MORE_OP);
+ Thread t1 = new ReadThread(caseNum, "t1", "1st read lock attempt failed", NO_MORE_OP, null);
+ Thread t2 = new ReadThread(caseNum, "t2", "2nd read lock attempt failed", NO_MORE_OP, null);
t1.start();
t2.start();
@@ -500,16 +522,22 @@
public void testWriteWithExistingReader() throws Exception
{
String caseNum = "8";
- Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
- "1st write lock attempt failed", NO_MORE_OP);
- Thread t2 = writeThread(caseNum, "t2", 0, SLEEP_MSECS,
- "2nd read lock attempt failed", NO_MORE_OP);
+ CountDownLatch waitFor = new CountDownLatch(1);
+ ReadThread t1 = new ReadThread(caseNum, "t1", "1st write lock attempt failed", NO_MORE_OP, waitFor);
+ WriteThread t2 = new WriteThread(caseNum, "t2", "2nd read lock attempt failed", NO_MORE_OP, waitFor);
t1.start();
t2.start();
+
+ t1.notifyBeforeSecondOp.await();
+ t2.notifyLatch.await();
+ waitFor.countDown();
+
+ waitFor.countDown();
t1.join(3000);
t2.join(3000);
+
// there is NO guarantee as to which thread will get the lock!!
boolean t0GetsLock = checkLockingResult(caseNum + "-t1-RL-1") && checkLockingResult(caseNum + "-t2-WL-0");
boolean t1GetsLock = checkLockingResult(caseNum + "-t1-RL-0") && checkLockingResult(caseNum + "-t2-WL-1");
@@ -531,13 +559,17 @@
public void testReadWithExistingWriter() throws Exception
{
String caseNum = "13";
- Thread t1 = writeThread(caseNum, "t1", 0, SLEEP_MSECS,
- "1st write lock attempt failed", NO_MORE_OP);
- Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
- "2nd read lock attempt failed", NO_MORE_OP);
+ CountDownLatch waitFor = new CountDownLatch(1);
+ WriteThread t1 = new WriteThread(caseNum, "t1", "1st write lock attempt failed", NO_MORE_OP, waitFor);
+ ReadThread t2 = new ReadThread(caseNum, "t2", "2nd read lock attempt failed", NO_MORE_OP, waitFor);
t1.start();
t2.start();
+
+ t1.notifyLatch.await();
+ t2.notifyBeforeSecondOp.await();
+ waitFor.countDown();
+
t1.join(3000);
t2.join(3000);
@@ -562,13 +594,16 @@
public void testMultipleWritelocks() throws Exception
{
String caseNum = "14";
- Thread t1 = writeThread(caseNum, "t1", 0, SLEEP_MSECS,
- "1st write lock attempt failed", NO_MORE_OP);
- Thread t2 = writeThread(caseNum, "t2", 0, SLEEP_MSECS,
- "2nd write lock attempt failed", NO_MORE_OP);
+ CountDownLatch waitFor = new CountDownLatch(1);
+ WriteThread t1 = new WriteThread(caseNum, "t1", "1st write lock attempt failed", NO_MORE_OP, waitFor);
+ WriteThread t2 = new WriteThread(caseNum, "t2", "2nd write lock attempt failed", NO_MORE_OP, waitFor);
t1.start();
t2.start();
+ t1.notifyLatch.await();
+ t2.notifyLatch.await();
+ waitFor.countDown();
+
t1.join(3000);
t2.join(3000);
@@ -590,21 +625,23 @@
/**
* Case #7 - T1 acquires RL, T2 acquires UL.
*/
-
public void testUpgradeWithExistingReader() throws Exception
{
String caseNum = "7";
- Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS,
- "1st read lock attempt failed", NO_MORE_OP);
- Thread t2 = upgradeThread(caseNum, "t2", 0,
- "2nd upgrade lock attempt failed");
+ CountDownLatch waitFor = new CountDownLatch(1);
+ ReadThread t1 = new ReadThread(caseNum, "t1", "1st read lock attempt failed", NO_MORE_OP, waitFor);
+ UpgradeThread t2 = new UpgradeThread(caseNum, "t2", "2nd upgrade lock attempt failed", NO_MORE_OP, t1.notifyBeforeSecondOp);
+ t2.beforeFinishWait = waitFor;
t1.start();
t2.start();
+ t2.notifyBeforeFinish.await(10, TimeUnit.SECONDS);
+ waitFor.countDown();
+
t1.join(3000);
t2.join(3000);
- assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
- checkLockingResult(caseNum + "-t2-UL-0"));
+ assertTrue(checkLockingResult(caseNum + "-t1-RL-1"));
+ assertTrue(checkLockingResult(caseNum + "-t2-UL-0"));
cleanLockingResult();
// possilbe deadlock check
if (t1.isAlive() || t2.isAlive())
@@ -619,13 +656,17 @@
public void testUpgradeWithMultipleReaders() throws Exception
{
String caseNum = "9";
- Thread t1 = readThread(caseNum, "t1", 0, SLEEP_MSECS * 2,
- "1st read lock attempt failed", NO_MORE_OP);
- Thread t2 = readThread(caseNum, "t2", 0, SLEEP_MSECS,
- "2nd read lock attempt failed", INVOKE_UPGRADE);
+ CountDownLatch waitFor = new CountDownLatch(1);
+ ReadThread t1 = new ReadThread(caseNum, "t1", "1st read lock attempt failed", NO_MORE_OP, waitFor);
+ ReadThread t2 = new ReadThread(caseNum, "t2", "2nd read lock attempt failed", INVOKE_UPGRADE, t1.notifyBeforeSecondOp);
t1.start();
t2.start();
+
+ t1.notifyBeforeSecondOp.await(10, TimeUnit.SECONDS);
+ t2.notifyBeforeFinish.await(10, TimeUnit.SECONDS);
+ waitFor.countDown();
+
t1.join(3000);
t2.join(3000);
assertTrue(checkLockingResult(caseNum + "-t1-RL-1") &&
17 years, 2 months
JBoss Cache SVN: r7504 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-18 14:36:17 -0500 (Sun, 18 Jan 2009)
New Revision: 7504
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
Log:
more strict replication control
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2009-01-18 19:32:36 UTC (rev 7503)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2009-01-18 19:36:17 UTC (rev 7504)
@@ -11,6 +11,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.UnitTestCacheFactory;
import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.util.TestingUtil;
@@ -184,6 +185,7 @@
caches.get(2).getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
// should cause a gravitation event
+ replListener0.expect(PutDataMapCommand.class);
replListener0.expect(DataGravitationCleanupCommand.class);
replListener1.expect(DataGravitationCleanupCommand.class);
assertEquals(value, caches.get(2).get(fqn, key));
17 years, 2 months
JBoss Cache SVN: r7503 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-18 14:32:36 -0500 (Sun, 18 Jan 2009)
New Revision: 7503
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesNoPoolNoDataGravitationTest.java
Log:
more strict replication control
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesNoPoolNoDataGravitationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesNoPoolNoDataGravitationTest.java 2009-01-18 18:42:24 UTC (rev 7502)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesNoPoolNoDataGravitationTest.java 2009-01-18 19:32:36 UTC (rev 7503)
@@ -2,7 +2,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
import org.jboss.cache.util.CachePrinter;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.util.internals.replicationlisteners.ReplicationListener;
@@ -13,6 +16,7 @@
import static org.testng.AssertJUnit.assertTrue;
import java.util.List;
+import java.util.ArrayList;
/**
* @author Mircea.Markus(a)jboss.com
@@ -20,10 +24,18 @@
@Test(groups = "functional", testName = "buddyreplication.Buddy3NodesNoPoolNoDataGravitationTest")
public class Buddy3NodesNoPoolNoDataGravitationTest extends AbstractNodeBasedBuddyTest
{
+
+ List<ReplicationListener> replListener = new ArrayList<ReplicationListener>();
+
@BeforeClass
public void createCaches() throws Exception
{
caches = createCaches(3, false, false);
+ for (Cache c : caches)
+ {
+ ReplicationListener listener = ReplicationListener.getReplicationListener(c);
+ replListener.add(listener);
+ }
}
public void testSingleBuddy() throws Exception
@@ -128,7 +140,10 @@
{
Fqn fqn = Fqn.fromString("/test");
Fqn backupFqn = fqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), fqn);
+
+ replListener.get(1).expect(PutKeyValueCommand.class);
caches.get(0).put(fqn, key, value);
+ replListener.get(1).waitForReplicationToOccur();
TestingUtil.dumpCacheContents(caches);
@@ -142,12 +157,16 @@
assertNoLocks(caches);
backupFqn = fqnTransformer.getBackupFqn(caches.get(1).getLocalAddress(), fqn);
- ReplicationListener replicationListener0 = ReplicationListener.getReplicationListener(caches.get(0));
- replicationListener0.expect(DataGravitationCleanupCommand.class);
+ replListener.get(0).expect(DataGravitationCleanupCommand.class);
+ replListener.get(2).expect(DataGravitationCleanupCommand.class);
+ replListener.get(2).expect(PutDataMapCommand.class);
+
caches.get(1).getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
+ log.info("Before gravitation call...");
assertEquals("value", caches.get(1).get(fqn, key));
- replicationListener0.waitForReplicationToOccur(); // cleanup commands are async
+ replListener.get(0).waitForReplicationToOccur(); // cleanup commands are async
+ replListener.get(2).waitForReplicationToOccur(); // cleanup commands are async
TestingUtil.dumpCacheContents(caches);
17 years, 2 months
JBoss Cache SVN: r7502 - core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-18 13:42:24 -0500 (Sun, 18 Jan 2009)
New Revision: 7502
Modified:
core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java
Log:
more verbose logging
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java 2009-01-18 17:46:06 UTC (rev 7501)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/ConcurrentTransactionalTest.java 2009-01-18 18:42:24 UTC (rev 7502)
@@ -42,12 +42,8 @@
private Log logger_ = LogFactory.getLog(ConcurrentTransactionalTest.class);
private static Throwable thread_ex = null;
private static final int NUM = 10000;
+ Log log = LogFactory.getLog(ConcurrentTransactionalTest.class);
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception
- {
- }
-
private void createCache(IsolationLevel level)
{
Configuration conf = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, false);
@@ -130,6 +126,7 @@
}
catch (Exception e)
{
+ log.error("Exception here: " + e, e);
e.printStackTrace();
fail(e.toString());
}
17 years, 2 months
JBoss Cache SVN: r7501 - in core/trunk/src/test/java/org/jboss/cache: transaction/pessimistic and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-01-18 12:46:06 -0500 (Sun, 18 Jan 2009)
New Revision: 7501
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ParentVersionTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/AsyncRollbackTxTest.java
Log:
more strict replication control
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -125,13 +125,8 @@
return cache;
}
- protected void destroyCache(Cache<Object, Object> c)
- {
- TestingUtil.killCaches(c);
- }
-
- protected CacheSPI createPessimisticCache() throws Exception
+ protected CacheSPI createPessimisticCache() throws Exception
{
Configuration c = new Configuration();
c.setClusterName("name");
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -6,6 +6,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.transaction.TransactionSetup;
@@ -34,9 +35,9 @@
public void tearDown()
{
super.tearDown();
- destroyCache(cache);
- destroyCache(cache2);
- cache = null;
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
+ cache = null;
cache2 = null;
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -2,9 +2,9 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.lock.LockManager;
@@ -54,7 +54,7 @@
assertEquals(false, cache.exists(Fqn.fromString("/one/two")));
assertNull(cache.getNode("/one"));
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
public void testSingleInstanceDuplicateCommit() throws Exception
@@ -102,7 +102,7 @@
assertNotNull(cache.getNode("/one/two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -167,7 +167,7 @@
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
public void test2InstanceCommit() throws Exception
@@ -228,8 +228,8 @@
assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
public void test2InstanceRemove() throws Exception
@@ -299,8 +299,8 @@
assertEquals(null, cache.get("/one/two", "key1"));
assertEquals(false, cache2.exists("/one/two"));
assertEquals(null, cache2.get("/one/two", "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
public void testValidationFailCommit2Instances() throws Exception
@@ -375,8 +375,8 @@
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -6,10 +6,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.VersionedNode;
+import org.jboss.cache.*;
import org.jboss.cache.commands.WriteCommand;
import org.jboss.cache.commands.tx.CommitCommand;
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
@@ -51,7 +48,7 @@
{
super.tearDown();
if (c != null)
- destroyCache(c);
+ TestingUtil.killCaches((Cache<Object, Object>) c);
c = null;
}
@@ -163,8 +160,8 @@
public void testRollbackTransaction() throws Exception
{
- destroyCache(c);
- c = createCacheWithListener();
+ TestingUtil.killCaches((Cache<Object, Object>) c);
+ c = createCacheWithListener();
MockInterceptor dummy = new MockInterceptor();
setAlteredInterceptorChain(dummy, c);
@@ -192,8 +189,8 @@
public void testRemotePrepareTransaction() throws Throwable
{
- destroyCache(c);
- c = createCacheWithListener();
+ TestingUtil.killCaches((Cache<Object, Object>) c);
+ c = createCacheWithListener();
MockInterceptor dummy = new MockInterceptor();
setAlteredInterceptorChain(dummy, c);
@@ -249,9 +246,9 @@
public void testRemoteCacheBroadcast() throws Exception
{
- destroyCache(c);
+ TestingUtil.killCaches((Cache<Object, Object>) c);
- CacheSPI<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
CacheSPI<Object, Object> cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
assertEquals(2, cache.getMembers().size());
assertEquals(2, cache2.getMembers().size());
@@ -285,15 +282,15 @@
assertTrue(cache2.exists(Fqn.fromString("/one")));
assertEquals("value", cache2.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
public void testTwoWayRemoteCacheBroadcast() throws Exception
{
- destroyCache(c);
- CacheSPI<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ TestingUtil.killCaches((Cache<Object, Object>) c);
+ CacheSPI<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
CacheSPI<Object, Object> cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
assertEquals(2, cache.getMembers().size());
assertEquals(2, cache2.getMembers().size());
@@ -330,8 +327,8 @@
assertEquals("value", cache2.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
@@ -428,7 +425,7 @@
c.removeNode(Fqn.fromString("/a/b"));
tm.commit();
- destroyCache(c);
+ TestingUtil.killCaches((Cache<Object, Object>) c);
}
public void testAddChildAfterRemoveParent() throws Exception
@@ -441,6 +438,6 @@
c.put(Fqn.fromString("/a/b"), "k", "v");
tm.commit();
- destroyCache(c);
+ TestingUtil.killCaches((Cache<Object, Object>) c);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -4,6 +4,7 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.lock.LockManager;
@@ -58,7 +59,7 @@
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
// flesh this out a bit more
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -94,7 +95,7 @@
assertEquals(2, listener.getNodesAdded());
assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -133,7 +134,7 @@
assertEquals(false, lockManager.isLocked(cache.getNode("/one/two")));
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -163,7 +164,7 @@
assertEquals(false, cache.exists(Fqn.fromString("/one/two")));
assertNull(cache.getRoot().getChild("one"));
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -212,7 +213,7 @@
assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -278,7 +279,7 @@
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -337,8 +338,8 @@
assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
public void test2InstanceRemove() throws Exception
@@ -403,8 +404,8 @@
assertEquals(null, cache.get("/one/two", "key1"));
assertEquals(null, cache2.get("/one/two", "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
public void testValidationFailCommit2Instances() throws Exception
@@ -479,8 +480,8 @@
assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
- destroyCache(cache);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
@@ -526,7 +527,7 @@
// assert we can't see the change from tx2 as we already touched the node
assertEquals(null, cache.get("/one/two", "key2"));
mgr.commit();
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
public void testGetKeysIsolationTransaction() throws Exception
@@ -569,7 +570,7 @@
// assert we can't see thge change from tx2 as we already touched the node
assertEquals(1, cache.getNode("/one/two").getKeys().size());
mgr.commit();
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
@@ -627,7 +628,7 @@
keys = cache.getNode("/one/two").getKeys();
assertEquals(2, keys.size());// key1 and key2
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
protected CacheSPI<Object, Object> createSyncReplicatedCache() throws Exception
@@ -754,8 +755,8 @@
//cache2.get(Fqn.fromString("/profiler/node" + i));
}
- destroyCache(cache1);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache1);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
catch (Exception e)
{
@@ -798,7 +799,7 @@
assertEquals("Known issue JBCACHE-1201: Correct node2 value", VALUE1, cache2.get(fqn, KEY));
assertEquals("Correct node1 value", VALUE1, cache1.get(fqn, KEY));
- destroyCache(cache1);
- destroyCache(cache2);
+ TestingUtil.killCaches((Cache<Object, Object>) cache1);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -2,6 +2,8 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
@@ -35,8 +37,8 @@
public void tearDown()
{
super.tearDown();
- destroyCache(cache);
- cache = null;
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ cache = null;
}
public void testExists() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -12,6 +12,8 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import org.jboss.cache.Cache;
+import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
@@ -47,9 +49,9 @@
public void tearDown()
{
super.tearDown();
- destroyCache(cache1);
- destroyCache(cache2);
- cache1 = null;
+ TestingUtil.killCaches((Cache<Object, Object>) cache1);
+ TestingUtil.killCaches((Cache<Object, Object>) cache2);
+ cache1 = null;
cache2 = null;
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ParentVersionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ParentVersionTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ParentVersionTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -5,6 +5,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -45,8 +46,8 @@
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- destroyCache(cache);
- cache = null;
+ TestingUtil.killCaches(cache);
+ cache = null;
}
private long getVersion(Node n)
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -3,8 +3,11 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.Cache;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.replicationlisteners.ReplicationListener;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.AfterMethod;
@@ -16,20 +19,24 @@
/**
* Tests removal of a node before the node is even created.
*/
-@Test(groups = {"functional", "optimistic"}, sequential = true, testName = "optimistic.RemoveBeforeCreateTest")
+@Test(groups = {"functional", "optimistic"}, testName = "optimistic.RemoveBeforeCreateTest")
public class RemoveBeforeCreateTest extends AbstractOptimisticTestCase
{
CacheSPI<Object, Object>[] c = null;
+ ReplicationListener[] replListeners;
TransactionManager t;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
c = new CacheSPI[2];
+ replListeners = new ReplicationListener[2];
c[0] = createReplicatedCache(Configuration.CacheMode.REPL_ASYNC);
c[1] = createReplicatedCache(Configuration.CacheMode.REPL_ASYNC);
- TestingUtil.blockUntilViewsReceived(c, 20000);
+ TestingUtil.blockUntilViewsReceived(c, 20000);
+ replListeners[0] = ReplicationListener.getReplicationListener(c[0]);
+ replListeners[1] = ReplicationListener.getReplicationListener(c[1]);
t = c[0].getTransactionManager();
}
@@ -39,19 +46,20 @@
{
if (c != null)
{
- destroyCache(c[0]);
- destroyCache(c[1]);
- c = null;
+ TestingUtil.killCaches((Cache<Object, Object>) c[0]);
+ TestingUtil.killCaches((Cache<Object, Object>) c[1]);
+ c = null;
}
}
@SuppressWarnings("unchecked")
public void testControl() throws Exception
{
+ replListeners[1].expectWithTx(PutKeyValueCommand.class);
t.begin();
c[0].put("/control", "key", "value");
t.commit();
- TestingUtil.sleepThread(200);
+ replListeners[1].waitForReplicationToOccur();
assertEquals("value", c[0].get("/control", "key"));
assertEquals("value", c[1].get("/control", "key"));
@@ -72,12 +80,13 @@
assertNull(c[0].getNode(f));
assertNull(c[1].getNode(f));
+ replListeners[1].expectWithTx(PutKeyValueCommand.class);
t.begin();
c[0].removeNode(f);
// should NOT barf!!!
t.commit();
- TestingUtil.sleepThread(200);
+ replListeners[1].waitForReplicationToOccur();
assertNull(c[0].getNode(f));
assertNull(c[1].getNode(f));
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -9,6 +9,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Cache;
+import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -40,8 +42,8 @@
public void tearDown()
{
super.tearDown();
- destroyCache(cache);
- cache = null;
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ cache = null;
threads = null;
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -7,6 +7,8 @@
package org.jboss.cache.optimistic;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Cache;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
@@ -58,6 +60,6 @@
// nothing should have been locked.
assertEquals(0, cache.getNumberOfLocksHeld());
- destroyCache(cache);
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -2,6 +2,8 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
@@ -32,8 +34,8 @@
public void tearDown()
{
super.tearDown();
- destroyCache(cache);
- cache = null;
+ TestingUtil.killCaches((Cache<Object, Object>) cache);
+ cache = null;
}
public void testUpdateOnWrite() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/AsyncRollbackTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/AsyncRollbackTxTest.java 2009-01-18 17:16:23 UTC (rev 7500)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/pessimistic/AsyncRollbackTxTest.java 2009-01-18 17:46:06 UTC (rev 7501)
@@ -126,7 +126,6 @@
doTest(false, true);
}
- @Test (invocationCount = 1000)
public void testCommitCreationInDifferentTxWriteLock() throws Throwable
{
doTest(true, true);
17 years, 2 months