sklaha commented on code in PR #249:
URL: https://github.com/apache/cassandra-sidecar/pull/249#discussion_r2322711529


##########
integration-tests/src/integrationTest/org/apache/cassandra/sidecar/routes/CassandraStatsIntegrationTest.java:
##########
@@ -256,4 +280,280 @@ void assertClientStatsResponse(HttpResponse<Buffer> 
response, Map<String, Boolea
             }
         }
     }
+
+    @Test
+    void testCompactionStatsRetrieval()
+    {
+        logger.info("Starting compaction stats test with {} tables", 
COMPACTION_TEST_TABLES.size());
+
+        // Generate SSTables for all test tables
+        for (QualifiedName tableName : COMPACTION_TEST_TABLES)
+        {
+            generateSSTables(tableName, 100);
+        }
+
+        // Create threads to trigger compaction on all tables
+        List<Thread> compactionThreads = new ArrayList<>();
+        for (QualifiedName tableName : COMPACTION_TEST_TABLES)
+        {
+            Thread thread = new Thread(() -> 
triggerCompactionForTable(tableName));
+            compactionThreads.add(thread);
+        }
+
+        // Start all compaction threads
+        for (Thread thread : compactionThreads)
+        {
+            thread.start();
+        }
+
+        // Poll immediately and repeatedly to catch active compactions
+        CompactionStatsResponse stats = null;
+        HttpResponse<Buffer> response;
+        boolean foundActiveCompactions;
+
+        for (int attempt = 0; attempt < MAX_POLL_ATTEMPTS; attempt++)
+        {
+            try
+            {
+                response = getBlocking(
+                trustedClient().get(serverWrapper.serverPort, "localhost", 
COMPACTION_STATS_ROUTE)
+                               .send()
+                               .expecting(HttpResponseExpectation.SC_OK));
+
+                stats = response.bodyAsJson(CompactionStatsResponse.class);
+                foundActiveCompactions = !stats.activeCompactions().isEmpty();
+
+                if (foundActiveCompactions)
+                {
+                    logger.info("SUCCESS: Found {} active compactions on 
attempt {}",
+                                stats.activeCompactionsCount(), attempt + 1);
+                    break;
+                }
+                else
+                {
+                    logger.info("Attempt {}: No active compactions yet", 
attempt + 1);
+                }
+
+                Thread.sleep(100); // Short sleep between attempts
+            }
+            catch (InterruptedException e)
+            {
+                Thread.currentThread().interrupt();
+                break;
+            }
+        }
+
+        // Wait for all compaction threads to complete
+        for (Thread thread : compactionThreads)
+        {
+            try
+            {
+                thread.join(5000);
+            }
+            catch (InterruptedException e)
+            {
+                Thread.currentThread().interrupt();
+                break;
+            }
+        }
+        assertThat(stats).isNotNull();
+        logger.info("Response:{}", stats);
+        validateCompactionStatsResponse(stats);
+    }
+
+
+    private void generateSSTables(QualifiedName tableName, int numSSTables)
+    {
+        for (int batch = 0; batch < numSSTables; batch++)
+        {
+            for (int i = batch * 1000; i < (batch + 1) * 1000; i++)
+            {
+                String statement = String.format("INSERT INTO %s (id, data) 
VALUES (%d, '%s');",
+                                                 tableName, i, "data" + i);
+                cluster.schemaChangeIgnoringStoppedInstances(statement);
+            }
+            cluster.stream().forEach(instance -> 
instance.flush(TEST_KEYSPACE));
+        }
+    }
+
+    private void triggerCompactionForTable(QualifiedName tableName)
+    {
+        cluster.stream().forEach(instance ->
+                                 {
+                                     try
+                                     {
+                                         instance.nodetool("compact", 
tableName.keyspace(), tableName.table());
+                                     }
+                                     catch (Exception e)
+                                     {
+                                         logger.warn("Failed to trigger 
compaction for {}: {}", tableName, e.getMessage());
+                                     }
+                                 });
+    }
+
+    private void validateCompactionStatsResponse(CompactionStatsResponse stats)
+    {
+        assertThat(stats).isNotNull();
+
+        // Basic counters validation
+        assertThat(stats.concurrentCompactors()).isGreaterThanOrEqualTo(0);
+        assertThat(stats.totalPendingTasks()).isGreaterThanOrEqualTo(0);
+        assertThat(stats.completedCompactions()).isGreaterThanOrEqualTo(0);
+        assertThat(stats.dataCompacted()).isGreaterThanOrEqualTo(0);
+        assertThat(stats.abortedCompactions()).isGreaterThanOrEqualTo(0);
+        assertThat(stats.reducedCompactions()).isGreaterThanOrEqualTo(0);
+        
assertThat(stats.sstablesDroppedFromCompaction()).isGreaterThanOrEqualTo(0);
+
+        // Pending tasks validation
+        assertThat(stats.pendingTasks()).isNotNull();
+
+        // Validate each pending task entry if there are any
+        if (!stats.pendingTasks().isEmpty())
+        {
+            validatePendingTasks(stats);
+        }
+
+        // Completion rates validation
+        assertThat(stats.completedCompactionsRate()).isNotNull();
+
+        // Validate mean rate format is X.XX/hour

Review Comment:
   Fixed



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