You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by yz...@apache.org on 2015/11/26 14:14:08 UTC
[26/43] ignite git commit: Fixing getAnd* methods with binary
marshaller.
Fixing getAnd* methods with binary marshaller.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ae0ea3cf
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ae0ea3cf
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ae0ea3cf
Branch: refs/heads/ignite-1.5-cache-get-opts
Commit: ae0ea3cf9adcf73958cae9e9b8183cab907694de
Parents: afcf0ab
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Thu Nov 26 11:36:08 2015 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Thu Nov 26 11:36:08 2015 +0300
----------------------------------------------------------------------
.../dht/atomic/GridNearAtomicUpdateFuture.java | 3 +-
.../transactions/IgniteTxLocalAdapter.java | 29 ++++--
.../cache/GridCacheAbstractFullApiSelfTest.java | 97 ++++++++++++++++++++
3 files changed, 120 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ae0ea3cf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index 07111a1..513e6e8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -324,7 +324,8 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
GridCacheReturn ret = (GridCacheReturn)res;
Object retval =
- res == null ? null : rawRetval ? ret : (this.retval || op == TRANSFORM) ? ret.value() : ret.success();
+ res == null ? null : rawRetval ? ret : (this.retval || op == TRANSFORM) ?
+ cctx.unwrapPortableIfNeeded(ret.value(), keepBinary) : ret.success();
if (op == TRANSFORM && retval == null)
retval = Collections.emptyMap();
http://git-wip-us.apache.org/repos/asf/ignite/blob/ae0ea3cf/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
index 7c6a1d4..b3ff3a6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
@@ -2932,6 +2932,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
KeyCacheObject cacheKey = cacheCtx.toCacheKeyObject(key);
+ boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
+
final IgniteInternalFuture<Void> loadFut = enlistWrite(
cacheCtx,
cacheKey,
@@ -2945,7 +2947,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
ret,
opCtx != null && opCtx.skipStore(),
/*singleRmv*/false,
- opCtx != null && opCtx.isKeepBinary());
+ keepBinary);
if (pessimistic()) {
assert loadFut == null || loadFut.isDone() : loadFut;
@@ -3009,7 +3011,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
}
}
else
- return optimisticPutFuture(loadFut, ret);
+ return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
}
catch (IgniteCheckedException e) {
return new GridFinishedFuture(e);
@@ -3099,6 +3101,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
+ final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
+
final IgniteInternalFuture<Void> loadFut = enlistWrite(
cacheCtx,
keySet,
@@ -3115,7 +3119,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
null,
opCtx != null && opCtx.skipStore(),
false,
- opCtx != null && opCtx.isKeepBinary());
+ keepBinary);
if (pessimistic()) {
assert loadFut == null || loadFut.isDone() : loadFut;
@@ -3177,7 +3181,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
}
}
else
- return optimisticPutFuture(loadFut, ret);
+ return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
}
catch (RuntimeException e) {
onException();
@@ -3191,7 +3195,12 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
* @param ret Future result.
* @return Future.
*/
- private IgniteInternalFuture optimisticPutFuture(IgniteInternalFuture<Void> loadFut, final GridCacheReturn ret) {
+ private IgniteInternalFuture optimisticPutFuture(
+ final GridCacheContext cacheCtx,
+ IgniteInternalFuture<Void> loadFut,
+ final GridCacheReturn ret,
+ final boolean keepBinary
+ ) {
if (implicit()) {
// Should never load missing values for implicit transaction as values will be returned
// with prepare response, if required.
@@ -3211,7 +3220,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
try {
txFut.get();
- return implicitRes;
+ return new GridCacheReturn(cacheCtx, true, keepBinary,
+ implicitRes.value(), implicitRes.success());
}
catch (IgniteCheckedException | RuntimeException e) {
rollbackAsync();
@@ -3337,6 +3347,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
else
plc = null;
+ final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
+
final IgniteInternalFuture<Void> loadFut = enlistWrite(
cacheCtx,
keys0,
@@ -3353,7 +3365,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
drMap,
opCtx != null && opCtx.skipStore(),
singleRmv,
- opCtx != null && opCtx.isKeepBinary()
+ keepBinary
);
if (log.isDebugEnabled())
@@ -3432,7 +3444,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
try {
txFut.get();
- return implicitRes;
+ return new GridCacheReturn(cacheCtx, true, keepBinary,
+ implicitRes.value(), implicitRes.success());
}
catch (IgniteCheckedException | RuntimeException e) {
rollbackAsync();
http://git-wip-us.apache.org/repos/asf/ignite/blob/ae0ea3cf/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
index 89c4029..c10f81a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
@@ -2393,6 +2393,60 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
/**
* @throws Exception If failed.
*/
+ public void testGetAndRemoveObject() throws Exception {
+ IgniteCache<String, TestValue> cache = ignite(0).cache(null);
+
+ TestValue val1 = new TestValue(1);
+ TestValue val2 = new TestValue(2);
+
+ cache.put("key1", val1);
+ cache.put("key2", val2);
+
+ assert !cache.remove("key1", new TestValue(0));
+
+ TestValue oldVal = cache.get("key1");
+
+ assert oldVal != null && F.eq(val1, oldVal);
+
+ assert cache.remove("key1", val1);
+
+ assert cache.get("key1") == null;
+
+ TestValue oldVal2 = cache.getAndRemove("key2");
+
+ assert F.eq(val2, oldVal2);
+
+ assert cache.get("key2") == null;
+ assert cache.getAndRemove("key2") == null;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAndPutObject() throws Exception {
+ IgniteCache<String, TestValue> cache = ignite(0).cache(null);
+
+ TestValue val1 = new TestValue(1);
+ TestValue val2 = new TestValue(2);
+
+ cache.put("key1", val1);
+
+ TestValue oldVal = cache.get("key1");
+
+ assertEquals(val1, oldVal);
+
+ oldVal = cache.getAndPut("key1", val2);
+
+ assertEquals(val1, oldVal);
+
+ TestValue updVal = cache.get("key1");
+
+ assertEquals(val2, updVal);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
public void testDeletedEntriesFlag() throws Exception {
if (cacheMode() != LOCAL && cacheMode() != REPLICATED && memoryMode() != OFFHEAP_TIERED) {
final int cnt = 3;
@@ -5478,4 +5532,47 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
throw new EntryProcessorException("Test entry processor exception.");
}
}
+
+ /**
+ *
+ */
+ private static class TestValue implements Serializable {
+ /** */
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ TestValue(int val) {
+ this.val = val;
+ }
+
+ /**
+ * @return Value.
+ */
+ public int value() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (!(o instanceof TestValue))
+ return false;
+
+ TestValue value = (TestValue)o;
+
+ if (val != value.val)
+ return false;
+
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+ }
}