jdeppe-pivotal commented on a change in pull request #7146: URL: https://github.com/apache/geode/pull/7146#discussion_r759292046
########## File path: geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/executor/auth/AuthWhileServersRestartDUnitTest.java ########## @@ -0,0 +1,127 @@ +/* + * 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.executor.auth; + +import static org.apache.geode.distributed.ConfigurationProperties.GEODE_FOR_REDIS_PORT; +import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS; +import static org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT; +import static redis.clients.jedis.BinaryJedisCluster.DEFAULT_MAX_ATTEMPTS; + +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; + +import org.apache.geode.examples.SimpleSecurityManager; +import org.apache.geode.internal.AvailablePortHelper; +import org.apache.geode.redis.ConcurrentLoopingThreads; +import org.apache.geode.test.dunit.rules.MemberVM; +import org.apache.geode.test.dunit.rules.RedisClusterStartupRule; +import org.apache.geode.test.dunit.rules.SerializableFunction; +import org.apache.geode.test.junit.rules.ExecutorServiceRule; +import org.apache.geode.test.junit.rules.ServerStarterRule; + +public class AuthWhileServersRestartDUnitTest { + + @ClassRule + public static RedisClusterStartupRule clusterStartUp = new RedisClusterStartupRule(4); + + @ClassRule + public static ExecutorServiceRule executor = new ExecutorServiceRule(); + + private static int redisServerPort; + private static SerializableFunction<ServerStarterRule> operatorForVM3; + private static final String KEY = "key"; + private static final int SO_TIMEOUT = 10_000; + + @BeforeClass + public static void classSetup() { + MemberVM locator = clusterStartUp.startLocatorVM(0, + x -> x.withSecurityManager(SimpleSecurityManager.class)); + int locatorPort = locator.getPort(); + + SerializableFunction<ServerStarterRule> serverOperator = s -> s + .withCredential("cluster", "cluster") + .withConnectionToLocator(locatorPort); + + clusterStartUp.startRedisVM(1, serverOperator); + clusterStartUp.startRedisVM(2, serverOperator); + + int server3Port = AvailablePortHelper.getRandomAvailableTCPPort(); + String finalRedisPort = Integer.toString(server3Port); + + operatorForVM3 = serverOperator.compose(o -> o + .withProperty(GEODE_FOR_REDIS_PORT, finalRedisPort)); + + clusterStartUp.startRedisVM(3, operatorForVM3); + + redisServerPort = clusterStartUp.getRedisPort(1); + // Make sure buckets get created + new JedisCluster(new HostAndPort(BIND_ADDRESS, redisServerPort), + REDIS_CLIENT_TIMEOUT, SO_TIMEOUT, DEFAULT_MAX_ATTEMPTS, "data", "data", "bootstrap", + new GenericObjectPoolConfig<>()); + } + + @After + public void after() { + clusterStartUp.flushAll("data", "data"); + } + + @Test + public void testReconnectionWithAuthAndServerRestarts() throws Exception { + AtomicBoolean running = new AtomicBoolean(true); + + Future<?> future = executor.submit(() -> { + try { + for (int i = 0; i < 20 && running.get(); i++) { + clusterStartUp.moveBucketForKey(KEY, "server-3"); + // Sleep for a bit so that commands can execute + Thread.sleep(2000); Review comment: Good call - I've switched over to using an awaitility statement instead of `sleep`, Regarding the future used here - `AsyncInvocation` is used for remote async calls. This code is all just local to this JVM and does not do any obvious remote calls. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
