[infinispan-commits] Infinispan SVN: r1652 - in trunk/client/hotrod-client/src: main/java/org/infinispan/client/hotrod/impl and 1 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Apr 1 13:36:09 EDT 2010
Author: mircea.markus
Date: 2010-04-01 13:36:09 -0400 (Thu, 01 Apr 2010)
New Revision: 1652
Added:
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
Modified:
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java
Log:
ongoing work on hotrod client
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java 2010-04-01 14:46:36 UTC (rev 1651)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCache.java 2010-04-01 17:36:09 UTC (rev 1652)
@@ -353,5 +353,5 @@
public V getValue();
}
- RemoteCache withFlags(Flag... flags);
+ RemoteCache<K,V> withFlags(Flag... flags);
}
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java 2010-04-01 14:46:36 UTC (rev 1651)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/HotrodOperationsImpl.java 2010-04-01 17:36:09 UTC (rev 1652)
@@ -117,11 +117,9 @@
Transport transport = getTransport();
try {
short status = sendPutOperation(key, value, transport, PUT_IF_ABSENT_REQUEST, PUT_IF_ABSENT_RESPONSE, lifespan, maxIdle, flags);
- if (status == NO_ERROR_STATUS) {
+ if (status == NO_ERROR_STATUS || status == NOT_PUT_REMOVED_REPLACED_STATUS) {
return returnPossiblePrevValue(transport, flags);
- } else if (status == NOT_PUT_REMOVED_REPLACED_STATUS) {
- return null;
- }
+ }
} finally {
releaseTransport(transport);
}
@@ -274,8 +272,6 @@
transport.writeByte(operationCode);
transport.writeArray(cacheNameBytes);
-
-
int flagInt = 0;
if (flags != null) {
for (Flag flag : flags) {
@@ -286,7 +282,7 @@
transport.writeByte(clientIntelligence);
transport.writeVInt(0);//this will be changed once smarter clients are supported
if (log.isTraceEnabled()) {
- log.trace("wrote header for message " + messageId + ". Operation code: " + operationCode);
+ log.trace("wrote header for message " + messageId + ". Operation code: " + operationCode + ". Flags: " + Integer.toHexString(flagInt));
}
return messageId;
}
Added: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java (rev 0)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java 2010-04-01 17:36:09 UTC (rev 1652)
@@ -0,0 +1,95 @@
+package org.infinispan.client.hotrod;
+
+import org.infinispan.Cache;
+import org.infinispan.client.hotrod.impl.SerializationMarshaller;
+import org.infinispan.config.Configuration;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.server.core.CacheValue;
+import org.infinispan.server.hotrod.CacheKey;
+import org.infinispan.server.hotrod.HotRodServer;
+import org.infinispan.server.hotrod.test.HotRodTestingUtil;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+ at Test(testName = "client.hotrod.ForceReturnValueTest", groups = "functional")
+public class ForceReturnValueTest extends SingleCacheManagerTest {
+ private Cache cache;
+
+ RemoteCache remoteCache;
+
+ private RemoteCacheManager remoteCacheManager;
+
+ private HotRodServer hotrodServer;
+
+ @Override
+ protected CacheManager createCacheManager() throws Exception {
+ Configuration standaloneConfig = getDefaultStandaloneConfig(false);
+ cacheManager = TestCacheManagerFactory.createLocalCacheManager();
+ cache = cacheManager.getCache();
+ hotrodServer = HotRodTestingUtil.startHotRodServer(cacheManager);
+
+ remoteCacheManager = getRemoteCacheManager();
+ remoteCache = remoteCacheManager.getCache();
+ return cacheManager;
+ }
+
+ protected RemoteCacheManager getRemoteCacheManager() {
+ return new RemoteCacheManager();
+ }
+
+
+ @AfterClass(enabled = true)
+ public void testDestroyRemoteCacheFactory() {
+ assert remoteCache.ping();
+ hotrodServer.stop();
+ assert !remoteCache.ping();
+ }
+
+ public void testPut() {
+ assert null == remoteCache.put("aKey", "aValue");
+ assert "aValue".equals(remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).put("aKey", "otherValue"));
+ assert remoteCache.containsKey("aKey");
+ assert remoteCache.get("aKey").equals("otherValue");
+ }
+
+ public void testRemove() {
+ assert null == remoteCache.put("aKey", "aValue");
+ assert remoteCache.get("aKey").equals("aValue");
+ assert "aValue".equals(remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).remove("aKey"));
+ assert !remoteCache.containsKey("aKey");
+ }
+
+ public void testContains() {
+ assert !remoteCache.containsKey("aKey");
+ remoteCache.put("aKey", "aValue");
+ assert remoteCache.containsKey("aKey");
+ }
+
+ public void testReplace() {
+ assert null == remoteCache.replace("aKey", "anotherValue");
+ remoteCache.put("aKey", "aValue");
+ assert "aValue".equals(remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).replace("aKey", "anotherValue"));
+ assert remoteCache.get("aKey").equals("anotherValue");
+ }
+
+ public void testPutIfAbsent() {
+ remoteCache.put("aKey", "aValue");
+ assert null == remoteCache.putIfAbsent("aKey", "anotherValue");
+ Object existingValue = remoteCache.withFlags(Flag.FORCE_RETURN_VALUE).putIfAbsent("aKey", "anotherValue");
+ assert "aValue".equals(existingValue) : "Existing value was:" + existingValue;
+ }
+}
Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java 2010-04-01 14:46:36 UTC (rev 1651)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/HotRodIntegrationTest.java 2010-04-01 17:36:09 UTC (rev 1652)
@@ -131,7 +131,6 @@
private static Log log = LogFactory.getLog(HotRodIntegrationTest.class);
- @Test (invocationCount = 10)
public void testGetVersionedCacheEntry() {
assert null == remoteCache.getVersioned("aKey");
remoteCache.put("aKey", "aValue");
More information about the infinispan-commits
mailing list