[ https://issues.apache.org/jira/browse/GEODE-8965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17298913#comment-17298913 ]
ASF GitHub Bot commented on GEODE-8965: --------------------------------------- sabbey37 commented on a change in pull request #6085: URL: https://github.com/apache/geode/pull/6085#discussion_r591631839 ########## File path: geode-redis/src/distributedTest/java/org/apache/geode/redis/OutOfMemoryDUnitTest.java ########## @@ -0,0 +1,225 @@ +/* + * 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 static org.apache.geode.test.awaitility.GeodeAwaitility.await; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable; + +import java.util.Arrays; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.exceptions.JedisException; + +import org.apache.geode.test.awaitility.GeodeAwaitility; +import org.apache.geode.test.dunit.IgnoredException; +import org.apache.geode.test.dunit.rules.MemberVM; +import org.apache.geode.test.dunit.rules.RedisClusterStartupRule; +import org.apache.geode.test.junit.rules.ExecutorServiceRule; + +public class OutOfMemoryDUnitTest { + + @ClassRule + public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4); + + @Rule + public ExecutorServiceRule executor = new ExecutorServiceRule(); + + private static final String expectedEx = "Member: .*? above .*? critical threshold"; + private static final String FILLER_KEY = "fillerKey-"; + private static final String PRESSURE_KEY = "pressureKey-"; + private static final String LOCAL_HOST = "127.0.0.1"; + private static final int KEY_TTL_SECONDS = 10; + private static final int MAX_ITERATION_COUNT = 4000; + private static final int LARGE_VALUE_SIZE = 128 * 1024; + private static final int PRESSURE_VALUE_SIZE = 4 * 1024; + private static final int JEDIS_TIMEOUT = + Math.toIntExact(GeodeAwaitility.getTimeout().toMillis()); + private static Jedis jedis1; + private static Jedis jedis2; + + private static MemberVM server1; + private static MemberVM server2; + + private static Thread memoryPressureThread; + + @BeforeClass + public static void classSetup() { + IgnoredException.addIgnoredException(expectedEx); + + MemberVM locator = clusterStartUp.startLocatorVM(0); + + Properties serverProperties = new Properties(); + server1 = clusterStartUp.startRedisVM(1, serverProperties, locator.getPort()); + server2 = clusterStartUp.startRedisVM(2, serverProperties, locator.getPort()); + + server1.getVM().invoke(() -> RedisClusterStartupRule.getCache().getResourceManager() + .setCriticalHeapPercentage(5.0F)); + server2.getVM().invoke(() -> RedisClusterStartupRule.getCache().getResourceManager() + .setCriticalHeapPercentage(5.0F)); + + int redisServerPort1 = clusterStartUp.getRedisPort(1); + int redisServerPort2 = clusterStartUp.getRedisPort(2); + + jedis1 = new Jedis(LOCAL_HOST, redisServerPort1, JEDIS_TIMEOUT); + jedis2 = new Jedis(LOCAL_HOST, redisServerPort2, JEDIS_TIMEOUT); + } + + @Before + public void testSetup() { + jedis1.flushAll(); + } + + @AfterClass + public static void tearDown() { + jedis1.disconnect(); + jedis2.disconnect(); + + server1.stop(); + server2.stop(); + } + + @Test + public void shouldReturnOOMError_forWriteOperations_whenThresholdReached() + throws InterruptedException { + IgnoredException.addIgnoredException(expectedEx); + IgnoredException.addIgnoredException("LowMemoryException"); + + memoryPressureThread = new Thread(makeMemoryPressureRunnable()); + memoryPressureThread.start(); + + fillMemory(jedis2, false); + + assertThatThrownBy(() -> jedis2.set("oneMoreKey", makeLongStringValue(2 * LARGE_VALUE_SIZE))) + .hasMessageContaining("OOM"); + + memoryPressureThread.interrupt(); + memoryPressureThread.join(); + } + + @Test + public void shouldAllowDeleteOperations_afterThresholdReached() throws InterruptedException { + IgnoredException.addIgnoredException(expectedEx); + IgnoredException.addIgnoredException("LowMemoryException"); + + fillMemory(jedis2, false); + + assertThatNoException().isThrownBy(() -> jedis2.del(FILLER_KEY + 1)); + } + + @Test + public void shouldAllowExpiration_afterThresholdReached() { + IgnoredException.addIgnoredException(expectedEx); + IgnoredException.addIgnoredException("LowMemoryException"); + + fillMemory(jedis2, true); + + await().untilAsserted(() -> { + assertThat(jedis2.ttl(FILLER_KEY + 1)).isEqualTo(-2); + }); + } Review comment: Since we weren't actually filling the memory in the previous test `shouldReturnOOMError_forWriteOperations_whenThresholdReached`, how can we know we're filling the memory here before verifying delete operations and expirations perform as expected? Would it make sense to also add the `memoryPressureThread` here? Not sure if we should also add the OOM error assertion to verify the system is actually out of memory before trying to delete or wait for expiration, though that seems to be the only way we'd know we reached the threshold right before performing the delete or verifying expiration. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Implement Redis "noevict" policy for Geode Redis > ------------------------------------------------ > > Key: GEODE-8965 > URL: https://issues.apache.org/jira/browse/GEODE-8965 > Project: Geode > Issue Type: New Feature > Components: redis > Reporter: Raymond Ingles > Assignee: Raymond Ingles > Priority: Major > Labels: blocks-1.14.0, pull-request-available > > Redis supports the "noevict" eviction policy. When this is selected, Redis > returns an OOM error when commands that consume new memory are attempted. New > data cannot be written to the cache until either TTL expiration or explicit > deletion of keys has freed enough memory to allow write operations again. -- This message was sent by Atlassian Jira (v8.3.4#803005)