burmanm commented on a change in pull request #1372:
URL: https://github.com/apache/cassandra/pull/1372#discussion_r785164931
##########
File path: test/unit/org/apache/cassandra/db/virtual/BatchMetricsTableTest.java
##########
@@ -49,42 +47,45 @@ public static void setUpClass()
@Before
public void config()
{
- table = new BatchMetricsTable(KS_NAME);
+ BatchMetricsTable table = new BatchMetricsTable(KS_NAME);
VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME,
ImmutableList.of(table)));
}
@Test
- void testSelectAll() throws Throwable
+ public void testSelectAll() throws Throwable
{
- String ks = createKeyspace("CREATE KEYSPACE %s WITH replication={
'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
- String tbl = createTable(ks, "CREATE TABLE %s (id int primary key, val
int)");
+ BatchMetrics metrics = BatchStatement.metrics;
- String batch = format("BEGIN BATCH " +
- "INSERT INTO %s.%s (id, val) VALUES (0, 0) USING
TTL %d; " +
- "INSERT INTO %s.%s (id, val) VALUES (1, 1) USING
TTL %d; " +
- "APPLY BATCH;",
- ks, tbl, 1,
- ks, tbl, 1);
- execute(batch);
+ for (int i = 0; i < 10; i++)
+ {
+ metrics.partitionsPerLoggedBatch.update(i);
+ metrics.partitionsPerUnloggedBatch.update(i + 10);
+ metrics.partitionsPerCounterBatch.update(i * 10);
+ }
- BatchMetrics metrics = BatchStatement.metrics;
- ResultSet result = executeNet("SELECT * FROM vts.batch_metrics");
+ ResultSet result = executeNet(format("SELECT * FROM %s.batch_metrics",
KS_NAME));
assertEquals(5, result.getColumnDefinitions().size());
AtomicInteger rowCount = new AtomicInteger(0);
result.forEach(r -> {
- Snapshot snapshot;
- if(r.getString("name").equals("partitions_per_logged_batch")) {
- snapshot = metrics.partitionsPerLoggedBatch.getSnapshot();
- } else
if(r.getString("name").equals("partitions_per_unlogged_batch")) {
- snapshot = metrics.partitionsPerUnloggedBatch.getSnapshot();
- } else {
- snapshot = metrics.partitionsPerCounterBatch.getSnapshot();
- }
- assertEquals(r.getDouble("p50"), snapshot.getMedian(), 1.0);
- assertEquals(r.getDouble("p99"), snapshot.get99thPercentile(),
1.0);
+ Snapshot snapshot = getExpectedHistogramSnapshot(metrics,
r.getString("name"));
+ assertEquals(snapshot.getMedian(), r.getDouble("p50th"), 0.0);
+ assertEquals(snapshot.get99thPercentile(), r.getDouble("p99th"),
0.0);
rowCount.addAndGet(1);
});
assertEquals(3, rowCount.get());
}
+
+ private Snapshot getExpectedHistogramSnapshot(BatchMetrics metrics, String
tableName)
+ {
+ if ("partitions_per_logged_batch".equals(tableName))
+ {
+ return metrics.partitionsPerLoggedBatch.getSnapshot();
+ }
+ else if ("partitions_per_unlogged_batch".equals(tableName))
Review comment:
I see both approaches used in the code base, I'm personally on the
"else" camp usually - to me it makes it easier to follow the flow, with the
added bonus of being able to hide the whole conditional flow in the editor with
a single click (does not matter in this case, but in general).
--
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]