use of org.apache.ignite.cache.query.QueryDetailMetrics in project ignite by apache.
the class CacheAbstractQueryDetailMetricsSelfTest method testQueryMetricsEviction.
/**
* Test metrics eviction.
*
* @throws Exception In case of error.
*/
public void testQueryMetricsEviction() throws Exception {
IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A");
// Execute several DIFFERENT queries with guaranteed DIFFERENT time of execution.
cache.query(new SqlFieldsQuery("select * from String")).getAll();
Thread.sleep(100);
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
Thread.sleep(100);
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
Thread.sleep(100);
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
Thread.sleep(100);
cache.query(new ScanQuery()).getAll();
Thread.sleep(100);
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
// Check that collected metrics contains correct items: metrics for last 3 queries.
Collection<? extends QueryDetailMetrics> metrics = cache.queryDetailMetrics();
String lastMetrics = "";
for (QueryDetailMetrics m : metrics) lastMetrics += m.queryType() + " " + m.query() + ";";
assertTrue(lastMetrics.contains("SQL_FIELDS select * from String limit 2;"));
assertTrue(lastMetrics.contains("SCAN A;"));
assertTrue(lastMetrics.contains("SQL from String;"));
cache = grid(0).context().cache().jcache("B");
cache.query(new SqlFieldsQuery("select * from String")).getAll();
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
cache.query(new ScanQuery()).getAll();
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
if (gridCnt > 1) {
cache = grid(1).context().cache().jcache("A");
cache.query(new SqlFieldsQuery("select * from String")).getAll();
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
cache.query(new ScanQuery()).getAll();
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
cache = grid(1).context().cache().jcache("B");
cache.query(new SqlFieldsQuery("select * from String")).getAll();
cache.query(new SqlFieldsQuery("select count(*) from String")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 1")).getAll();
cache.query(new SqlFieldsQuery("select * from String limit 2")).getAll();
cache.query(new ScanQuery()).getAll();
cache.query(new SqlQuery("String", "from String")).getAll();
waitingFor(cache, "size", QRY_DETAIL_METRICS_SIZE);
for (int i = 0; i < QRY_DETAIL_METRICS_SIZE; i++) checkMetrics(cache, QRY_DETAIL_METRICS_SIZE, i, 1, 1, 0, false);
}
}
use of org.apache.ignite.cache.query.QueryDetailMetrics in project ignite by apache.
the class CacheAbstractQueryDetailMetricsSelfTest method checkMetrics.
/**
* Check metrics.
*
* @param cache Cache to check metrics.
* @param sz Expected size of metrics.
* @param idx Index of metrics to check.
* @param execs Expected number of executions.
* @param completions Expected number of completions.
* @param failures Expected number of failures.
* @param first {@code true} if metrics checked for first query only.
*/
private void checkMetrics(IgniteCache<Integer, String> cache, int sz, int idx, int execs, int completions, int failures, boolean first) {
Collection<? extends QueryDetailMetrics> metrics = cache.queryDetailMetrics();
assertNotNull(metrics);
assertEquals(sz, metrics.size());
QueryDetailMetrics m = new ArrayList<>(metrics).get(idx);
info("Metrics: " + m);
assertEquals("Executions", execs, m.executions());
assertEquals("Completions", completions, m.completions());
assertEquals("Failures", failures, m.failures());
assertTrue(m.averageTime() >= 0);
assertTrue(m.maximumTime() >= 0);
assertTrue(m.minimumTime() >= 0);
if (first)
assertTrue("On first execution minTime == maxTime", m.minimumTime() == m.maximumTime());
}
Aggregations