shishkovilja commented on code in PR #11512:
URL: https://github.com/apache/ignite/pull/11512#discussion_r1826574921


##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java:
##########
@@ -216,68 +199,35 @@ public void 
testOptimisticRepeatableReadCheckContentionTxMetricNear() throws Exc
      * @param isolation Isolation level.
      * @throws Exception If failed.
      */
-    private void runKeyCollisionsMetric(TransactionConcurrency concurrency, 
TransactionIsolation isolation) throws Exception {
+    private void runKeyCollisionsMetric(TransactionConcurrency concurrency, 
TransactionIsolation isolation, boolean nearCashe)
+            throws Exception {
         Ignite ig = startGridsMultiThreaded(3);
 
         int contCnt = (int)U.staticField(IgniteTxManager.class, 
"COLLISIONS_QUEUE_THRESHOLD") * 5;
 
-        CountDownLatch txLatch = new CountDownLatch(contCnt);
-
         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;
-                }
-            });
-        }
+        IgniteCache<Integer, Integer> cache = (IgniteCache<Integer, Integer>)
+                cl.getOrCreateCache(getCacheConfiguration(DEFAULT_CACHE_NAME, 
nearCashe));
 
-        IgniteInternalFuture f = GridTestUtils.runAsync(() -> {
-            try (Transaction tx = cliTxMgr.txStart(concurrency, isolation)) {
-                cache0.put(keyId, 0);
-                tx.commit();
-            }
-        });
-
-        blockOnce.await();
+        IgniteTransactions transactions = cl.transactions();
 
         GridCompoundFuture<?, ?> finishFut = new GridCompoundFuture<>();
 
+        AtomicBoolean doTest = new AtomicBoolean(true);
+
         for (int i = 0; i < contCnt; ++i) {

Review Comment:
   Replace with `GridTestUtils#runMultithreadedAsync`.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java:
##########
@@ -216,68 +199,35 @@ public void 
testOptimisticRepeatableReadCheckContentionTxMetricNear() throws Exc
      * @param isolation Isolation level.
      * @throws Exception If failed.
      */
-    private void runKeyCollisionsMetric(TransactionConcurrency concurrency, 
TransactionIsolation isolation) throws Exception {
+    private void runKeyCollisionsMetric(TransactionConcurrency concurrency, 
TransactionIsolation isolation, boolean nearCashe)
+            throws Exception {
         Ignite ig = startGridsMultiThreaded(3);
 
         int contCnt = (int)U.staticField(IgniteTxManager.class, 
"COLLISIONS_QUEUE_THRESHOLD") * 5;
 
-        CountDownLatch txLatch = new CountDownLatch(contCnt);
-
         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);

Review Comment:
   We have to ensure, that key is primary for node. So, we can not remove it.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java:
##########
@@ -286,50 +236,31 @@ private void 
runKeyCollisionsMetric(TransactionConcurrency concurrency, Transact
 
         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();

Review Comment:
   Unnecessary edit.



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java:
##########
@@ -216,68 +199,35 @@ public void 
testOptimisticRepeatableReadCheckContentionTxMetricNear() throws Exc
      * @param isolation Isolation level.
      * @throws Exception If failed.
      */
-    private void runKeyCollisionsMetric(TransactionConcurrency concurrency, 
TransactionIsolation isolation) throws Exception {
+    private void runKeyCollisionsMetric(TransactionConcurrency concurrency, 
TransactionIsolation isolation, boolean nearCashe)
+            throws Exception {
         Ignite ig = startGridsMultiThreaded(3);
 
         int contCnt = (int)U.staticField(IgniteTxManager.class, 
"COLLISIONS_QUEUE_THRESHOLD") * 5;
 
-        CountDownLatch txLatch = new CountDownLatch(contCnt);
-
         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;
-                }
-            });
-        }
+        IgniteCache<Integer, Integer> cache = (IgniteCache<Integer, Integer>)
+                cl.getOrCreateCache(getCacheConfiguration(DEFAULT_CACHE_NAME, 
nearCashe));

Review Comment:
   1. Fix generics and remove redundant classcast.
   2. Is it necessary to pass constant cache name as argument?



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxWithKeyContentionSelfTest.java:
##########
@@ -286,50 +236,31 @@ private void 
runKeyCollisionsMetric(TransactionConcurrency concurrency, Transact
 
         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();
-
         assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
             @Override public boolean apply() {
                 try {

Review Comment:
   This try catch is actually useless, because exception is propagated to main 
thread. I suggest to add try-finally statement, with futures finishing in 
finally block.



-- 
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

Reply via email to