use of org.apache.accumulo.test.metrics.TestStatsDSink.Metric in project accumulo by apache.
the class ExternalCompactionMetricsIT method testMetrics.
@Test
public void testMetrics() throws Exception {
Collection<ProcessReference> tservers = ((MiniAccumuloClusterImpl) getCluster()).getProcesses().get(ServerType.TABLET_SERVER);
assertEquals(2, tservers.size());
// kill one tserver so that queue metrics are not spread across tservers
((MiniAccumuloClusterImpl) getCluster()).killProcess(TABLET_SERVER, tservers.iterator().next());
String[] names = getUniqueNames(2);
try (final AccumuloClient client = Accumulo.newClient().from(getCluster().getClientProperties()).build()) {
String table1 = names[0];
createTable(client, table1, "cs1", 5);
String table2 = names[1];
createTable(client, table2, "cs2", 10);
writeData(client, table1);
writeData(client, table2);
final LinkedBlockingQueue<Metric> queueMetrics = new LinkedBlockingQueue<>();
final AtomicBoolean shutdownTailer = new AtomicBoolean(false);
Thread thread = Threads.createThread("metric-tailer", () -> {
while (!shutdownTailer.get()) {
List<String> statsDMetrics = sink.getLines();
for (String s : statsDMetrics) {
if (shutdownTailer.get()) {
break;
}
if (s.startsWith(MetricsProducer.METRICS_MAJC_QUEUED)) {
queueMetrics.add(TestStatsDSink.parseStatsDMetric(s));
}
}
}
});
thread.start();
compact(client, table1, 7, "DCQ1", false);
compact(client, table2, 13, "DCQ2", false);
boolean sawDCQ1_5 = false;
boolean sawDCQ2_10 = false;
// wait until expected number of queued are seen in metrics
while (!sawDCQ1_5 || !sawDCQ2_10) {
Metric qm = queueMetrics.take();
sawDCQ1_5 |= match(qm, "DCQ1", "5");
sawDCQ2_10 |= match(qm, "DCQ2", "10");
}
cluster.getClusterControl().startCompactors(Compactor.class, 1, QUEUE1);
cluster.getClusterControl().startCompactors(Compactor.class, 1, QUEUE2);
cluster.getClusterControl().startCoordinator(CompactionCoordinator.class);
boolean sawDCQ1_0 = false;
boolean sawDCQ2_0 = false;
// wait until queued goes to zero in metrics
while (!sawDCQ1_0 || !sawDCQ2_0) {
Metric qm = queueMetrics.take();
sawDCQ1_0 |= match(qm, "DCQ1", "0");
sawDCQ2_0 |= match(qm, "DCQ2", "0");
}
shutdownTailer.set(true);
thread.join();
// Wait for all external compactions to complete
long count;
do {
UtilWaitThread.sleep(100);
try (TabletsMetadata tm = getCluster().getServerContext().getAmple().readTablets().forLevel(DataLevel.USER).fetch(ColumnType.ECOMP).build()) {
count = tm.stream().flatMap(t -> t.getExternalCompactions().keySet().stream()).count();
}
} while (count > 0);
verify(client, table1, 7);
verify(client, table2, 13);
} finally {
// We stopped the TServer and started our own, restart the original TabletServers
// Uncomment this if other tests are added.
//
// cluster.getClusterControl().start(ServerType.TABLET_SERVER);
}
}
Aggregations