JeetKunDoug commented on code in PR #58:
URL: https://github.com/apache/cassandra-sidecar/pull/58#discussion_r1313399299


##########
src/test/integration/org/apache/cassandra/sidecar/routes/TokenRangeIntegrationLeavingTest.java:
##########
@@ -0,0 +1,786 @@
+/*
+ * 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.cassandra.sidecar.routes;
+
+import java.math.BigInteger;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Range;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.Uninterruptibles;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import net.bytebuddy.ByteBuddy;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.dynamic.ClassFileLocator;
+import net.bytebuddy.dynamic.TypeResolutionStrategy;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+import net.bytebuddy.implementation.MethodDelegation;
+import net.bytebuddy.implementation.bind.annotation.SuperCall;
+import net.bytebuddy.pool.TypePool;
+import org.apache.cassandra.distributed.UpgradeableCluster;
+import org.apache.cassandra.distributed.api.IUpgradeableInstance;
+import org.apache.cassandra.distributed.api.TokenSupplier;
+import org.apache.cassandra.distributed.shared.ClusterUtils;
+import org.apache.cassandra.sidecar.common.data.TokenRangeReplicasResponse;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.cassandra.testing.ConfigurableCassandraTestContext;
+import org.apache.cassandra.utils.Shared;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Cluster shrink scenarios integration tests for token range replica mapping 
endpoint with cassandra container.
+ */
+@ExtendWith(VertxExtension.class)
+public class TokenRangeIntegrationLeavingTest extends 
BaseTokenRangeIntegrationTest
+{
+    @CassandraIntegrationTest(nodesPerDc = 5, network = true, gossip = true, 
buildCluster = false)
+    void retrieveMappingWithKeyspaceLeavingNode(VertxTestContext context,
+                                                
ConfigurableCassandraTestContext cassandraTestContext) throws Exception
+    {
+        runLeavingTestScenario(context,
+                               cassandraTestContext,
+                               1,
+                               BBHelperSingleLeavingNode::install,
+                               BBHelperSingleLeavingNode.TRANSIENT_STATE_START,
+                               BBHelperSingleLeavingNode.TRANSIENT_STATE_END,
+                               
generateExpectedRangeMappingSingleLeavingNode());
+    }
+
+    @CassandraIntegrationTest(nodesPerDc = 5, network = true, gossip = true, 
buildCluster = false)
+    void retrieveMappingWithMultipleLeavingNodes(VertxTestContext context,
+                                                 
ConfigurableCassandraTestContext cassandraTestContext) throws Exception
+    {
+        runLeavingTestScenario(context,
+                               cassandraTestContext,
+                               2,
+                               BBHelperMultipleLeavingNodes::install,
+                               
BBHelperMultipleLeavingNodes.TRANSIENT_STATE_START,
+                               
BBHelperMultipleLeavingNodes.TRANSIENT_STATE_END,
+                               
generateExpectedRangeMappingMultipleLeavingNodes());
+    }
+
+    @CassandraIntegrationTest(nodesPerDc = 6, network = true, gossip = true, 
buildCluster = false)
+    void retrieveMappingHalveClusterSize(VertxTestContext context,
+                                         ConfigurableCassandraTestContext 
cassandraTestContext) throws Exception
+    {
+        runLeavingTestScenario(context,
+                               cassandraTestContext,
+                               3,
+                               BBHelperHalveClusterSize::install,
+                               BBHelperHalveClusterSize.TRANSIENT_STATE_START,
+                               BBHelperHalveClusterSize.TRANSIENT_STATE_END,
+                               generateExpectedRangeMappingHalveClusterSize());
+    }
+
+    @CassandraIntegrationTest(
+    nodesPerDc = 5, numDcs = 2, network = true, gossip = true, buildCluster = 
false)
+    void retrieveMappingWithLeavingNodesMultiDC(VertxTestContext context,
+                                                
ConfigurableCassandraTestContext cassandraTestContext)
+    throws Exception
+    {
+
+        int leavingNodesPerDC = 1;
+        CassandraIntegrationTest annotation = 
sidecarTestContext.cassandraTestContext().annotation;
+        int numNodes = annotation.nodesPerDc() + annotation.newNodesPerDc();
+        UpgradeableCluster cluster = getMultiDCCluster(numNodes,
+                                                       annotation.numDcs(),
+                                                       
BBHelperLeavingNodesMultiDC::install,
+                                                       cassandraTestContext);
+
+        runLeavingTestScenario(context,
+                               leavingNodesPerDC,
+                               
BBHelperLeavingNodesMultiDC.TRANSIENT_STATE_START,
+                               BBHelperLeavingNodesMultiDC.TRANSIENT_STATE_END,
+                               cluster,
+                               
generateExpectedRangeMappingLeavingNodeMultiDC());
+    }
+
+    @CassandraIntegrationTest(nodesPerDc = 6, numDcs = 2, network = true, 
gossip = true, buildCluster = false)
+    void retrieveMappingMultiDCHalveClusterSize(VertxTestContext context,
+                                                
ConfigurableCassandraTestContext cassandraTestContext) throws Exception
+    {
+
+        int leavingNodesPerDC = 3;
+        CassandraIntegrationTest annotation = 
sidecarTestContext.cassandraTestContext().annotation;
+        int numNodes = annotation.nodesPerDc() + annotation.newNodesPerDc();
+        UpgradeableCluster cluster = getMultiDCCluster(numNodes,
+                                                       annotation.numDcs(),
+                                                       
BBHelperHalveClusterMultiDC::install,
+                                                       cassandraTestContext);
+
+        Map<String, Map<Range<BigInteger>, List<String>>> expectedRangeMappings
+        = generateExpectedRangeHalveClusterSizeMultiDC();
+        runLeavingTestScenario(context,
+                               leavingNodesPerDC,
+                               
BBHelperHalveClusterMultiDC.TRANSIENT_STATE_START,
+                               BBHelperHalveClusterMultiDC.TRANSIENT_STATE_END,
+                               cluster,
+                               expectedRangeMappings);
+    }
+
+    void runLeavingTestScenario(VertxTestContext context,
+                                ConfigurableCassandraTestContext 
cassandraTestContext,
+                                int leavingNodesPerDC,
+                                BiConsumer<ClassLoader, Integer> 
instanceInitializer,
+                                CountDownLatch transientStateStart,
+                                CountDownLatch transientStateEnd,
+                                Map<String, Map<Range<BigInteger>, 
List<String>>> expectedRangeMappings)
+    throws Exception
+    {
+
+        UpgradeableCluster cluster = 
cassandraTestContext.configureAndStartCluster(
+        builder -> builder.withInstanceInitializer(instanceInitializer));
+
+        runLeavingTestScenario(context,
+                               leavingNodesPerDC,
+                               transientStateStart,
+                               transientStateEnd,
+                               cluster,
+                               expectedRangeMappings);
+    }
+
+    void runLeavingTestScenario(VertxTestContext context,
+                                int leavingNodesPerDC,
+                                CountDownLatch transientStateStart,
+                                CountDownLatch transientStateEnd,
+                                UpgradeableCluster cluster,
+                                Map<String, Map<Range<BigInteger>, 
List<String>>> expectedRangeMappings)
+    throws Exception
+    {
+        try
+        {
+            CassandraIntegrationTest annotation = 
sidecarTestContext.cassandraTestContext().annotation;
+            Set<String> dcReplication;
+
+            if (annotation.numDcs() > 1)

Review Comment:
   This logic is repeated a bunch of times - maybe move to the integration test 
base?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to