You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/01/28 11:03:24 UTC

[GitHub] AMashenkov commented on a change in pull request #5896: IGNITE-11029: Public API for edge-chasing deadlock detection configuration

AMashenkov commented on a change in pull request #5896: IGNITE-11029: Public API for edge-chasing deadlock detection configuration
URL: https://github.com/apache/ignite/pull/5896#discussion_r251368718
 
 

 ##########
 File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/MvccDeadlockDetectionConfigTest.java
 ##########
 @@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.mvcc;
+
+import java.util.concurrent.CyclicBarrier;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.TransactionConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
+import org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/** */
+@RunWith(JUnit4.class)
+public class MvccDeadlockDetectionConfigTest extends GridCommonAbstractTest  {
+    /** */
+    private boolean deadlockDetectionEnabled;
+
+    /** */
+    @After
+    public void stopCluster() {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        int timeout = deadlockDetectionEnabled ? 1 : 0;
+
+        return super.getConfiguration(igniteInstanceName)
+            .setTransactionConfiguration(new TransactionConfiguration().setDeadlockTimeout(timeout));
+    }
+
+    /** */
+    @Test
+    public void deadlockDetectionDisabled() throws Exception {
+        deadlockDetectionEnabled = false;
+
+        Ignite ign = startGrid();
+
+        IgniteCache<Object, Object> cache = ign.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+            .setAtomicityMode(TRANSACTIONAL_SNAPSHOT));
+
+        CyclicBarrier b = new CyclicBarrier(2);
+
+        int txTimeout = 3_000;
+
+        IgniteInternalFuture<?> futA = GridTestUtils.runAsync(() -> {
+            try (Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, txTimeout, 0)) {
+                cache.put(1, 'a');
+                b.await();
+                cache.put(2, 'a');
+            }
+
+            return null;
+        });
+
+        IgniteInternalFuture<?> futB = GridTestUtils.runAsync(() -> {
+            try (Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, txTimeout, 0)) {
+                cache.put(2, 'b');
+                b.await();
+                cache.put(1, 'b');
+            }
+
+            return null;
+        });
+
+        IgniteCheckedException e = awaitCompletion(futA, futB);
+
+        assertTrue(e.toString(), e.hasCause(IgniteTxTimeoutCheckedException.class));
+    }
+
+    /** */
+    @Test
+    public void deadlockDetectionEnabled() throws Exception {
+        deadlockDetectionEnabled = true;
+
+        Ignite ign = startGrid();
+
+        IgniteCache<Object, Object> cache = ign.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+            .setAtomicityMode(TRANSACTIONAL_SNAPSHOT));
+
+        CyclicBarrier b = new CyclicBarrier(2);
+
+        IgniteInternalFuture<?> futA = GridTestUtils.runAsync(() -> {
+            try (Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                cache.put(1, 'a');
+                b.await();
+                cache.put(2, 'a');
+            }
+
+            return null;
+        });
+
+        IgniteInternalFuture<?> futB = GridTestUtils.runAsync(() -> {
+            try (Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                cache.put(2, 'b');
+                b.await();
+                cache.put(1, 'b');
+            }
+
+            return null;
+        });
+
+        IgniteCheckedException e = awaitCompletion(futA, futB);
+
+        assertTrue(e.toString(), e.hasCause(IgniteTxRollbackCheckedException.class));
 
 Review comment:
   Should we check if any DeadLock exception occurs here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services