shishkovilja commented on code in PR #11512: URL: https://github.com/apache/ignite/pull/11512#discussion_r1819013161
########## modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java: ########## @@ -219,117 +246,39 @@ public void testOptimisticRepeatableReadCheckContentionTxMetricNear() throws Exc private void runKeyCollisionsMetric(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { Ignite ig = startGridsMultiThreaded(3); - int contCnt = (int)U.staticField(IgniteTxManager.class, "COLLISIONS_QUEUE_THRESHOLD") * 5; - - CountDownLatch txLatch = new CountDownLatch(contCnt); + int contCnt = (int)U.staticField(IgniteTxManager.class, "COLLISIONS_QUEUE_THRESHOLD") * 20; ig.cluster().state(ClusterState.ACTIVE); client = true; Ignite cl = startGrid(); - IgniteTransactions cliTxMgr = cl.transactions(); - - IgniteCache<Integer, Integer> cache = ig.cache(DEFAULT_CACHE_NAME); - - IgniteCache<Integer, Integer> cache0 = cl.cache(DEFAULT_CACHE_NAME); - - final Integer keyId = primaryKey(cache); - - CountDownLatch blockOnce = new CountDownLatch(1); - - for (Ignite ig0 : G.allGrids()) { - if (ig0.configuration().isClientMode()) - continue; - - TestRecordingCommunicationSpi commSpi0 = - (TestRecordingCommunicationSpi)ig0.configuration().getCommunicationSpi(); - - commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() { - @Override public boolean apply(ClusterNode node, Message msg) { - if (msg instanceof GridNearTxFinishResponse && blockOnce.getCount() > 0) { - blockOnce.countDown(); - - return true; - } - - return false; - } - }); - } - - IgniteInternalFuture f = GridTestUtils.runAsync(() -> { - try (Transaction tx = cliTxMgr.txStart(concurrency, isolation)) { - cache0.put(keyId, 0); - tx.commit(); - } - }); - - blockOnce.await(); - - GridCompoundFuture<?, ?> finishFut = new GridCompoundFuture<>(); - - for (int i = 0; i < contCnt; ++i) { - IgniteInternalFuture f0 = GridTestUtils.runAsync(() -> { - try (Transaction tx = cliTxMgr.txStart(concurrency, isolation)) { - cache0.put(keyId, 0); - - tx.commit(); - - txLatch.countDown(); - } - }); - - finishFut.add(f0); - } - - finishFut.markInitialized(); - - for (Ignite ig0 : G.allGrids()) { - TestRecordingCommunicationSpi commSpi0 = - (TestRecordingCommunicationSpi)ig0.configuration().getCommunicationSpi(); - - if (ig0.configuration().isClientMode()) - continue; - - commSpi0.stopBlock(); - } - - IgniteTxManager srvTxMgr = ((IgniteEx)ig).context().cache().context().tm(); + IgniteCache<Integer, Integer> cache = cl.cache(DEFAULT_CACHE_NAME); assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { + startTransactions(cl, cache, contCnt, concurrency, isolation); Review Comment: Why should we start transactions in the predicate? ########## modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java: ########## @@ -210,6 +204,39 @@ public void testOptimisticRepeatableReadCheckContentionTxMetricNear() throws Exc runKeyCollisionsMetric(OPTIMISTIC, REPEATABLE_READ); } + /** + * + * @param clientIgnite + * @param cache + * @param contCnt + * @param concurrency + * @param isolation + * @return + */ + private void startTransactions(Ignite clientIgnite, IgniteCache<Integer, Integer> cache, int contCnt, + TransactionConcurrency concurrency, TransactionIsolation isolation) { + ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); Review Comment: Why should we migrate to ExecutorService from runAsync? ########## modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java: ########## @@ -210,6 +204,39 @@ public void testOptimisticRepeatableReadCheckContentionTxMetricNear() throws Exc runKeyCollisionsMetric(OPTIMISTIC, REPEATABLE_READ); } + /** + * + * @param clientIgnite + * @param cache + * @param contCnt + * @param concurrency + * @param isolation + * @return + */ + private void startTransactions(Ignite clientIgnite, IgniteCache<Integer, Integer> cache, int contCnt, + TransactionConcurrency concurrency, TransactionIsolation isolation) { + ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + + for (int i = 0; i < 5; i++) { Review Comment: Magic number. And why 5? Not 2? Not 10? -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org