yifan-c commented on code in PR #144:
URL: https://github.com/apache/cassandra-sidecar/pull/144#discussion_r1915453542


##########
server/src/test/integration/org/apache/cassandra/sidecar/routes/NodeDecommissionIntegrationTest.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.google.common.util.concurrent.Uninterruptibles;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.buffer.Buffer;
+import io.vertx.ext.web.client.HttpResponse;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.common.data.OperationalJobStatus;
+import org.apache.cassandra.sidecar.common.response.OperationalJobResponse;
+import org.apache.cassandra.sidecar.testing.IntegrationTestBase;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+
+import static org.apache.cassandra.sidecar.AssertionUtils.loopAssert;
+import static 
org.apache.cassandra.sidecar.common.data.OperationalJobStatus.FAILED;
+import static 
org.apache.cassandra.sidecar.common.data.OperationalJobStatus.RUNNING;
+import static 
org.apache.cassandra.sidecar.common.data.OperationalJobStatus.SUCCEEDED;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+/**
+ * Test the node decommission endpoint with cassandra container.
+ */
+@ExtendWith(VertxExtension.class)
+public class NodeDecommissionIntegrationTest extends IntegrationTestBase
+{
+    @CassandraIntegrationTest(nodesPerDc = 2)
+    void decommissionNodeDefault(VertxTestContext context) throws 
InterruptedException
+    {
+        final String[] jobId = new String[1];
+        String testRoute = 
"/api/v1/cassandra/operations/decommission?force=true";
+        testWithClient(client -> client.put(server.actualPort(), "127.0.0.1", 
testRoute)
+                                       .send(context.succeeding(response -> {
+                                           logger.info("Response Status:" + 
response.statusCode());
+                                           OperationalJobResponse 
decommissionResponse = response.bodyAsJson(OperationalJobResponse.class);
+                                           
assertThat(decommissionResponse.status()).isEqualTo(RUNNING);
+                                           jobId[0] = 
String.valueOf(decommissionResponse.jobId());
+                                       })));
+        Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
+        pollStatusForState(jobId[0], SUCCEEDED, null);
+        context.completeNow();
+        context.awaitCompletion(2, TimeUnit.MINUTES);
+    }
+
+    @CassandraIntegrationTest(nodesPerDc = 2)
+    void decommissionNodeWithFailure(VertxTestContext context) throws 
InterruptedException
+    {
+        String testRoute = "/api/v1/cassandra/operations/decommission";
+        testWithClient(client -> client.put(server.actualPort(), "127.0.0.1", 
testRoute)
+                                       .send(context.succeeding(response -> {
+                                           logger.info("Response Status:" + 
response.statusCode());
+                                           logger.info("Response Body:" + 
response.bodyAsString());
+                                           OperationalJobResponse 
decommissionResponse = response.bodyAsJson(OperationalJobResponse.class);
+                                           
assertThat(decommissionResponse.status()).isEqualTo(FAILED);
+                                           
assertThat(decommissionResponse.jobId()).isNotNull();
+                                           String jobId = 
String.valueOf(decommissionResponse.jobId());
+                                           assertThat(jobId).isNotNull();
+                                           context.completeNow();
+                                       })));
+        context.awaitCompletion(2, TimeUnit.MINUTES);
+    }
+
+    private void pollStatusForState(String uuid,
+                                    OperationalJobStatus expectedStatus,
+                                    String expectedReason)
+    {
+        int attempts = 10;
+        String status = "/api/v1/cassandra/operational-jobs/" + uuid;
+        AtomicBoolean stateReached = new AtomicBoolean(false);
+        logger.info("Job Stats Attempt: {}", attempts);
+        AtomicInteger counter = new AtomicInteger(0);
+        loopAssert(30, () -> {
+            counter.incrementAndGet();
+            // todo: create a helper method in the base class to get response 
in the blocking manner

Review Comment:
   let's keep the todo. I am adding the helper in another patch. Find it 
useful. I will update here when rebasing. 



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to