ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [43/50] incubator-ignite git commit: # ignite-sprint-4 added test
Date Wed, 29 Apr 2015 13:15:03 GMT
# ignite-sprint-4 added test


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7d9df3d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7d9df3d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7d9df3d4

Branch: refs/heads/ignite-786
Commit: 7d9df3d43a3bfe89021784654ae4e0283c54af94
Parents: acc731c
Author: sboikov <sboikov@gridgain.com>
Authored: Wed Apr 29 09:30:49 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Wed Apr 29 09:31:35 2015 +0300

----------------------------------------------------------------------
 .../distributed/GridCacheLockAbstractTest.java  | 70 ++++++++++++++++++++
 1 file changed, 70 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7d9df3d4/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
index 257f88a..72a64a1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheLockAbstractTest.java
@@ -31,6 +31,7 @@ import org.jetbrains.annotations.*;
 import javax.cache.*;
 import java.util.*;
 import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
 import java.util.concurrent.locks.*;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.*;
@@ -494,4 +495,73 @@ public abstract class GridCacheLockAbstractTest extends GridCommonAbstractTest
{
         fut1.get();
         fut2.get();
     }
+
+    /**
+     * @throws Throwable If failed.
+     */
+    public void testLockReentrancy() throws Throwable {
+        fail("https://issues.apache.org/jira/browse/IGNITE-835");
+
+        for (int i = 10; i < 100; i++) {
+            log.info("Key: " + i);
+
+            final int i0 = i;
+
+            final Lock lock = cache1.lock(i);
+
+            lock.lockInterruptibly();
+
+            try {
+                final AtomicReference<Throwable> err = new AtomicReference<>();
+
+                Thread t =  new Thread(new Runnable() {
+                    @Override public void run() {
+                        try {
+                            assert !lock.tryLock();
+                            assert !lock.tryLock(100, TimeUnit.MILLISECONDS);
+
+                            assert !cache1.lock(i0).tryLock();
+                            assert !cache1.lock(i0).tryLock(100, TimeUnit.MILLISECONDS);
+                        }
+                        catch (Throwable e) {
+                            err.set(e);
+                        }
+                    }
+                });
+
+                t.start();
+                t.join();
+
+                if (err.get() != null)
+                    throw err.get();
+
+                lock.lock();
+                lock.unlock();
+
+                t =  new Thread(new Runnable() {
+                    @Override public void run() {
+                        try {
+                            assert !lock.tryLock();
+                            assert !lock.tryLock(100, TimeUnit.MILLISECONDS);
+
+                            assert !cache1.lock(i0).tryLock();
+                            assert !cache1.lock(i0).tryLock(100, TimeUnit.MILLISECONDS);
+                        }
+                        catch (Throwable e) {
+                            err.set(e);
+                        }
+                    }
+                });
+
+                t.start();
+                t.join();
+
+                if (err.get() != null)
+                    throw err.get();
+            }
+            finally {
+                lock.unlock();
+            }
+        }
+    }
 }


Mime
View raw message