geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [05/13] geode git commit: GEODE-2799: Handle different types of KeyInfo set when creating the KeySet Iterator.
Date Mon, 24 Apr 2017 20:19:42 GMT
GEODE-2799: Handle different types of KeyInfo set when creating the KeySet Iterator.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/60ec931f
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/60ec931f
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/60ec931f

Branch: refs/heads/feature/GEODE-2632-6-1
Commit: 60ec931f53ead9a18950fb4b8e441ff3e9993820
Parents: 363e50d
Author: eshu <eshu@pivotal.io>
Authored: Fri Apr 21 13:55:49 2017 -0700
Committer: eshu <eshu@pivotal.io>
Committed: Fri Apr 21 13:55:49 2017 -0700

----------------------------------------------------------------------
 .../geode/internal/cache/LocalRegion.java       |  2 +-
 .../internal/cache/LocalRegionDataView.java     | 14 ++++-
 .../apache/geode/internal/cache/TXState.java    |  1 +
 .../cache/TXStateProxyImplJUnitTest.java        | 60 ++++++++++++++++++++
 4 files changed, 73 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/60ec931f/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index 5d5044b..45035d7 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -11177,7 +11177,7 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
     return getRegionMap().keySet();
   }
 
-  public final InternalDataView getSharedDataView() {
+  public InternalDataView getSharedDataView() {
     return this.sharedDataView;
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/60ec931f/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegionDataView.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegionDataView.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegionDataView.java
index b4aa20b..8db979b 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegionDataView.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegionDataView.java
@@ -200,11 +200,19 @@ public class LocalRegionDataView implements InternalDataView {
    */
   public Object getKeyForIterator(final KeyInfo keyInfo, final LocalRegion currRgn,
       boolean rememberReads, boolean allowTombstones) {
-    final AbstractRegionEntry re = (AbstractRegionEntry) keyInfo.getKey();
+    final Object key = keyInfo.getKey();
+    if (key == null) {
+      return null;
+    }
     // fix for 42182, before returning a key verify that its value
     // is not a removed token
-    if (re != null && (!re.isDestroyedOrRemoved() || (allowTombstones &&
re.isTombstone()))) {
-      return re.getKey();
+    if (key instanceof RegionEntry) {
+      RegionEntry re = (RegionEntry) key;
+      if (!re.isDestroyedOrRemoved() || (allowTombstones && re.isTombstone())) {
+        return re.getKey();
+      }
+    } else if (getEntry(keyInfo, currRgn, allowTombstones) != null) {
+      return key;
     }
     return null;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/60ec931f/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
index 234baee..0a9d80e 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
@@ -1705,6 +1705,7 @@ public class TXState implements TXStateInterface {
    */
   public Object getKeyForIterator(KeyInfo curr, LocalRegion currRgn, boolean rememberReads,
       boolean allowTombstones) {
+    assert !(curr.getKey() instanceof RegionEntry);
     if (!readEntryAndCheckIfDestroyed(curr, currRgn, rememberReads)) {
       return curr.getKey();
     } else {

http://git-wip-us.apache.org/repos/asf/geode/blob/60ec931f/geode-core/src/test/java/org/apache/geode/internal/cache/TXStateProxyImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/TXStateProxyImplJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/TXStateProxyImplJUnitTest.java
new file mode 100644
index 0000000..9ce76c5
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/TXStateProxyImplJUnitTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information
regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain
a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under
the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
+ * or implied. See the License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+
+package org.apache.geode.internal.cache;
+
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.LocalRegion.NonTXEntry;
+import org.apache.geode.internal.cache.region.entry.RegionEntryFactoryBuilder;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class TXStateProxyImplJUnitTest {
+  @Test
+  public void testGetKeyForIterator() {
+    RegionEntryFactory factory = new RegionEntryFactoryBuilder().getRegionEntryFactoryOrNull(false,
+        false, false, false, false);
+    LocalRegion region = mock(LocalRegion.class);
+    String key = "testkey";
+    RegionEntry re = factory.createEntry(region, key, null);
+    TXId txId = new TXId(mock(InternalDistributedMember.class), 1);
+    TXStateProxyImpl tx = new TXStateProxyImpl(mock(TXManagerImpl.class), txId, false);
+    LocalRegionDataView view = mock(LocalRegionDataView.class);
+    boolean allowTombstones = false;
+    boolean rememberReads = true;
+
+    KeyInfo stringKeyInfo = new KeyInfo(key, null, null);
+    KeyInfo regionEntryKeyInfo = new KeyInfo(re, null, null);
+
+    when(region.getSharedDataView()).thenReturn(view);
+    when(view.getEntry(stringKeyInfo, region, allowTombstones)).thenReturn(mock(NonTXEntry.class));
+    when(view.getKeyForIterator(stringKeyInfo, region, rememberReads, allowTombstones))
+        .thenCallRealMethod();
+    when(view.getKeyForIterator(regionEntryKeyInfo, region, rememberReads, allowTombstones))
+        .thenCallRealMethod();
+
+    Object key1 = tx.getKeyForIterator(regionEntryKeyInfo, region, rememberReads, allowTombstones);
+    assertTrue(key1.equals(key));
+    Object key2 = tx.getKeyForIterator(stringKeyInfo, region, rememberReads, allowTombstones);
+    assertTrue(key2.equals(key));
+  }
+
+}


Mime
View raw message