Author: manik.surtani(a)jboss.com
Date: 2008-01-08 06:51:00 -0500 (Tue, 08 Jan 2008)
New Revision: 5043
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java
Log:
Implemented missing tests
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java 2008-01-08
01:12:23 UTC (rev 5042)
+++
core/trunk/src/test/java/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java 2008-01-08
11:51:00 UTC (rev 5043)
@@ -3,13 +3,16 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
+import org.jboss.cache.misc.TestingUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
+import java.util.List;
/**
* Tests whether remote calls to RPC methods suppress return values (as sometimes
expected)
@@ -24,12 +27,16 @@
private Fqn fqn = Fqn.fromString("/a");
private Object key = "key";
private Object value = "value";
+ private RemoteCacheInvocationDelegate rcid;
+ private Method invokeMethod;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache();
cache.put(fqn, key, value);
+ rcid = TestingUtil.getRemoteDelegate(cache);
+ invokeMethod =
cache.getClass().getSuperclass().getDeclaredMethod("invoke", MethodCall.class);
}
@AfterMethod(alwaysRun = true)
@@ -40,47 +47,48 @@
public void testMethodsThatShouldReturnValues() throws Throwable
{
- assert false : "Implement me";
- /*
- Object retval =
cache._replicate(MethodCallFactory.create(MethodDeclarations.clusteredGetMethod,
MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn), false));
- assertNotNull(retval);
+ MethodCall mc = MethodCallFactory.create(MethodDeclarations.getKeysMethodLocal_id,
fqn);
+ assert rcid._replicate(mc) == null;
+ List l = rcid.clusteredGet(mc, false);
-
assertNotNull(cache._replicate(MethodCallFactory.create(MethodDeclarations.dataGravitationMethod,
fqn, false)));
- */
+ assert l != null;
+ assert (Boolean) l.get(0);
+ assert l.get(1).equals(Collections.singleton(key));
}
+ /**
+ * The purpose of this test is to ensure that these remote method calls - when called
using _replicate - will always return null
+ * since a return value is not neeeded.
+ *
+ * @throws Throwable
+ */
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);
+ doNullReturnTest(MethodDeclarations.getDataMapMethodLocal_id,
Collections.singletonMap(key, value), fqn);
+ doNullReturnTest(MethodDeclarations.getNodeMethodLocal_id, cache.getNode(fqn),
fqn);
+ doNullReturnTest(MethodDeclarations.getKeysMethodLocal_id,
Collections.singleton(key), fqn);
+ doNullReturnTest(MethodDeclarations.getChildrenNamesMethodLocal_id,
Collections.emptySet(), fqn);
+ doNullReturnTest(MethodDeclarations.putKeyValMethodLocal_id, value, null, fqn, key,
value, true);
+ doNullReturnTest(MethodDeclarations.removeKeyMethodLocal_id, value, null, fqn, key,
true);
+ }
- // ------------ buddy replication
- doNullReturnTest(MethodDeclarations.remoteAnnounceBuddyPoolNameMethod,
cache.getLocalAddress(), null);
- doNullReturnTest(MethodDeclarations.remoteRemoveFromBuddyGroupMethod,
"arse");
- doNullReturnTest(MethodDeclarations.remoteAssignToBuddyGroupMethod, new
BuddyGroup(), Collections.emptyMap());
+ private void doNullReturnTest(int methodId, Object expectedretValForLocalTest,
Object... args) throws Throwable
+ {
+ MethodCall mc = MethodCallFactory.create(methodId, args);
+ // "local" version of the call:
+ Object retVal = invokeCallDirectly(mc);
+ assert retVal != null && retVal.equals(expectedretValForLocalTest);
- // ------------ move() api
- doNullReturnTest(MethodDeclarations.moveMethodLocal, fqn, Fqn.ROOT);
-
- // ------------ Channel BLOCK event
- doNullReturnTest(MethodDeclarations.blockChannelMethodLocal);
- doNullReturnTest(MethodDeclarations.unblockChannelMethodLocal);
+ // now try this using the replicate method.
+ Object retVal2 = rcid._replicate(mc);
+ assert retVal2 == null;
}
-
- private void doNullReturnTest(Method m, Object... args)
+ private Object invokeCallDirectly(MethodCall mc) throws NoSuchMethodException,
IllegalAccessException, InvocationTargetException
{
- assert false : "Implement me";
- /*
- MethodCall c = MethodCallFactory.create(m, args);
- assertNull(m + " should return a null when called remotely",
cache._replicate(c));
- */
+ invokeMethod.setAccessible(true);
+ return invokeMethod.invoke(cache, mc);
}
}