Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9EA5B19C0A for ; Tue, 15 Mar 2016 00:23:49 +0000 (UTC) Received: (qmail 13048 invoked by uid 500); 15 Mar 2016 00:23:49 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 13008 invoked by uid 500); 15 Mar 2016 00:23:49 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 12999 invoked by uid 99); 15 Mar 2016 00:23:49 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Mar 2016 00:23:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 154DAC0D23 for ; Tue, 15 Mar 2016 00:23:49 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.549 X-Spam-Level: X-Spam-Status: No, score=-3.549 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.329] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id nvvcudpe02ln for ; Tue, 15 Mar 2016 00:23:46 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id C3DD75FBCB for ; Tue, 15 Mar 2016 00:23:45 +0000 (UTC) Received: (qmail 12525 invoked by uid 99); 15 Mar 2016 00:23:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Mar 2016 00:23:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 633BEE08BF; Tue, 15 Mar 2016 00:23:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.incubator.apache.org Date: Tue, 15 Mar 2016 00:23:58 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [15/44] incubator-geode git commit: GEODE-1042: add junit test for the fix in processChunk() 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-949-2 Commit: 70ca9214ffede4ec56a0e80e192a52895faf7735 Parents: 6c74e5a Author: zhouxh Authored: Tue Mar 8 15:31:26 2016 -0800 Committer: zhouxh 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 * CompactCompositeRegionKey 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 returnValue; - private final HashMap returnVersions = new HashMap(); + protected volatile RegionVersionVector returnRVV; + protected final HashMap returnValue; + protected final HashMap returnVersions = new HashMap(); private final Map canonicalMembers = new ConcurrentHashMap(); /** 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")); + } +}