You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2015/12/03 00:10:48 UTC
incubator-geode git commit: GEODE-184: The gfsh 'locate entry'
command fails to find the entry on partitioned regions if the key is not a
string
Repository: incubator-geode
Updated Branches:
refs/heads/develop f9744623d -> 74e136401
GEODE-184: The gfsh 'locate entry' command fails to find the entry on partitioned regions if the key is not a string
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/74e13640
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/74e13640
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/74e13640
Branch: refs/heads/develop
Commit: 74e136401fa0d0a01d562c8e3f3db48b30ad56bc
Parents: f974462
Author: Jens Deppe <jd...@pivotal.io>
Authored: Wed Dec 2 08:10:13 2015 -0800
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Wed Dec 2 15:10:06 2015 -0800
----------------------------------------------------------------------
.../cli/functions/DataCommandFunction.java | 6 +-
.../functions/DataCommandFunctionJUnitTest.java | 132 +++++++++++++++++++
2 files changed, 135 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/74e13640/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunction.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunction.java b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunction.java
index d4dac05..af849f8 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunction.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunction.java
@@ -536,10 +536,10 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnt
//Following code is adaptation of which.java of old Gfsh
PartitionedRegion pr = (PartitionedRegion)region;
Region localRegion = PartitionRegionHelper.getLocalData((PartitionedRegion)region);
- value = localRegion.get(key);
+ value = localRegion.get(keyObject);
if(value!=null){
- DistributedMember primaryMember = PartitionRegionHelper.getPrimaryMemberForKey(region, key);
- int bucketId = pr.getKeyInfo(key).getBucketId();
+ DistributedMember primaryMember = PartitionRegionHelper.getPrimaryMemberForKey(region, keyObject);
+ int bucketId = pr.getKeyInfo(keyObject).getBucketId();
boolean isPrimary = member == primaryMember;
keyInfo.addLocation(new Object[]{region.getFullPath(),true,getJSONForNonPrimitiveObject(value)[1],isPrimary,""+bucketId});
}else{
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/74e13640/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunctionJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunctionJUnitTest.java
new file mode 100644
index 0000000..905a9cd
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/management/internal/cli/functions/DataCommandFunctionJUnitTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.management.internal.cli.functions;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionFactory;
+import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.management.internal.cli.domain.DataCommandResult;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * TODO: Add additional tests for all methods in DataCommandFunction.
+ *
+ * @author Jens Deppe
+ */
+@Category(IntegrationTest.class)
+public class DataCommandFunctionJUnitTest {
+
+ private static Cache cache;
+
+ private static Region region1;
+
+ private static final String PARTITIONED_REGION = "part_region";
+
+ public static class StringCheese {
+ private String cheese;
+
+ public StringCheese() {
+ // Empty constructor
+ }
+
+ public StringCheese(final String cheese) {
+ this.cheese = cheese;
+ }
+
+ public void setCheese(final String cheese) {
+ this.cheese = cheese;
+ }
+
+ @Override
+ public String toString() {
+ return cheese;
+ }
+
+ @Override
+ public int hashCode() {
+ int h = this.cheese.hashCode();
+ return h;
+ }
+
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof StringCheese) {
+ return this.cheese.equals(((StringCheese)other).cheese);
+ }
+ return false;
+ }
+ }
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ cache = new CacheFactory().
+ set(DistributionConfig.MCAST_PORT_NAME, "0").
+ create();
+ RegionFactory factory = cache.createRegionFactory(RegionShortcut.PARTITION);
+ region1 = factory.create(PARTITIONED_REGION);
+
+ region1.put(new StringCheese("key_1"), "value_1");
+ region1.put("key_2", "value_2");
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ cache.close();
+ cache = null;
+ }
+
+ /*
+ * This test addresses GEODE-184
+ */
+ @Test
+ public void testLocateKeyIsObject() throws Exception {
+ DataCommandFunction dataCmdFn = new DataCommandFunction();
+
+ DataCommandResult result = dataCmdFn.locateEntry("{'cheese': 'key_1'}", StringCheese.class.getName(), String.class.getName(), PARTITIONED_REGION, false);
+
+ assertNotNull(result);
+ result.aggregate(null);
+ List<DataCommandResult.KeyInfo> keyInfos = result.getLocateEntryLocations();
+ assertEquals(1, keyInfos.size());
+ }
+
+ @Test
+ public void testLocateKeyIsString() throws Exception {
+ DataCommandFunction dataCmdFn = new DataCommandFunction();
+
+ DataCommandResult result = dataCmdFn.locateEntry("key_2", String.class.getName(), String.class.getName(), PARTITIONED_REGION, false);
+
+ assertNotNull(result);
+ result.aggregate(null);
+ List<DataCommandResult.KeyInfo> keyInfos = result.getLocateEntryLocations();
+ assertEquals(1, keyInfos.size());
+ }
+}