geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [13/45] incubator-geode git commit: GEODE-1042: add junit test for the fix in processChunk()
Date Tue, 15 Mar 2016 18:38:51 GMT
GEODE-1042: add junit test for the fix in processChunk()


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

Branch: refs/heads/feature/GEODE-1050
Commit: 70ca9214ffede4ec56a0e80e192a52895faf7735
Parents: 6c74e5a
Author: zhouxh <gzhou@pivotal.io>
Authored: Tue Mar 8 15:31:26 2016 -0800
Committer: zhouxh <gzhou@pivotal.io>
Committed: Wed Mar 9 10:42:53 2016 -0800

----------------------------------------------------------------------
 .../gemfire/internal/cache/LocalRegion.java     |  2 +-
 .../cache/partitioned/FetchEntriesMessage.java  |  8 +-
 .../FetchEntriesMessageJUnitTest.java           | 93 ++++++++++++++++++++
 3 files changed, 98 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/70ca9214/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
index 966130a..830d47d 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
@@ -556,7 +556,7 @@ public class LocalRegion extends AbstractRegion
    * <code>CompactCompositeRegionKey</code> that points to the raw row bytes
and
    * so requires a handle to table schema for interpretation of those bytes.
    */
-  public final boolean keyRequiresRegionContext() {
+  public boolean keyRequiresRegionContext() {
     return this.keyRequiresRegionContext;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/70ca9214/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessage.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessage.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessage.java
index fda15c4..8360a1e 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessage.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessage.java
@@ -195,7 +195,7 @@ public final class FetchEntriesMessage extends PartitionMessage
     public FetchEntriesReplyMessage() {
     }
   
-    private FetchEntriesReplyMessage(InternalDistributedMember dest,
+    protected FetchEntriesReplyMessage(InternalDistributedMember dest,
         int processorId, int buckId, HeapDataOutputStream chunk,
         int seriesNum, int msgNum, int numSeries, boolean lastInSeries, boolean hasRVV) {
       setRecipient(dest);
@@ -455,9 +455,9 @@ public final class FetchEntriesMessage extends PartitionMessage
 
     private final PartitionedRegion pr;
 
-    private volatile RegionVersionVector returnRVV; 
-    private final HashMap<Object, Object> returnValue;
-    private final HashMap<Object, VersionTag> returnVersions = new HashMap();
+    protected volatile RegionVersionVector returnRVV; 
+    protected final HashMap<Object, Object> returnValue;
+    protected final HashMap<Object, VersionTag> returnVersions = new HashMap();
     private final Map<VersionSource,VersionSource> canonicalMembers = new ConcurrentHashMap<VersionSource,VersionSource>();
     
     /** lock used to synchronize chunk processing */

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/70ca9214/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessageJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessageJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessageJUnitTest.java
new file mode 100755
index 0000000..39bb5ea
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/FetchEntriesMessageJUnitTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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 com.gemstone.gemfire.internal.cache.partitioned;
+
+import static org.mockito.Mockito.*;
+
+import java.io.IOException;
+
+import org.apache.logging.log4j.Logger;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.internal.HeapDataOutputStream;
+import com.gemstone.gemfire.internal.Version;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.cache.InitialImageOperation;
+import com.gemstone.gemfire.internal.cache.PartitionedRegion;
+import com.gemstone.gemfire.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesReplyMessage;
+import com.gemstone.gemfire.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse;
+import com.gemstone.gemfire.internal.cache.versions.VersionTag;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.test.fake.Fakes;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import junit.framework.TestCase;
+
+@Category(UnitTest.class)
+public class FetchEntriesMessageJUnitTest extends TestCase {
+  protected static final Logger logger = LogService.getLogger();
+  GemFireCacheImpl cache;
+  
+  private VersionTag createVersionTag(boolean validVersionTag) throws ClassNotFoundException,
IOException {
+    VersionTag tag = VersionTag.create(cache.getMyId());
+    if (validVersionTag) {
+      tag.setRegionVersion(1);
+      tag.setEntryVersion(1);
+    }
+    return tag;
+  }
+
+  private HeapDataOutputStream createDummyChunk() throws IOException, ClassNotFoundException
{
+    HeapDataOutputStream mos = new HeapDataOutputStream(InitialImageOperation.CHUNK_SIZE_IN_BYTES+2048,
Version.CURRENT);
+    mos.reset();
+    DataSerializer.writeObject("keyWithOutVersionTag", mos);
+    DataSerializer.writeObject("valueWithOutVersionTag", mos);
+    DataSerializer.writeObject(null /* versionTag */, mos);
+
+    DataSerializer.writeObject("keyWithVersionTag", mos);
+    DataSerializer.writeObject("valueWithVersionTag", mos);
+    
+    VersionTag tag = createVersionTag(true);
+    DataSerializer.writeObject(tag, mos);
+
+    DataSerializer.writeObject((Object)null, mos);
+    return mos;
+  }
+  
+  @Test
+  public void testProcessChunk() throws IOException, ClassNotFoundException {
+    cache = Fakes.cache();
+    PartitionedRegion pr = mock(PartitionedRegion.class);
+    InternalDistributedSystem system = cache.getDistributedSystem();
+    when(pr.keyRequiresRegionContext()).thenReturn(false);
+
+    FetchEntriesResponse response = new FetchEntriesResponse(system, pr, null, 0);
+    HeapDataOutputStream chunkStream = createDummyChunk();
+    FetchEntriesReplyMessage reply = new FetchEntriesReplyMessage(null, 0, 0, chunkStream,
0, 0, 0, false, false);
+    reply.chunk = chunkStream.toByteArray();
+    response.processChunk(reply);
+    assertNull(response.returnRVV);
+    assertEquals(2, response.returnValue.size());
+    assertTrue(response.returnValue.get("keyWithOutVersionTag").equals("valueWithOutVersionTag"));
+    assertTrue(response.returnValue.get("keyWithVersionTag").equals("valueWithVersionTag"));
+    assertNull(response.returnVersions.get("keyWithOutVersionTag"));
+    assertNotNull(response.returnVersions.get("keyWithVersionTag"));
+  }
+}


Mime
View raw message