use of org.apache.ignite.GridTestTask in project ignite by apache.
the class ClusterNodeMetricsSelfTest method testSingleTaskMetrics.
/**
* @throws Exception If failed.
*/
public void testSingleTaskMetrics() throws Exception {
Ignite ignite = grid();
final CountDownLatch taskLatch = new CountDownLatch(2);
ignite.compute().executeAsync(new GridTestTask(taskLatch), "testArg");
// Let metrics update twice.
final CountDownLatch latch = new CountDownLatch(3);
ignite.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt.type() == EVT_NODE_METRICS_UPDATED;
latch.countDown();
taskLatch.countDown();
return true;
}
}, EVT_NODE_METRICS_UPDATED);
// Wait for metrics update.
latch.await();
ClusterMetrics metrics = ignite.cluster().localNode().metrics();
info("Node metrics: " + metrics);
assert metrics.getAverageActiveJobs() > 0;
assert metrics.getAverageCancelledJobs() == 0;
assert metrics.getAverageJobExecuteTime() >= 0;
assert metrics.getAverageJobWaitTime() >= 0;
assert metrics.getAverageRejectedJobs() == 0;
assert metrics.getAverageWaitingJobs() == 0;
assert metrics.getCurrentActiveJobs() == 0;
assert metrics.getCurrentCancelledJobs() == 0;
assert metrics.getCurrentJobExecuteTime() > 0;
assert metrics.getCurrentJobWaitTime() == 0;
assert metrics.getCurrentWaitingJobs() == 0;
assert metrics.getMaximumActiveJobs() == 1;
assert metrics.getMaximumCancelledJobs() == 0;
assert metrics.getMaximumJobExecuteTime() >= 0;
assert metrics.getMaximumJobWaitTime() >= 0;
assert metrics.getMaximumRejectedJobs() == 0;
assert metrics.getMaximumWaitingJobs() == 0;
assert metrics.getTotalCancelledJobs() == 0;
assert metrics.getTotalExecutedJobs() == 1;
assert metrics.getTotalRejectedJobs() == 0;
assert metrics.getTotalExecutedTasks() == 1;
assertTrue("MaximumJobExecuteTime=" + metrics.getMaximumJobExecuteTime() + " is less than AverageJobExecuteTime=" + metrics.getAverageJobExecuteTime(), metrics.getMaximumJobExecuteTime() >= metrics.getAverageJobExecuteTime());
}
use of org.apache.ignite.GridTestTask in project ignite by apache.
the class ClusterMetricsSelfTest method performTaskExecutionTest.
/**
* @throws Exception In case of error.
*/
private void performTaskExecutionTest() throws Exception {
Ignite g = grid(0);
JobFinishLock jobFinishLock = new JobFinishLock();
MetricsUpdateLock metricsUpdLock = new MetricsUpdateLock();
try {
for (Ignite g0 : G.allGrids()) g0.events().localListen(jobFinishLock, EVT_JOB_FINISHED);
g.compute().execute(new GridTestTask(), "testArg");
// Wait until all nodes fire JOB FINISH event.
jobFinishLock.await();
g.events().localListen(metricsUpdLock, EVT_NODE_METRICS_UPDATED);
// Wait until local node will have updated metrics.
metricsUpdLock.await();
ClusterMetrics m = g.cluster().metrics();
checkMetrics(m);
} finally {
for (Ignite g0 : G.allGrids()) g0.events().stopLocalListen(jobFinishLock);
g.events().stopLocalListen(metricsUpdLock);
}
}
Aggregations