diff --git a/src/main/java/com/fauna/client/Stats.java b/src/main/java/com/fauna/client/QueryStatsSummary.java similarity index 54% rename from src/main/java/com/fauna/client/Stats.java rename to src/main/java/com/fauna/client/QueryStatsSummary.java index 71bb0f56..4e10a9cd 100644 --- a/src/main/java/com/fauna/client/Stats.java +++ b/src/main/java/com/fauna/client/QueryStatsSummary.java @@ -1,6 +1,12 @@ package com.fauna.client; -public final class Stats { +/** + * A class for representing aggregate query stats. This should be used when collecting query stats + * across multiple requests. + *
+ * For a single request, use @link com.fauna.response.QueryStats instead. + */ +public final class QueryStatsSummary { private final long readOps; private final long computeOps; private final long writeOps; @@ -15,7 +21,7 @@ public final class Stats { private final int rateLimitedComputeQueryCount; private final int rateLimitedWriteQueryCount; - public Stats( + public QueryStatsSummary( long readOps, long computeOps, long writeOps, @@ -43,17 +49,75 @@ public Stats( this.rateLimitedWriteQueryCount = rateLimitedWriteQueryCount; } + /** + * Gets the aggregate read ops. + * @return A long representing the aggregate read ops + */ public long getReadOps() { return readOps; } + + /** + * Gets the aggregate compute ops. + * @return A long representing the aggregate compute ops + */ public long getComputeOps() { return computeOps; } + + /** + * Gets the aggregate write ops. + * @return A long representing the aggregate write ops + */ public long getWriteOps() { return writeOps; } + + /** + * Gets the aggregate query time in milliseconds. + * @return A long representing the aggregate query time in milliseconds. + */ public long getQueryTimeMs() { return queryTimeMs; } + + /** + * Gets the count of retries due to contention. + * @return An int representing the count of retries due to contention. + */ public int getContentionRetries() { return contentionRetries; } + + /** + * Gets the aggregate storage bytes read. + * @return A long representing the aggregate number of storage bytes read. + */ public long getStorageBytesRead() { return storageBytesRead; } + + /** + * Gets the aggregate storage bytes written. + * @return A long representing the aggregate number of storage bytes written. + */ public long getStorageBytesWrite() { return storageBytesWrite; } + + /** + * Gets the aggregate processing time in milliseconds. + * @return A long representing the aggregate processing time in milliseconds. + */ public long getProcessingTimeMs() { return processingTimeMs; } + + /** + * Gets the count of queries summarized on this instance. + * @return An int representing the count of queries summarized. + */ public int getQueryCount() { return queryCount; } + /** + * Gets the count of rate limited queries due to read limits. + * @return An int representing the count of rate limited queries. + */ public int getRateLimitedReadQueryCount() { return rateLimitedReadQueryCount; } + + /** + * Gets the count of rate limited queries due to compute limits. + * @return An int representing the count of rate limited queries. + */ public int getRateLimitedComputeQueryCount() { return rateLimitedComputeQueryCount; } + + /** + * Gets the count of rate limited queries due to write limits. + * @return An int representing the count of rate limited queries. + */ public int getRateLimitedWriteQueryCount() { return rateLimitedWriteQueryCount; } } diff --git a/src/main/java/com/fauna/client/StatsCollector.java b/src/main/java/com/fauna/client/StatsCollector.java index c9e90baf..07321c9e 100644 --- a/src/main/java/com/fauna/client/StatsCollector.java +++ b/src/main/java/com/fauna/client/StatsCollector.java @@ -14,11 +14,11 @@ public interface StatsCollector { * Return the collected Stats. * @return Stats object */ - Stats read(); + QueryStatsSummary read(); /** * Return the collected Stats and reset counts. * @return Stats object */ - Stats readAndReset(); + QueryStatsSummary readAndReset(); } diff --git a/src/main/java/com/fauna/client/StatsCollectorImpl.java b/src/main/java/com/fauna/client/StatsCollectorImpl.java index 995a688b..2c8da78d 100644 --- a/src/main/java/com/fauna/client/StatsCollectorImpl.java +++ b/src/main/java/com/fauna/client/StatsCollectorImpl.java @@ -55,8 +55,8 @@ public void add(QueryStats stats) { } @Override - public Stats read() { - return new Stats( + public QueryStatsSummary read() { + return new QueryStatsSummary( readOps.get(), computeOps.get(), writeOps.get(), @@ -73,8 +73,8 @@ public Stats read() { } @Override - public Stats readAndReset() { - return new Stats( + public QueryStatsSummary readAndReset() { + return new QueryStatsSummary( readOps.getAndSet(0), computeOps.getAndSet(0), writeOps.getAndSet(0), diff --git a/src/test/java/com/fauna/client/TestStatsCollectorImpl.java b/src/test/java/com/fauna/client/TestStatsCollectorImpl.java index 7dd96d84..e8036541 100644 --- a/src/test/java/com/fauna/client/TestStatsCollectorImpl.java +++ b/src/test/java/com/fauna/client/TestStatsCollectorImpl.java @@ -36,7 +36,7 @@ public void testAdd_singleQueryStats_updatesCorrectly() { statsCollector.add(stats); // Assert - Stats result = statsCollector.read(); + QueryStatsSummary result = statsCollector.read(); assertEquals(10, result.getComputeOps()); assertEquals(20, result.getReadOps()); assertEquals(5, result.getWriteOps()); @@ -62,7 +62,7 @@ public void testAdd_multipleQueryStats_accumulatesValuesCorrectly() { statsCollector.add(stats2); // Assert - Stats result = statsCollector.read(); + QueryStatsSummary result = statsCollector.read(); assertEquals(25, result.getComputeOps()); assertEquals(45, result.getReadOps()); assertEquals(15, result.getWriteOps()); @@ -80,7 +80,7 @@ public void testAdd_multipleQueryStats_accumulatesValuesCorrectly() { @Test public void testRead_initialStats_returnsZeroStats() { // Act - Stats result = statsCollector.read(); + QueryStatsSummary result = statsCollector.read(); // Assert assertEquals(0, result.getComputeOps()); @@ -106,8 +106,8 @@ public void testReadAndReset_returnsAndResetsStats() { statsCollector.add(stats); // Act - Stats beforeReset = statsCollector.readAndReset(); - Stats afterReset = statsCollector.read(); + QueryStatsSummary beforeReset = statsCollector.readAndReset(); + QueryStatsSummary afterReset = statsCollector.read(); // Assert the stats before reset assertEquals(10, beforeReset.getComputeOps());