geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject [29/38] incubator-geode git commit: GEODE-1921: Redis adaptor Strings region has incorrect attributes
Date Tue, 04 Oct 2016 17:03:35 GMT
GEODE-1921: Redis adaptor Strings region has incorrect attributes

- renamed them to redis_strings and redis_hll
- made the strings regions and the hll region PARTITION by default
- these regions are no longer internal regions


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

Branch: refs/heads/feature/e2e-testing
Commit: c9790a4343718df40e9374bbc49d99782067913e
Parents: 6555c86
Author: Swapnil Bawaskar <sbawaskar@pivotal.io>
Authored: Wed Sep 21 23:47:20 2016 -0700
Committer: Swapnil Bawaskar <sbawaskar@pivotal.io>
Committed: Wed Sep 28 16:17:50 2016 -0700

----------------------------------------------------------------------
 .../apache/geode/redis/GeodeRedisServer.java    | 28 +++----
 .../org/apache/geode/redis/RedisServerTest.java | 84 ++++++++++++++++++++
 2 files changed, 94 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c9790a43/geode-core/src/main/java/org/apache/geode/redis/GeodeRedisServer.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/redis/GeodeRedisServer.java b/geode-core/src/main/java/org/apache/geode/redis/GeodeRedisServer.java
index 45d1886..d86d7fe 100644
--- a/geode-core/src/main/java/org/apache/geode/redis/GeodeRedisServer.java
+++ b/geode-core/src/main/java/org/apache/geode/redis/GeodeRedisServer.java
@@ -47,6 +47,7 @@ import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.channel.socket.oio.OioServerSocketChannel;
 import io.netty.util.concurrent.Future;
+import org.apache.geode.cache.*;
 import org.apache.geode.redis.internal.ByteArrayWrapper;
 import org.apache.geode.redis.internal.ByteToCommandDecoder;
 import org.apache.geode.redis.internal.Coder;
@@ -56,16 +57,6 @@ import org.apache.geode.redis.internal.RegionProvider;
 
 import org.apache.geode.InternalGemFireError;
 import org.apache.geode.LogWriter;
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.EntryEvent;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.RegionDestroyedException;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.Scope;
 import org.apache.geode.cache.util.CacheListenerAdapter;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.internal.cache.GemFireCacheImpl;
@@ -231,13 +222,13 @@ public class GeodeRedisServer {
    * The field that defines the name of the {@link Region} which holds all of
    * the strings. The current value of this field is {@value #STRING_REGION}.
    */
-  public static final String STRING_REGION = "__StRiNgS";
+  public static final String STRING_REGION = "ReDiS_StRiNgS";
 
   /**
    * The field that defines the name of the {@link Region} which holds all of
    * the HyperLogLogs. The current value of this field is {@value #HLL_REGION}.
    */
-  public static final String HLL_REGION = "__HlL";
+  public static final String HLL_REGION = "ReDiS_HlL";
 
   /**
    * The field that defines the name of the {@link Region} which holds all of
@@ -425,23 +416,24 @@ public class GeodeRedisServer {
   private void initializeRedis() {
     synchronized (this.cache) {
       Region<ByteArrayWrapper, ByteArrayWrapper> stringsRegion;
-      InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true);
-      AttributesFactory af = new AttributesFactory();
-      af.setScope(Scope.LOCAL);
-      RegionAttributes ra = af.create();
+
       Region<ByteArrayWrapper, HyperLogLogPlus> hLLRegion;
       Region<String, RedisDataType> redisMetaData;
       GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache;
       try {
         if ((stringsRegion = cache.getRegion(STRING_REGION)) == null) {
-          stringsRegion = gemFireCache.createVMRegion(GeodeRedisServer.STRING_REGION, ra,
ira);
+          RegionFactory<ByteArrayWrapper, ByteArrayWrapper> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
+          stringsRegion = regionFactory.create(STRING_REGION);
         }
         if ((hLLRegion = cache.getRegion(HLL_REGION)) == null) {
-          hLLRegion = gemFireCache.createVMRegion(HLL_REGION, ra, ira);
+          RegionFactory<ByteArrayWrapper, HyperLogLogPlus> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
+          hLLRegion = regionFactory.create(HLL_REGION);
         }
         if ((redisMetaData = cache.getRegion(REDIS_META_DATA_REGION)) == null) {
+          AttributesFactory af = new AttributesFactory();
           af.addCacheListener(metaListener);
           af.setDataPolicy(DataPolicy.REPLICATE);
+          InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true).setIsUsedForMetaRegion(true);
           redisMetaData = gemFireCache.createVMRegion(REDIS_META_DATA_REGION, af.create(),
ira);
         }
       } catch (IOException | ClassNotFoundException e) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c9790a43/geode-core/src/test/java/org/apache/geode/redis/RedisServerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/redis/RedisServerTest.java b/geode-core/src/test/java/org/apache/geode/redis/RedisServerTest.java
new file mode 100644
index 0000000..a92cc84
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/redis/RedisServerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.redis;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.Region;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Properties;
+
+@Category(IntegrationTest.class)
+public class RedisServerTest {
+
+  Cache cache;
+  GeodeRedisServer redisServer;
+
+  @Before
+  public void createCache() {
+    Properties props = new Properties();
+    props.setProperty("mcast-port", "0");
+    CacheFactory cacheFactory = new CacheFactory(props);
+    cache = cacheFactory.create();
+  }
+
+  @After
+  public void teardown() {
+    if (redisServer != null) {
+      redisServer.shutdown();
+      cache.close();
+    }
+  }
+
+  @Test
+  public void initializeRedisCreatesThreeRegions() {
+    createCache();
+    assert(cache.rootRegions().size() == 0);
+    redisServer = new GeodeRedisServer(0);
+    redisServer.start();
+    assert cache.rootRegions().size() == 2 : cache.rootRegions().size();
+    assert cache.getRegion(GeodeRedisServer.REDIS_META_DATA_REGION) != null;
+  }
+
+  @Test
+  public void initializeRedisCreatesPartitionedRegionByDefault() {
+    createCache();
+    assert(cache.rootRegions().size() == 0);
+    redisServer = new GeodeRedisServer(0);
+    redisServer.start();
+    Region r = cache.getRegion(GeodeRedisServer.STRING_REGION);
+    assert r.getAttributes().getDataPolicy() == DataPolicy.PARTITION : r.getAttributes().getDataPolicy();
+  }
+
+  @Test
+  public void initializeRedisCreatesRegionsUsingSystemProperty() {
+    createCache();
+    assert(cache.rootRegions().size() == 0);
+    System.setProperty("gemfireredis.regiontype", "REPLICATE");
+    redisServer = new GeodeRedisServer(0);
+    redisServer.start();
+    Region r = cache.getRegion(GeodeRedisServer.STRING_REGION);
+    assert r.getAttributes().getDataPolicy() == DataPolicy.REPLICATE : r.getAttributes().getDataPolicy();
+    System.setProperty("gemfireredis.regiontype", "");
+  }
+}


Mime
View raw message