[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/marshall ...
Manik Surtani
msurtani at jboss.com
Mon Jan 15 06:22:39 EST 2007
User: msurtani
Date: 07/01/15 06:22:39
Added: tests/functional/org/jboss/cache/marshall
RemoteCallerReturnValuesTest.java
ReturnValueMarshallingTest.java
Log:
Tests marshalling of return values
Revision Changes Path
1.1 date: 2007/01/15 11:22:39; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java
Index: RemoteCallerReturnValuesTest.java
===================================================================
package org.jboss.cache.marshall;
import junit.framework.TestCase;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.buddyreplication.BuddyGroup;
import java.lang.reflect.Method;
import java.util.Collections;
/**
* Tests whether remote calls to RPC methods suppress return values (as sometimes expected)
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class RemoteCallerReturnValuesTest extends TestCase
{
private CacheImpl cache;
private Fqn fqn = Fqn.fromString("/a");
private Object key = "key";
private Object value = "value";
protected void setUp() throws Exception
{
cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache();
cache.put(fqn, key, value);
}
protected void tearDown()
{
cache.stop();
}
public void testMethodsThatShouldReturnValues() throws Throwable
{
Object retval = cache._replicate(MethodCallFactory.create(MethodDeclarations.clusteredGetMethod, MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn), false));
assertNotNull(retval);
assertNotNull(cache._replicate(MethodCallFactory.create(MethodDeclarations.dataGravitationMethod, fqn, false, false)));
}
public void testMethodsThatShouldReturnNull() throws Throwable
{
doNullReturnTest(MethodDeclarations.getDataMapMethodLocal, fqn);
doNullReturnTest(MethodDeclarations.existsMethod, fqn);
doNullReturnTest(MethodDeclarations.getNodeMethodLocal, fqn);
doNullReturnTest(MethodDeclarations.getKeysMethodLocal, fqn);
doNullReturnTest(MethodDeclarations.getChildrenNamesMethodLocal, fqn);
doNullReturnTest(MethodDeclarations.releaseAllLocksMethodLocal, fqn);
doNullReturnTest(MethodDeclarations.printMethodLocal, fqn);
// ------------ buddy replication
doNullReturnTest(MethodDeclarations.remoteAnnounceBuddyPoolNameMethod, cache.getLocalAddress(), null);
doNullReturnTest(MethodDeclarations.remoteRemoveFromBuddyGroupMethod, "arse");
doNullReturnTest(MethodDeclarations.remoteAssignToBuddyGroupMethod, new BuddyGroup(), Collections.emptyMap());
// ------------ move() api
doNullReturnTest(MethodDeclarations.moveMethodLocal, fqn, Fqn.ROOT);
// ------------ Channel BLOCK event
doNullReturnTest(MethodDeclarations.blockChannelLocal);
doNullReturnTest(MethodDeclarations.unblockChannelLocal);
}
private void doNullReturnTest(Method m, Object... args) throws Throwable
{
MethodCall c = MethodCallFactory.create(m, args);
assertNull(m + " should return a null when called remotely", cache._replicate(c));
}
}
1.1 date: 2007/01/15 11:22:39; author: msurtani; state: Exp;JBossCache/tests/functional/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
Index: ReturnValueMarshallingTest.java
===================================================================
package org.jboss.cache.marshall;
import junit.framework.TestCase;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.config.Configuration;
import java.util.List;
/**
* Tests the marshalling of retvals
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
public class ReturnValueMarshallingTest extends TestCase
{
private CacheImpl cache1, cache2;
private Fqn fqn = Fqn.fromString("/a");
private ClassLoader classLoader;
private Object key = "key", value;
private String className = "org.jboss.cache.marshall.MyList";
private Class listClass;
protected void setUp() throws Exception
{
cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setUseRegionBasedMarshalling(true);
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache1.start();
cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache2.getConfiguration().setUseRegionBasedMarshalling(true);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache2.start();
classLoader = getClassLoader();
Region r1 = cache1.getRegion(fqn, true);
r1.setActive(true);
r1.registerContextClassLoader(classLoader);
Region r2 = cache2.getRegion(fqn, true);
r2.setActive(true);
r2.registerContextClassLoader(classLoader);
listClass = classLoader.loadClass(className);
value = listClass.newInstance();
cache1.put(fqn, key, value);
}
protected void tearDown()
{
cache1.stop();
cache2.stop();
}
private ClassLoader getClassLoader() throws Exception
{
String[] includesClasses = {className};
String[] excludesClasses = {};
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
}
public void testClusteredGet() throws Exception
{
assertNotNull(cache1.get(fqn, key));
assertNotSame(MyList.class, cache1.get(fqn, key).getClass());
assertSame(listClass, cache1.get(fqn, key).getClass());
assertNotNull(cache2.get(fqn, key));
assertNotSame(MyList.class, cache2.get(fqn, key).getClass());
assertSame(listClass, cache2.get(fqn, key).getClass());
// now test if this is the same when obtained using a clustered get mcall
MethodCall call = MethodCallFactory.create(MethodDeclarations.replicateMethod,
MethodCallFactory.create(MethodDeclarations.clusteredGetMethod,
MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false),
false
)
);
List responses = cache1.getRPCManager().callRemoteMethods(null, call, true, true, 15000);
List response1 = (List) responses.get(0);// response from the first (and only) node
Boolean found = (Boolean) response1.get(0);
assertTrue("Should have found remote data", found);
Object data = response1.get(1);
// now test that the data returned has been marshalled using the appropriate class loader.
assertNotNull(data);
assertNotSame(MyList.class, data.getClass());
assertSame(listClass, data.getClass());
}
public void testDataGravitation() throws Exception
{
assertNotNull(cache1.get(fqn, key));
assertNotSame(MyList.class, cache1.get(fqn, key).getClass());
assertSame(listClass, cache1.get(fqn, key).getClass());
assertNotNull(cache2.get(fqn, key));
assertNotSame(MyList.class, cache2.get(fqn, key).getClass());
assertSame(listClass, cache2.get(fqn, key).getClass());
// now test if this is the same when obtained using a data gravitate call
MethodCall call = MethodCallFactory.create(MethodDeclarations.replicateMethod,
MethodCallFactory.create(MethodDeclarations.dataGravitationMethod,
fqn, false, false
)
);
List responses = cache1.getRPCManager().callRemoteMethods(null, call, true, true, 15000);
List response1 = (List) responses.get(0);// response from the first (and only) node
Boolean found = (Boolean) response1.get(0);
assertTrue("Should have found remote data", found);
Object data = response1.get(1);
// now test that the data returned has been marshalled using the appropriate class loader.
// what is this data object returned? :S
System.out.println(data);
assertNotNull(data);
assertNotSame(MyList.class, data.getClass());
assertSame(listClass, data.getClass());
}
}
More information about the jboss-cvs-commits
mailing list