arjunashok commented on code in PR #166:
URL: https://github.com/apache/cassandra-sidecar/pull/166#discussion_r1915613765


##########
server/src/test/integration/org/apache/cassandra/sidecar/routes/StreamStatsIntegrationTest.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import com.datastax.driver.core.Session;
+import io.vertx.core.buffer.Buffer;
+import io.vertx.ext.web.client.HttpResponse;
+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.shared.ClusterUtils;
+import org.apache.cassandra.distributed.shared.Uninterruptibles;
+import org.apache.cassandra.sidecar.common.response.StreamStatsResponse;
+import org.apache.cassandra.sidecar.common.response.data.StreamProgressStats;
+import org.apache.cassandra.sidecar.common.server.data.QualifiedTableName;
+import org.apache.cassandra.sidecar.testing.CassandraSidecarTestContext;
+import org.apache.cassandra.sidecar.testing.IntegrationTestBase;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.cassandra.testing.ConfigurableCassandraTestContext;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests the stream stats endpoint with cassandra container.
+ */
+@ExtendWith(VertxExtension.class)
+public class StreamStatsIntegrationTest extends IntegrationTestBase
+{
+    @CassandraIntegrationTest(numDataDirsPerInstance = 4, nodesPerDc = 5, 
network = true, buildCluster = false)
+    void streamStatsTest(VertxTestContext context, 
ConfigurableCassandraTestContext cassandraTestContext) throws 
InterruptedException
+    {
+
+        BBHelperDecommissioningNode.reset();
+        UpgradeableCluster cluster = 
cassandraTestContext.configureAndStartCluster(
+        builder -> 
builder.withInstanceInitializer(BBHelperDecommissioningNode::install));
+        IUpgradeableInstance node = cluster.get(5);
+        IUpgradeableInstance seed = cluster.get(1);
+
+        createTestKeyspace();
+        createTestTableAndPopulate();
+
+        startAsync("Decommission node" + node.config().num(),
+                   () -> 
node.nodetoolResult("decommission").asserts().success());
+        AtomicBoolean hasStats = new AtomicBoolean(false);
+        AtomicBoolean dataReceived = new AtomicBoolean(false);
+
+        // Wait until nodes have reached expected state
+        awaitLatchOrThrow(BBHelperDecommissioningNode.transientStateStart, 2, 
TimeUnit.MINUTES, "transientStateStart");
+
+        ClusterUtils.awaitRingState(seed, node, "Leaving");
+        BBHelperDecommissioningNode.transientStateEnd.countDown();
+
+        for (int i = 0; i < 20; i++)

Review Comment:
   This was an optimal no. of attempts to poll for stats with the provided 
delay to deterministically capture streaming stats after a node was 
decommissioned. Will add this as a comment.



##########
server/src/test/integration/org/apache/cassandra/sidecar/routes/StreamStatsIntegrationTest.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import com.datastax.driver.core.Session;
+import io.vertx.core.buffer.Buffer;
+import io.vertx.ext.web.client.HttpResponse;
+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.shared.ClusterUtils;
+import org.apache.cassandra.distributed.shared.Uninterruptibles;
+import org.apache.cassandra.sidecar.common.response.StreamStatsResponse;
+import org.apache.cassandra.sidecar.common.response.data.StreamProgressStats;
+import org.apache.cassandra.sidecar.common.server.data.QualifiedTableName;
+import org.apache.cassandra.sidecar.testing.CassandraSidecarTestContext;
+import org.apache.cassandra.sidecar.testing.IntegrationTestBase;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.cassandra.testing.ConfigurableCassandraTestContext;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests the stream stats endpoint with cassandra container.
+ */
+@ExtendWith(VertxExtension.class)
+public class StreamStatsIntegrationTest extends IntegrationTestBase
+{
+    @CassandraIntegrationTest(numDataDirsPerInstance = 4, nodesPerDc = 5, 
network = true, buildCluster = false)
+    void streamStatsTest(VertxTestContext context, 
ConfigurableCassandraTestContext cassandraTestContext) throws 
InterruptedException
+    {
+
+        BBHelperDecommissioningNode.reset();
+        UpgradeableCluster cluster = 
cassandraTestContext.configureAndStartCluster(
+        builder -> 
builder.withInstanceInitializer(BBHelperDecommissioningNode::install));
+        IUpgradeableInstance node = cluster.get(5);
+        IUpgradeableInstance seed = cluster.get(1);
+
+        createTestKeyspace();
+        createTestTableAndPopulate();
+
+        startAsync("Decommission node" + node.config().num(),
+                   () -> 
node.nodetoolResult("decommission").asserts().success());
+        AtomicBoolean hasStats = new AtomicBoolean(false);
+        AtomicBoolean dataReceived = new AtomicBoolean(false);
+
+        // Wait until nodes have reached expected state
+        awaitLatchOrThrow(BBHelperDecommissioningNode.transientStateStart, 2, 
TimeUnit.MINUTES, "transientStateStart");
+
+        ClusterUtils.awaitRingState(seed, node, "Leaving");
+        BBHelperDecommissioningNode.transientStateEnd.countDown();
+
+        for (int i = 0; i < 20; i++)
+        {
+            startAsync("Request-" + i , () -> {
+                try
+                {
+                    streamStats(context, hasStats, dataReceived);
+                }
+                catch (Exception e)
+                {
+                    throw new RuntimeException(e);
+                }
+            });
+
+            Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
+        }
+
+        assertThat(hasStats).isTrue();
+        assertThat(dataReceived).isTrue();
+        context.completeNow();
+        context.awaitCompletion(2, TimeUnit.MINUTES);
+    }
+
+    private void streamStats(VertxTestContext context, AtomicBoolean hasStats, 
AtomicBoolean dataReceived) throws Exception
+    {
+        String testRoute = "/api/v1/cassandra/stats/stream";
+        testWithClient(context, client -> {
+            BBHelperDecommissioningNode.transientStateEnd.countDown();
+            client.get(server.actualPort(), "127.0.0.1", testRoute)
+                  .send(context.succeeding(response -> {
+                       assertRingResponseOK(response, sidecarTestContext, 
hasStats, dataReceived);
+                  }));
+        });
+    }
+
+    void assertRingResponseOK(HttpResponse<Buffer> response, 
CassandraSidecarTestContext cassandraTestContext,
+                              AtomicBoolean hasStats, AtomicBoolean 
dataReceived)
+    {
+        StreamStatsResponse streamStatsResponse = 
response.bodyAsJson(StreamStatsResponse.class);
+        assertThat(streamStatsResponse).isNotNull();
+        StreamProgressStats streamProgress = 
streamStatsResponse.streamProgressStats();
+        assertThat(streamProgress).isNotNull();
+        if (streamProgress.totalFilesToReceive() > 0)
+        {
+            hasStats.set(true);
+            if (streamProgress.totalFilesToReceive() == 
streamProgress.totalFilesReceived() &&

Review Comment:
   Since the integration test is polling the stats API until we actually have 
some data streamed to validate, we only validate bytes received in such cases. 
However, the test does validate that there were stats captured and data 
received at the end of all the attempts.



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