Author: manik.surtani(a)jboss.com
Date: 2007-12-27 15:40:54 -0500 (Thu, 27 Dec 2007)
New Revision: 4920
Modified:
core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.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/LockParentVersionTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java
core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java
Log:
Updated optimistic tests and optimised dependency detection during component registration
Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2007-12-27 20:20:04
UTC (rev 4919)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2007-12-27 20:40:54
UTC (rev 4920)
@@ -132,14 +132,8 @@
// injection bootstrap stuff
componentRegistry = cache.getComponentRegistry();
- // and the configuration
- componentRegistry.registerComponent(configuration);
this.configuration = configuration;
- // and the component registry itself. This bit of recursiveness is needed for
factories that are also components.
- // See NodeFactory for example, which is created by an EmptyConstructorFactory
- componentRegistry.registerComponent(componentRegistry);
-
// make sure we set the CacheImpl and CacheSPI instance in the component registry.
componentRegistry.registerComponent(cache);
componentRegistry.registerComponent(CacheSPI.class.getName(), spi);
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-27
20:20:04 UTC (rev 4919)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -59,6 +59,8 @@
*/
public class ComponentRegistry
{
+ static final Object NULL_COMPONENT = new Object();
+
State overallState = CONSTRUCTED;
/**
@@ -81,6 +83,7 @@
public ComponentRegistry(Configuration configuration)
{
// bootstrap.
+ registerComponent(this);
registerComponent(configuration);
}
@@ -125,9 +128,10 @@
// components that depended on the old component should now depend on the new
one.
c.dependencyFor.addAll(old.dependencyFor);
}
- addComponentDependencies(c);
+ componentLookup.put(name, c);
- componentLookup.put(name, c);
+ addComponentDependencies(c, old == null);
+
State stateToMoveTo = overallState == null ? CONSTRUCTED : overallState;
c.changeState(stateToMoveTo);
@@ -138,7 +142,7 @@
}
}
- protected void addComponentDependencies(Component c)
+ protected void addComponentDependencies(Component c, boolean firstTimeAdded)
{
// build any dependent components if necessary
for (Dependency d : c.dependencies)
@@ -147,6 +151,16 @@
Component dependencyComponent = componentLookup.get(d.name);
if (dependencyComponent != null)
dependencyComponent.dependencyFor.add(c.asDependency());
}
+
+ if (firstTimeAdded)
+ {
+ // loop through all other components already registered and make sure the
current component's dependencyFor map is accurate
+ for (Component other : componentLookup.values())
+ {
+ if (other.dependencies.contains(c.asDependency()))
c.dependencyFor.add(other.asDependency());
+ }
+ }
+
}
public <T> T getComponent(Class<T> c)
@@ -167,9 +181,9 @@
Component wrapper = componentLookup.get(name);
if (wrapper == null) return null;
- T component = (T) wrapper.instance;
+ T component = (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
- if (c.isAssignableFrom(component.getClass())) return component;
+ if (component == null || c.isAssignableFrom(component.getClass())) return
component;
else
throw new ConfigurationException("Component registered under " + name
+ " is of type " + component.getClass() + " and cannot be assigned to
" + c);
}
@@ -224,27 +238,37 @@
{
// first see if this has been injected externally.
component = getFromConfiguration(componentClass);
+ boolean attemptedFactoryConstruction = false;
if (component == null && isNonBootstrap(componentClass))
{
// create this component and add it to the registry
ComponentFactory factory = getFactory(componentClass);
component = factory.construct(componentName, componentClass);
+ attemptedFactoryConstruction = true;
+
}
+ String componentNameToUse = componentName == null ? componentClass.getName() :
componentName;
+
if (component != null)
{
- // wire dependencies
-// wireDependencies(component);
- if (componentName == null)
- registerComponent(componentClass.getName(), component);
- else
- registerComponent(componentName, component);
+ registerComponent(componentNameToUse, component);
}
+ else if (attemptedFactoryConstruction)
+ {
+ registerNullComponent(componentNameToUse);
+ }
}
return component;
}
+ // registers a special "null" component that has no dependencies.
+ void registerNullComponent(String componentName)
+ {
+ registerComponent(componentName, NULL_COMPONENT);
+ }
+
private boolean isNonBootstrap(Class<?> componentClass)
{
return !(componentClass.equals(CacheSPI.class) ||
componentClass.equals(CacheImpl.class) || componentClass.equals(Cache.class)
@@ -566,10 +590,10 @@
Component impl = componentLookup.get(CacheImpl.class.getName());
Component conf = componentLookup.get(Configuration.class.getName());
Component cr = componentLookup.get(ComponentRegistry.class.getName());
- addComponentDependencies(spi);
- addComponentDependencies(impl);
- addComponentDependencies(conf);
- addComponentDependencies(cr);
+ addComponentDependencies(spi, true);
+ addComponentDependencies(impl, true);
+ addComponentDependencies(conf, true);
+ addComponentDependencies(cr, true);
}
/**
@@ -671,14 +695,6 @@
// now for each injection method, get dependencies
for (Method m : injectionMethods)
dependencies.addAll(getDeclaredDependencies(m));
-
- // backward-chaining - make sure I know about components that depend on me.
- me = asDependency();
- for (Dependency d : dependencies)
- {
- Component c = componentLookup.get(d.name);
- if (c != null) c.dependencyFor.add(me);
- }
}
/**
Modified:
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -1,7 +1,7 @@
package org.jboss.cache.factories;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.RPCManager;
import org.jboss.cache.RegionManager;
@@ -10,7 +10,6 @@
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.invocation.CacheInvocationDelegate;
import org.jboss.cache.marshall.CacheMarshaller200;
import org.jboss.cache.marshall.CacheMarshaller210;
import org.jboss.cache.marshall.Marshaller;
@@ -21,8 +20,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.lang.reflect.Constructor;
-
/**
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
* @since 2.1.0
@@ -36,25 +33,11 @@
@BeforeMethod
public void setUp() throws Exception
{
- ComponentFactory cf = (ComponentFactory) new DefaultCacheFactory();
+ CacheFactory cf = new DefaultCacheFactory();
- CacheSPI spi = new CacheInvocationDelegate();
- Constructor ctor = CacheImpl.class.getDeclaredConstructor();
- ctor.setAccessible(true);
- CacheImpl ci = (CacheImpl) ctor.newInstance();
-
- configuration = ci.getConfiguration();
- cr = TestingUtil.extractComponentRegistry(ci);
-
- cf.componentRegistry = cr;
- cf.configuration = configuration;
-
- cr.registerComponent(cr); // register self
- cr.registerComponent(ci);
- cr.registerComponent(spi);
- cr.registerComponent(configuration);
-
- cr.wire();
+ Cache cache = cf.createCache(false);
+ cr = TestingUtil.extractComponentRegistry(cache);
+ configuration = cache.getConfiguration();
}
public void testDefaultFactoryScanning()
@@ -71,6 +54,28 @@
}
+ public void testDependencyConsistency()
+ {
+ for (ComponentRegistry.Component component : cr.componentLookup.values())
+ {
+ // test that this component appears in all dependencies' dependencyFor
collection.
+ for (ComponentRegistry.Dependency dep : component.dependencies)
+ {
+ assert
cr.componentLookup.get(dep.name).dependencyFor.contains(component.asDependency()) :
"Dependency " + dep.name + " does not have component " +
component.name + " in it's dependencyFor collection.";
+ }
+ }
+
+ for (ComponentRegistry.Component component : cr.componentLookup.values())
+ {
+ // test that this component appears in all dependencies' dependencyFor
collection.
+ for (ComponentRegistry.Dependency dep : component.dependencyFor)
+ {
+ assert
cr.componentLookup.get(dep.name).dependencies.contains(component.asDependency()) :
"Dependency " + dep.name + " does not have component " +
component.name + " in it's dependencies collection.";
+ }
+ }
+ }
+
+
public void testNamedComponents()
{
cr.registerComponent("blah", new Object());
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -46,7 +46,7 @@
* @author manik
*/
@Test(groups = "functional")
-public abstract class AbstractOptimisticTestCase
+public class AbstractOptimisticTestCase
{
// some test data shared among all the test cases
protected Fqn<String> fqn = Fqn.fromString("/blah");
@@ -140,7 +140,6 @@
c.setClusterName("name");
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -158,7 +157,6 @@
c.setClusterName("name");
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(Configuration.CacheMode.LOCAL);
c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
@@ -170,23 +168,6 @@
return cache;
}
- protected String getDefaultProperties()
- {
- return "UDP(mcast_addr=228.1.2.3;mcast_port=48866;ip_ttl=32;" +
-
"mcast_send_buf_size=150000;mcast_recv_buf_size=80000;loopback=true;ip_mcast=true;bind_addr=127.0.0.1):"
+
- "PING(timeout=1000;num_initial_members=2):" +
- "MERGE2(min_interval=5000;max_interval=10000):" +
- "FD_SOCK:" +
- "VERIFY_SUSPECT(timeout=1500):" +
-
"pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800):"
+
- "UNICAST(timeout=600,1200,2400,4800):" +
- "pbcast.STABLE(desired_avg_gossip=20000):" +
- "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
- "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
- "shun=false;print_local_addr=true):" +
- "pbcast.STATE_TRANSFER";
- }
-
protected CacheSPI createReplicatedCache(Configuration.CacheMode mode) throws
Exception
{
return createReplicatedCache("test", mode);
@@ -204,7 +185,6 @@
c.setClusterName(name);
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(mode);
if (mode == Configuration.CacheMode.REPL_SYNC)
{
@@ -245,12 +225,11 @@
Configuration c = cache.getConfiguration();
c.setClusterName(name);
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(cacheMode);
c.setSyncCommitPhase(true);
c.setSyncRollbackPhase(true);
c.setNodeLockingScheme("OPTIMISTIC");
-
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setCacheLoaderConfig(getCacheLoaderConfig(shared, false));
cache.create();
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -30,7 +30,7 @@
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
*/
-@Test
+@Test(groups = "functional")
public class ConcurrentTransactionTest extends AbstractOptimisticTestCase
{
private CacheSPI<Object, Object> cache;
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -21,6 +21,7 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class FullStackInterceptorTest extends AbstractOptimisticTestCase
{
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -6,6 +6,7 @@
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -16,6 +17,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
+@Test(groups = "functional")
public class HasChildTest extends AbstractOptimisticTestCase
{
private CacheSPI<Object, Object> cache;
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/LockParentVersionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/LockParentVersionTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/LockParentVersionTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -1,9 +1,12 @@
package org.jboss.cache.optimistic;
+import org.testng.annotations.Test;
+
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
+@Test(groups = "functional")
public class LockParentVersionTest extends ParentVersionTest
{
public LockParentVersionTest()
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -1,14 +1,14 @@
package org.jboss.cache.optimistic;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodDeclarations;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Handles putXXX() methods: if the given node doesn't exist, it will be created
* (depending on the create_if_not_exists argument)
@@ -19,24 +19,19 @@
*/
public class MockFailureInterceptor extends Interceptor
{
- public void setCache(CacheSPI cache)
- {
- super.setCache(cache);
- }
-
private List<Method> allCalled = new ArrayList<Method>();
private List failurelist = new ArrayList();
+ @Override
public Object invoke(InvocationContext ctx) throws Throwable
{
MethodCall m = ctx.getMethodCall();
- if (failurelist.contains(m.getMethod()))
+ if (!MethodDeclarations.isBlockUnblockMethod(m.getMethodId()))
{
- throw new Exception("Failure in method" + m);
+ if (failurelist.contains(m.getMethod())) throw new Exception("Failure in
method " + m);
+ allCalled.add(m.getMethod());
}
- allCalled.add(m.getMethod());
-
return null;
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java 2007-12-27
20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -1,9 +1,9 @@
package org.jboss.cache.optimistic;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodDeclarations;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -19,20 +19,19 @@
*/
public class MockInterceptor extends Interceptor
{
- public void setCache(CacheSPI cache)
- {
- super.setCache(cache);
- }
-
private Method called = null;
private List<Method> calledlist = new ArrayList<Method>();
+ @Override
public synchronized Object invoke(InvocationContext ctx) throws Throwable
{
MethodCall m = ctx.getMethodCall();
- calledlist.add(m.getMethod());
- called = m.getMethod();
+ if (!MethodDeclarations.isBlockUnblockMethod(m.getMethodId()))
+ {
+ calledlist.add(m.getMethod());
+ called = m.getMethod();
+ }
return null;
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -11,6 +11,9 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -18,25 +21,40 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class NodeInterceptorGetKeyValTest extends AbstractOptimisticTestCase
{
- public void testTransactionGetKeyMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionGetKeyMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -83,26 +101,10 @@
assertNull(cache.get("/one/two", "key1"));
mgr.commit();
- cache.stop();
}
public void testTransactionGetKeyValOverwriteMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -139,27 +141,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
-
- cache.stop();
}
public void testTransactionGetKeyValOverwriteNullMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -195,27 +180,11 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTwoTransactionGetIsolationKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -287,8 +256,5 @@
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
-
-
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -11,33 +11,50 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import java.util.Iterator;
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class NodeInterceptorGetKeysTest extends AbstractOptimisticTestCase
{
- public void testTransactionGetKeysMethod() throws Exception
+ private TestListener listener;
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionGetKeysMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -84,27 +101,12 @@
assertNull(cache.get("/one/two", "key1"));
mgr.commit();
- cache.stop();
}
public void testTransactionGetNoKeysMethod() throws Exception
{
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -129,27 +131,10 @@
assertEquals(0, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
-
-
- cache.stop();
}
public void testTransactionGetKeysIteratorMethod() throws Exception
{
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -171,13 +156,6 @@
//assert we can see this with a key value get in the transaction
assertEquals(1, cache.getNode("/one/two").getKeys().size());
-
- for (Iterator<?> it =
cache.getNode("/one/two").getKeys().iterator(); it.hasNext();)
- {
- it.next();
- it.remove();
- }
- assertEquals(0, cache.getNode("/one/two").getKeys().size());
mgr.commit();
@@ -185,8 +163,5 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
-
-
- cache.stop();
}
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -11,6 +11,9 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -18,25 +21,40 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class NodeInterceptorKeyValTest extends AbstractOptimisticTestCase
{
- public void testTransactionPutKeyMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TestListener listener;
+ private MockInterceptor dummy;
+ private TransactionManager mgr;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionPutKeyMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -68,27 +86,11 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -124,26 +126,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteNullMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -177,27 +163,11 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionAdditionlaKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -233,26 +203,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTwoTransactionAdditionKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr =
cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -319,8 +273,5 @@
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
-
-
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -7,13 +7,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -21,25 +24,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorPutEraseTest extends AbstractOptimisticTestCase
{
- public void testTransactionPutKeyMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionPutKeyMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -71,26 +89,10 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -125,26 +127,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteNullMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -177,8 +163,5 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
-
-
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -7,13 +7,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -21,25 +24,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorPutMapTest extends AbstractOptimisticTestCase
{
- public void testTransactionPutDataMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionPutDataMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -73,26 +91,10 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionPutLocalOverwriteDataMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -129,27 +131,12 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionPutLocalEmptyMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
Fqn f = Fqn.fromString("/one/two");
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -165,7 +152,7 @@
Map temp2 = new HashMap();
- cache.put(f, temp2, true);
+ cache.getNode(f).replaceAll(temp2);
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -182,9 +169,8 @@
assertNotNull(workspace.getNode(f));
assertEquals(null, workspace.getNode(f).get("key1"));
assertTrue(entry.getLocks().isEmpty());
- assertEquals(2, entry.getModifications().size());
+ assertEquals(3, entry.getModifications().size());
assertTrue(!cache.exists(f));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -7,13 +7,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -21,25 +24,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorRemoveDataTest extends AbstractOptimisticTestCase
{
- public void testTransactionRemoveNoNodeDataMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionRemoveNoNodeDataMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -47,7 +65,7 @@
cache.getInvocationContext().setTransaction(tx);
cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx,
true));
- cache.getNode("/one/two").clearData();
+ assert null == cache.getNode("/one/two");
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -65,29 +83,13 @@
assertEquals(0, workspace.getNodes().size());
assertNull(workspace.getNode(Fqn.fromString("/one/two")));
assertTrue(entry.getLocks().isEmpty());
- assertEquals(1, entry.getModifications().size());
+ assertEquals(0, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveEmptyMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -122,26 +124,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveDataMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -178,27 +164,11 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveOtherNodeDataMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -211,7 +181,6 @@
temp.put("key1", pojo);
cache.put("/one/two", temp);
-
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -235,6 +204,5 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -13,13 +13,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -27,25 +30,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorRemoveKeyValTest extends AbstractOptimisticTestCase
{
- public void testTransactionRemoveNoNodeKeyValMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionRemoveNoNodeKeyValMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -64,7 +82,6 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
-
mgr.commit();
//assert what should be the results of our call
@@ -74,26 +91,10 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveNoKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -117,7 +118,6 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
-
mgr.commit();
//assert what should be the results of our call
@@ -129,26 +129,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -172,7 +156,6 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
-
mgr.commit();
//assert what should be the results of our call
@@ -183,6 +166,5 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
}
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -12,11 +12,13 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
/**
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorTransactionTest extends AbstractOptimisticTestCase
{
public void testNoTransactionCRUDMethod() throws Exception
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -18,6 +18,7 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -26,6 +27,7 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class OptimisticCreateIfNotExistsInterceptorTest extends
AbstractOptimisticTestCase
{
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -51,8 +51,7 @@
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- super.tearDown();
- destroyCache(cache);
+ TestingUtil.killCaches(cache);
}
public void testLocalTransaction() 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 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -14,6 +14,7 @@
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.RollbackException;
import javax.transaction.Transaction;
@@ -25,6 +26,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class OptimisticVersioningTest extends AbstractOptimisticTestCase
{
CacheSPI cache1, cache2;
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -10,6 +10,7 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.transaction.DummyTransactionManager;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
@@ -18,6 +19,7 @@
*
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
*/
+@Test(groups = "functional")
public class OptimisticWithCacheLoaderTest extends AbstractOptimisticTestCase
{
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -14,6 +14,7 @@
import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
+import org.testng.annotations.Test;
import org.w3c.dom.Element;
/**
@@ -21,6 +22,7 @@
*
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
*/
+@Test(groups = "functional")
public class OptimisticWithPassivationTest extends AbstractOptimisticTestCase
{
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -12,6 +12,7 @@
import org.jboss.cache.Fqn;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
import javax.transaction.TransactionManager;
@@ -20,6 +21,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
*/
+@Test(groups = "functional")
public class ThreadedCacheAccessTest extends AbstractOptimisticTestCase
{
private static final Log log = LogFactory.getLog(ThreadedCacheAccessTest.class);
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -16,6 +16,7 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -23,6 +24,7 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class ThreadedOptimisticCreateIfNotExistsInterceptorTest extends
AbstractOptimisticTestCase
{
protected synchronized void setTransactionsInInvocationCtx(TransactionManager mgr,
CacheSPI cache) throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -9,6 +9,7 @@
import org.jboss.cache.CacheSPI;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -18,6 +19,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani
(manik(a)jboss.org)</a>
*/
+@Test(groups = "functional")
public class ValidationFailureTest extends AbstractOptimisticTestCase
{
public void testValidationFailureLockRelease() throws Exception
Modified:
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -8,8 +8,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.interceptors.InvocationContextInterceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.interceptors.OptimisticValidatorInterceptor;
@@ -18,37 +20,62 @@
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.util.CachePrinter;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class ValidatorInterceptorTest extends AbstractOptimisticTestCase
{
- public void testTransactionvalidateMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
- CacheSPI<Object, Object> cache = createCacheWithListener();
+ cache = createCacheWithListener();
+ mgr = cache.getTransactionManager();
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
+ Interceptor ici = TestingUtil.findInterceptor(cache,
InvocationContextInterceptor.class);
+ Interceptor validateInterceptor = TestingUtil.findInterceptor(cache,
OptimisticValidatorInterceptor.class);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache,
OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache,
OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
+ ici.setNext(validateInterceptor);
validateInterceptor.setNext(interceptor);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
+ TestingUtil.replaceInterceptorChain(cache, ici);
+ cache.addInterceptor(new ResetRemoteFlagInterceptor(),
InvocationContextInterceptor.class);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ System.out.println("Interceptors: " +
CachePrinter.printCacheInterceptors(cache));
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+
+ public void testTransactionvalidateMethod() throws Throwable
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -68,13 +95,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object>
workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace =
entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo,
workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -85,15 +107,8 @@
assertEquals(null, dummy.getCalled());
//now let us do a prepare
- MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
- }
- catch (Throwable t)
- {
- // do nothing
- }
+ MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
assertEquals(3, workspace.getNodes().size());
@@ -103,31 +118,14 @@
assertTrue(entry.getLocks().isEmpty());
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
- assertEquals(null, dummy.getCalled());
+ assertEquals(prepareMethod.getMethod(), dummy.getCalled());
mgr.commit();
-
- destroyCache(cache);
}
public void testTransactionValidateFailureMethod() throws Exception
{
-
- CacheSPI<Object, Object> cache = createCacheWithListener();
-
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -147,13 +145,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object>
workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace =
entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo,
workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -166,7 +159,7 @@
//lets change one of the underlying version numbers
workspace.getNode(Fqn.fromString("/one/two")).getNode().setVersion(new
DefaultDataVersion(2));
//now let us do a prepare
- MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -179,27 +172,10 @@
mgr.commit();
-
- destroyCache(cache);
}
- public void testTransactionValidateCommitMethod() throws Exception
+ public void testTransactionValidateCommitMethod() throws Throwable
{
-
- CacheSPI<Object, Object> cache = createCacheWithListener();
-
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -207,10 +183,8 @@
cache.getInvocationContext().setTransaction(tx);
cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx,
true));
- SamplePojo pojo = new SamplePojo(21, "test");
- Map<Object, Object> temp = new HashMap<Object, Object>();
- temp.put("key1", pojo);
- cache.put("/one/two", temp);
+ Object pojo = new SamplePojo(21, "test");
+ cache.put("/one/two", Collections.singletonMap((Object) "key1",
pojo));
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -219,13 +193,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object>
workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace =
entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo,
workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -237,7 +206,7 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -249,14 +218,7 @@
}
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod,
gtx);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
- }
- catch (Throwable t)
- {
- fail();
- }
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
assertEquals(3, workspace.getNodes().size());
@@ -267,46 +229,28 @@
assertEquals(1, entry.getModifications().size());
- assertEquals(null, dummy.getCalled());
- NodeSPI<Object, Object> node =
workspace.getNode(Fqn.fromString("/")).getNode();
+ assertEquals(commitMethod.getMethod(), dummy.getCalled());
+ NodeSPI<Object, Object> node = workspace.getNode(Fqn.ROOT).getNode();
//assert we can navigate
assertNotNull(node);
node = (NodeSPI<Object, Object>) node.getChild("one");
assertEquals(new DefaultDataVersion(0), node.getVersion());
assertNotNull(node);
- assertTrue(cache.exists(node.getFqn()));
node = (NodeSPI<Object, Object>) node.getChild("two");
assertNotNull(node);
- assertTrue(cache.exists(node.getFqn()));
+
assertEquals(new DefaultDataVersion(1), node.getVersion());
assertEquals(pojo, node.get("key1"));
mgr.commit();
-
- destroyCache(cache);
}
- public void testTransactionValidateFailRemoteCommitMethod() throws Exception
+ public void testTransactionValidateFailRemoteCommitMethod() throws Throwable
{
-
- CacheSPI<Object, Object> cache = createCacheWithListener();
-
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -339,7 +283,7 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -352,14 +296,7 @@
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod,
gtx);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
- }
- catch (Throwable t)
- {
- fail();
- }
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
assertEquals(3, workspace.getNodes().size());
@@ -370,7 +307,7 @@
assertEquals(1, entry.getModifications().size());
- assertEquals(null, dummy.getCalled());
+ assertEquals(commitMethod.getMethod(), dummy.getCalled());
NodeSPI<Object, Object> node =
workspace.getNode(Fqn.fromString("/")).getNode();
//assert we can navigate
@@ -388,27 +325,11 @@
assertEquals(pojo, node.get("key1"));
mgr.commit();
-
- destroyCache(cache);
}
- public void testTransactionValidateRollbackMethod() throws Exception
+ public void testTransactionValidateRollbackMethod() throws Throwable
{
- CacheSPI<Object, Object> cache = createCacheWithListener();
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- validateInterceptor.setCache(cache);
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -428,13 +349,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object>
workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace =
entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo,
workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -446,7 +362,8 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod =
MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx,
entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
+
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -458,14 +375,7 @@
}
MethodCall rollbackMethod =
MethodCallFactory.create(MethodDeclarations.rollbackMethod, gtx);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
- }
- catch (Throwable t)
- {
- fail();
- }
+ TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
assertEquals(0, workspace.getNodes().size());
@@ -475,8 +385,16 @@
assertEquals(1, entry.getModifications().size());
mgr.commit();
-
- destroyCache(cache);
}
+ public static class ResetRemoteFlagInterceptor extends Interceptor
+ {
+ @Override
+ public Object invoke(InvocationContext ctx) throws Throwable
+ {
+ log.trace("Setting isRemote on gtx " + ctx.getGlobalTransaction() +
" to true");
+ ctx.getGlobalTransaction().setRemote(true);
+ return nextInterceptor(ctx);
+ }
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java 2007-12-27
20:20:04 UTC (rev 4919)
+++
core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java 2007-12-27
20:40:54 UTC (rev 4920)
@@ -6,6 +6,7 @@
import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -13,6 +14,7 @@
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
*/
+@Test(groups = "functional")
public class VersioningOnReadTest extends AbstractOptimisticTestCase
{
CacheSPI cache;