use of org.apache.ignite.mxbean.CacheMetricsMXBean in project ignite by apache.
the class CacheMetricsManageTest method testTxContentionMetric.
/**
* Test correct metric for tx key contention.
*/
@Test
@WithSystemProperty(key = IGNITE_DUMP_TX_COLLISIONS_INTERVAL, value = "30000")
public void testTxContentionMetric() throws Exception {
Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-9224", MvccFeatureChecker.forcedMvcc());
backups = 1;
useTestCommSpi = true;
Ignite ig = startGridsMultiThreaded(2);
int contCnt = (int) U.staticField(IgniteTxManager.class, "COLLISIONS_QUEUE_THRESHOLD") * 20;
CountDownLatch txLatch = new CountDownLatch(contCnt * 2);
CountDownLatch txLatch0 = new CountDownLatch(contCnt * 2);
ig.cluster().active(true);
client = true;
Ignite cl = startGrid();
CacheConfiguration<?, ?> dfltCacheCfg = getCacheConfiguration();
dfltCacheCfg.setStatisticsEnabled(true);
String cacheName = dfltCacheCfg.getName();
IgniteCache<Integer, Integer> cache = ig.cache(cacheName);
IgniteCache<Integer, Integer> cache0 = cl.cache(cacheName);
CacheMetricsMXBean mxBeanCache = mxBean(0, cacheName, CacheLocalMetricsMXBeanImpl.class);
final List<Integer> priKeys = primaryKeys(cache, 3, 1);
final Integer backKey = backupKey(cache);
IgniteTransactions txMgr = cl.transactions();
CountDownLatch blockOnce = new CountDownLatch(1);
for (Ignite ig0 : G.allGrids()) {
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ig0.configuration().getCommunicationSpi();
commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridNearTxPrepareResponse && blockOnce.getCount() > 0) {
blockOnce.countDown();
return true;
}
return false;
}
});
}
IgniteInternalFuture f = GridTestUtils.runAsync(() -> {
try (Transaction tx = txMgr.txStart(PESSIMISTIC, READ_COMMITTED)) {
cache0.put(priKeys.get(0), 0);
cache0.put(priKeys.get(2), 0);
tx.commit();
}
});
blockOnce.await();
GridCompoundFuture<?, ?> finishFut = new GridCompoundFuture<>();
for (int i = 0; i < contCnt; ++i) {
IgniteInternalFuture f0 = GridTestUtils.runAsync(() -> {
try (Transaction tx = txMgr.txStart(PESSIMISTIC, READ_COMMITTED)) {
cache0.put(priKeys.get(0), 0);
cache0.put(priKeys.get(1), 0);
txLatch0.countDown();
tx.commit();
txLatch.countDown();
}
try (Transaction tx = txMgr.txStart(PESSIMISTIC, READ_COMMITTED)) {
cache0.put(priKeys.get(2), 0);
cache0.put(backKey, 0);
txLatch0.countDown();
tx.commit();
txLatch.countDown();
}
});
finishFut.add(f0);
}
finishFut.markInitialized();
txLatch0.await();
for (Ignite ig0 : G.allGrids()) {
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ig0.configuration().getCommunicationSpi();
commSpi0.stopBlock();
}
IgniteTxManager txManager = ((IgniteEx) ig).context().cache().context().tm();
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
U.invoke(IgniteTxManager.class, txManager, "collectTxCollisionsInfo");
} catch (IgniteCheckedException e) {
fail(e.toString());
}
String coll = mxBeanCache.getTxKeyCollisions();
if (coll.contains("val=" + priKeys.get(2)) || coll.contains("val=" + priKeys.get(0)))
;
return true;
}
}, 10_000));
f.get();
finishFut.get();
txLatch.await();
}
Aggregations