This is an automated email from the ASF dual-hosted git repository.

heybales pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new d3104cc  GEODE-9654: add system properties for timeouts (#6961)
d3104cc is described below

commit d3104cceb4714d49d5540691a3c628cda8b5efb5
Author: Hale Bales <[email protected]>
AuthorDate: Wed Oct 20 09:24:51 2021 -0700

    GEODE-9654: add system properties for timeouts (#6961)
    
    Adds system properties for geode-for-redis-write-timeout-seconds and 
geode-for-redis-interval-seconds
    
    - If they are set to non-integer, negative, or zero, the default values 
will quietly be used.
    - add tests for helper for setting timeouts
    - renames
    - add support for both geode. and gemfire. prefixes for timeout properties
---
 .../redis/GeodeRedisServerStartupDUnitTest.java    | 19 +++++
 .../redis/internal/PassiveExpirationManager.java   | 17 +++--
 .../geode/redis/internal/RedisProperties.java      | 39 ++++++++++
 .../redis/internal/netty/NettyRedisServer.java     | 19 +++--
 .../redis/internal/data/RedisPropertiesTest.java   | 86 ++++++++++++++++++++++
 5 files changed, 163 insertions(+), 17 deletions(-)

diff --git 
a/geode-for-redis/src/acceptanceTest/java/org/apache/geode/redis/GeodeRedisServerStartupDUnitTest.java
 
b/geode-for-redis/src/acceptanceTest/java/org/apache/geode/redis/GeodeRedisServerStartupDUnitTest.java
index 2f7ecfe..b155e66 100644
--- 
a/geode-for-redis/src/acceptanceTest/java/org/apache/geode/redis/GeodeRedisServerStartupDUnitTest.java
+++ 
b/geode-for-redis/src/acceptanceTest/java/org/apache/geode/redis/GeodeRedisServerStartupDUnitTest.java
@@ -62,6 +62,15 @@ public class GeodeRedisServerStartupDUnitTest {
   }
 
   @Test
+  public void startupOnDefaultPort_whenPortIsNotSpecified() {
+    MemberVM server = cluster.startServerVM(0, s -> s
+        .withProperty(REDIS_BIND_ADDRESS, "localhost")
+        .withProperty(REDIS_ENABLED, "true"));
+
+    
assertThat(cluster.getRedisPort(server)).isEqualTo(GeodeRedisServer.DEFAULT_REDIS_SERVER_PORT);
+  }
+
+  @Test
   public void startupOnRandomPort_whenPortIsZero() {
     MemberVM server = cluster.startServerVM(0, s -> s
         .withProperty(REDIS_PORT, "0")
@@ -123,6 +132,16 @@ public class GeodeRedisServerStartupDUnitTest {
   }
 
   @Test
+  public void startupOnSpecifiedPort() {
+    MemberVM server = cluster.startServerVM(0, s -> s
+        .withProperty(REDIS_PORT, "4242")
+        .withProperty(REDIS_BIND_ADDRESS, "localhost")
+        .withProperty(REDIS_ENABLED, "true"));
+
+    assertThat(cluster.getRedisPort(server)).isEqualTo(4242);
+  }
+
+  @Test
   public void startupWorksGivenAnyLocalAddress() {
     String anyLocal = LocalHostUtil.getAnyLocalAddress().getHostAddress();
     MemberVM server = cluster.startServerVM(0, s -> s
diff --git 
a/geode-for-redis/src/main/java/org/apache/geode/redis/internal/PassiveExpirationManager.java
 
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/PassiveExpirationManager.java
index e29682c..4e5bdf6 100644
--- 
a/geode-for-redis/src/main/java/org/apache/geode/redis/internal/PassiveExpirationManager.java
+++ 
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/PassiveExpirationManager.java
@@ -16,15 +16,16 @@
 
 package org.apache.geode.redis.internal;
 
-import static java.util.concurrent.TimeUnit.MINUTES;
+import static java.util.concurrent.TimeUnit.SECONDS;
 import static 
org.apache.geode.logging.internal.executors.LoggingExecutors.newSingleThreadScheduledExecutor;
+import static 
org.apache.geode.redis.internal.RedisProperties.EXPIRATION_INTERVAL_SECONDS;
+import static 
org.apache.geode.redis.internal.RedisProperties.getIntegerSystemProperty;
 
 import java.util.Map;
 import java.util.concurrent.ScheduledExecutorService;
 
 import org.apache.logging.log4j.Logger;
 
-import org.apache.geode.annotations.VisibleForTesting;
 import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.EntryDestroyedException;
 import org.apache.geode.cache.Region;
@@ -36,15 +37,17 @@ import org.apache.geode.redis.internal.data.RedisKey;
 public class PassiveExpirationManager {
   private static final Logger logger = LogService.getLogger();
 
-  private final ScheduledExecutorService expirationExecutor;
+  public static final int DEFAULT_REDIS_EXPIRATION_INTERVAL_SECONDS = 180;
 
-  @VisibleForTesting
-  public static final int INTERVAL = 3;
+  private final ScheduledExecutorService expirationExecutor;
 
   public PassiveExpirationManager(RegionProvider regionProvider) {
+    int interval = getIntegerSystemProperty(EXPIRATION_INTERVAL_SECONDS,
+        DEFAULT_REDIS_EXPIRATION_INTERVAL_SECONDS, 1);
+
     expirationExecutor = 
newSingleThreadScheduledExecutor("GemFireRedis-PassiveExpiration-");
-    expirationExecutor.scheduleWithFixedDelay(() -> 
doDataExpiration(regionProvider), INTERVAL,
-        INTERVAL, MINUTES);
+    expirationExecutor.scheduleWithFixedDelay(() -> 
doDataExpiration(regionProvider), interval,
+        interval, SECONDS);
   }
 
   public void stop() {
diff --git 
a/geode-for-redis/src/main/java/org/apache/geode/redis/internal/RedisProperties.java
 
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/RedisProperties.java
new file mode 100644
index 0000000..5ad8a4d
--- /dev/null
+++ 
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/RedisProperties.java
@@ -0,0 +1,39 @@
+/*
+ * 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.internal;
+
+
+public class RedisProperties {
+  /** System Property Names **/
+  public static final String WRITE_TIMEOUT_SECONDS = 
"geode-for-redis-write-timeout-seconds";
+  public static final String EXPIRATION_INTERVAL_SECONDS =
+      "geode-for-redis-expiration-interval-seconds";
+
+
+  /** assumes that default is greater than or equal to minValue **/
+  public static int getIntegerSystemProperty(String propName, int 
defaultValue, int minValue) {
+    int geodeValue = Integer.getInteger("geode." + propName, defaultValue);
+    int gemfireValue = Integer.getInteger("gemfire." + propName, defaultValue);
+
+    if (geodeValue != defaultValue && geodeValue >= minValue) {
+      return geodeValue;
+    } else if (gemfireValue != defaultValue && gemfireValue >= minValue) {
+      return gemfireValue;
+    } else {
+      return defaultValue;
+    }
+  }
+}
diff --git 
a/geode-for-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
 
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
index 0f1c722..44569f9 100644
--- 
a/geode-for-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
+++ 
b/geode-for-redis/src/main/java/org/apache/geode/redis/internal/netty/NettyRedisServer.java
@@ -17,6 +17,10 @@
 package org.apache.geode.redis.internal.netty;
 
 
+
+import static 
org.apache.geode.redis.internal.RedisProperties.WRITE_TIMEOUT_SECONDS;
+import static 
org.apache.geode.redis.internal.RedisProperties.getIntegerSystemProperty;
+
 import java.io.IOException;
 import java.io.UncheckedIOException;
 import java.net.InetAddress;
@@ -68,12 +72,9 @@ import org.apache.geode.redis.internal.statistics.RedisStats;
 public class NettyRedisServer {
 
   private static final int RANDOM_PORT_INDICATOR = 0;
+  public static final int DEFAULT_REDIS_WRITE_TIMEOUT_SECONDS = 10;
 
   private static final Logger logger = LogService.getLogger();
-  /**
-   * Connection timeout in milliseconds
-   */
-  private static final int CONNECT_TIMEOUT_MILLIS = 1000;
 
   private final Supplier<DistributionConfig> configSupplier;
   private final RegionProvider regionProvider;
@@ -88,6 +89,7 @@ public class NettyRedisServer {
   private final int serverPort;
   private final DistributedMember member;
   private final RedisSecurityService securityService;
+  private final int writeTimeoutSeconds;
 
   public NettyRedisServer(Supplier<DistributionConfig> configSupplier,
       RegionProvider regionProvider, PubSub pubsub, Supplier<Boolean> 
allowUnsupportedSupplier,
@@ -102,10 +104,8 @@ public class NettyRedisServer {
     this.member = member;
     this.securityService = securityService;
 
-    if (port < RANDOM_PORT_INDICATOR) {
-      throw new IllegalArgumentException(
-          "The geode-for-redis-port cannot be less than " + 
RANDOM_PORT_INDICATOR);
-    }
+    this.writeTimeoutSeconds =
+        getIntegerSystemProperty(WRITE_TIMEOUT_SECONDS, 
DEFAULT_REDIS_WRITE_TIMEOUT_SECONDS, 1);
 
     selectorGroup = createEventLoopGroup("Selector", true, 1);
     workerGroup = createEventLoopGroup("Worker", true, 0);
@@ -130,7 +130,6 @@ public class NettyRedisServer {
             .option(ChannelOption.SO_REUSEADDR, true)
             .option(ChannelOption.SO_RCVBUF, getBufferSize())
             .childOption(ChannelOption.SO_KEEPALIVE, true)
-            .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 
CONNECT_TIMEOUT_MILLIS)
             .childOption(ChannelOption.ALLOCATOR, 
PooledByteBufAllocator.DEFAULT);
 
     return createBoundChannel(serverBootstrap, port);
@@ -170,7 +169,7 @@ public class NettyRedisServer {
         addSSLIfEnabled(socketChannel, pipeline);
         pipeline.addLast(ByteToCommandDecoder.class.getSimpleName(),
             new ByteToCommandDecoder(redisStats, securityService, 
socketChannel.id()));
-        pipeline.addLast(new WriteTimeoutHandler(10));
+        pipeline.addLast(new WriteTimeoutHandler(writeTimeoutSeconds));
         pipeline.addLast(ExecutionHandlerContext.class.getSimpleName(),
             new ExecutionHandlerContext(socketChannel, regionProvider, pubsub,
                 allowUnsupportedSupplier, shutdownInvoker, redisStats, 
redisUsername,
diff --git 
a/geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/RedisPropertiesTest.java
 
b/geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/RedisPropertiesTest.java
new file mode 100644
index 0000000..d63253b
--- /dev/null
+++ 
b/geode-for-redis/src/test/java/org/apache/geode/redis/internal/data/RedisPropertiesTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.internal.data;
+
+import static 
org.apache.geode.redis.internal.RedisProperties.getIntegerSystemProperty;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+
+public class RedisPropertiesTest {
+  @Test
+  public void 
getIntegerSystemProperty_shouldReturnSpecifiedDefault_whenNeitherPrefixIsSet() {
+    assertThat(getIntegerSystemProperty("prop.name", 5, 0)).isEqualTo(5);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldReturnSpecifiedDefault_whenSetToEmptyString() {
+    System.setProperty("geode.prop.name0", "");
+    assertThat(getIntegerSystemProperty("prop.name0", 5, 0)).isEqualTo(5);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldReturnSpecifiedDefault_whenSetToNonIntegerString()
 {
+    System.setProperty("geode.prop.name0", "nonintegervalue");
+    assertThat(getIntegerSystemProperty("prop.name0", 5, 0)).isEqualTo(5);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldReturnSpecifiedDefault_whenSetToIntegerOutOfRange()
 {
+    System.setProperty("geode.prop.name1", "-5");
+    assertThat(getIntegerSystemProperty("prop.name1", 5, 0)).isEqualTo(5);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldReturnSetValue_whenSetToIntegerInRange() {
+    System.setProperty("geode.prop.name2", "10");
+    assertThat(getIntegerSystemProperty("prop.name2", 5, 0)).isEqualTo(10);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldDefaultToGeodePrefix_whenGemfireAlsoSet() {
+    System.setProperty("geode.prop.name3", "15");
+    System.setProperty("gemfire.prop.name3", "16");
+    assertThat(getIntegerSystemProperty("prop.name3", 5, 0))
+        .isEqualTo(15);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldUseGemfirePrefix_whenGeodePrefixOutOfRange() {
+    System.setProperty("geode.prop.name4", "-1");
+    System.setProperty("gemfire.prop.name4", "42");
+    assertThat(getIntegerSystemProperty("prop.name4", 3, 0)).isEqualTo(42);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldUseDefault_whenPrefixesAreOutOfRange() {
+    System.setProperty("geode.prop.name5", "-1");
+    System.setProperty("gemfire.prop.name5", "-2");
+    assertThat(getIntegerSystemProperty("prop.name5", 5, 0)).isEqualTo(5);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldUseGemfirePrefix_whenGeodeNotSet() {
+    System.setProperty("gemfire.prop.name6", "72");
+    assertThat(getIntegerSystemProperty("prop.name6", 5, 0)).isEqualTo(72);
+  }
+
+  @Test
+  public void 
getIntegerSystemProperty_shouldUseSetValue_whenSetToMinimumValue() {
+    System.setProperty("geode.prop.name7", "42");
+    assertThat(getIntegerSystemProperty("prop.name7", 5, 42)).isEqualTo(42);
+  }
+}

Reply via email to