ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: # IGNITE-59 Support lock, lockAll. Fix tests.
Date Tue, 20 Jan 2015 10:10:13 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/sprint-1 cbb74d610 -> 286038862


# IGNITE-59 Support lock, lockAll. Fix tests.


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

Branch: refs/heads/sprint-1
Commit: 286038862f5b148315232a7c56ae0430306e2a8e
Parents: cbb74d6
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Tue Jan 20 13:10:07 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Tue Jan 20 13:10:07 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/CacheLockAsyncImpl.java    |  7 ++--
 .../GridCacheMultiNodeLockAbstractTest.java     |  4 +--
 .../GridCacheLocalMultithreadedSelfTest.java    | 35 ++++++--------------
 3 files changed, 15 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28603886/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockAsyncImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockAsyncImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockAsyncImpl.java
index 4b058bd..5005982 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockAsyncImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockAsyncImpl.java
@@ -40,7 +40,7 @@ class CacheLockAsyncImpl<K> implements CacheLock {
     private final Collection<? extends K> keys;
 
     /** Future for previous asynchronous operation. */
-    protected ThreadLocal<IgniteFuture<?>> curFut;
+    protected final ThreadLocal<IgniteFuture<?>> curFut = new ThreadLocal<>();
 
     /**
      * @param delegate Delegate.
@@ -95,10 +95,7 @@ class CacheLockAsyncImpl<K> implements CacheLock {
 
     /** {@inheritDoc} */
     @Override public boolean tryLock(long time, TimeUnit unit) {
-        if (time <= 0)
-            return tryLock();
-
-        IgniteFuture<Boolean> fut = delegate.lockAllAsync(keys, unit.toMillis(time));
+        IgniteFuture<Boolean> fut = delegate.lockAllAsync(keys, time <= 0 ? -1 :
unit.toMillis(time));
 
         curFut.set(fut);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28603886/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheMultiNodeLockAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheMultiNodeLockAbstractTest.java
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheMultiNodeLockAbstractTest.java
index 257d260..1188022 100644
--- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheMultiNodeLockAbstractTest.java
+++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheMultiNodeLockAbstractTest.java
@@ -532,9 +532,9 @@ public abstract class GridCacheMultiNodeLockAbstractTest extends GridCommonAbstr
 
             checkRemoteLocked(cache2, keys1);
 
-            lock2_2.tryLock(-1, TimeUnit.MILLISECONDS);
+            lock2_2.enableAsync().tryLock(-1, TimeUnit.MILLISECONDS);
 
-            IgniteFuture<Boolean> f2 = lock2_2.future();
+            IgniteFuture<Boolean> f2 = lock2_2.enableAsync().future();
 
             assert !f2.get();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/28603886/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/local/GridCacheLocalMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/local/GridCacheLocalMultithreadedSelfTest.java
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/local/GridCacheLocalMultithreadedSelfTest.java
index cc79f38..452dc48 100644
--- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/local/GridCacheLocalMultithreadedSelfTest.java
+++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/local/GridCacheLocalMultithreadedSelfTest.java
@@ -17,6 +17,7 @@
 
 package org.gridgain.grid.kernal.processors.cache.local;
 
+import com.google.common.collect.*;
 import org.apache.ignite.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.lang.*;
@@ -37,7 +38,7 @@ import static org.gridgain.grid.cache.GridCacheMode.*;
  */
 public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest {
     /** Cache. */
-    private GridCache<Integer, String> cache;
+    private IgniteCache<Integer, String> cache;
 
     /**
      * Start grid by default.
@@ -50,7 +51,7 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
     @Override protected void beforeTest() throws Exception {
         Ignite ignite = grid();
 
-        cache = ignite.cache(null);
+        cache = ignite.jcache(null);
     }
 
     /** {@inheritDoc} */
@@ -83,8 +84,6 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
      * @throws Exception If test fails.
      */
     public void testBasicLocks() throws Throwable {
-        final IgniteCache<Object, Object> cache = grid().jcache(null);
-
         GridTestUtils.runMultiThreaded(new Callable<Object>() {
             /** {@inheritDoc} */
             @Override public Object call() throws Exception {
@@ -109,14 +108,10 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
      * @throws Exception If test fails.
      */
     public void testMultiLocks() throws Throwable {
-        final IgniteCache<Integer, String> cache = grid().jcache(null);
-
         GridTestUtils.runMultiThreaded(new Callable<Object>() {
             /** {@inheritDoc} */
             @Override public Object call() throws Exception {
-                Set<Integer> keys = new HashSet<Integer>();
-
-                Collections.addAll(keys, 1, 2, 3);
+                Set<Integer> keys = Sets.newHashSet(1, 2, 3);
 
                 cache.lockAll(keys).lock();
 
@@ -139,8 +134,6 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
      * @throws Exception If test fails.
      */
     public void testSlidingKeysLocks() throws Throwable {
-        final IgniteCache<Integer, String> cache = grid().jcache(null);
-
         final AtomicInteger cnt = new AtomicInteger();
 
         GridTestUtils.runMultiThreaded(new Callable<Object>() {
@@ -148,9 +141,7 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
             @Override public Object call() throws Exception {
                 int idx = cnt.incrementAndGet();
 
-                Set<Integer> keys = new HashSet<>();
-
-                Collections.addAll(keys, idx, idx + 1, idx + 2, idx + 3);
+                Set<Integer> keys = Sets.newHashSet(idx, idx + 1, idx + 2, idx + 3);
 
                 cache.lockAll(keys).lock();
 
@@ -173,8 +164,6 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
      * @throws Exception If test fails.
      */
     public void testSingleLockTimeout() throws Exception {
-        final IgniteCache<Object, Object> cache = grid().jcache(null);
-
         final CountDownLatch l1 = new CountDownLatch(1);
         final CountDownLatch l2 = new CountDownLatch(1);
 
@@ -239,8 +228,6 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
      * @throws Exception If test fails.
      */
     public void testMultiLockTimeout() throws Exception {
-        final IgniteCache<Integer, String> cache = grid().jcache(null);
-
         final CountDownLatch l1 = new CountDownLatch(1);
         final CountDownLatch l2 = new CountDownLatch(1);
         final CountDownLatch l3 = new CountDownLatch(1);
@@ -346,8 +333,6 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
      * @throws Exception If test failed.
      */
     public void testLockOrder() throws Exception {
-        final IgniteCache<Object, Object> cache = grid().jcache(null);
-
         final CountDownLatch l1 = new CountDownLatch(1);
         final CountDownLatch l2 = new CountDownLatch(1);
         final CountDownLatch l3 = new CountDownLatch(1);
@@ -380,9 +365,11 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
                 try {
                     l1.await();
 
-                    CacheLock lock1 = cache.enableAsync().lock(1);
+                    CacheLock lock1 = cache.lock(1);
+
+                    lock1.enableAsync().lock();
 
-                    IgniteFuture<Boolean> f1 = cache.enableAsync().future();
+                    IgniteFuture<Boolean> f1 = lock1.enableAsync().future();
 
                     try {
                         f1.get(100, TimeUnit.MILLISECONDS);
@@ -395,9 +382,9 @@ public class GridCacheLocalMultithreadedSelfTest extends GridCommonAbstractTest
 
                     CacheLock lock2 = cache.lock(2);
 
-                    lock2.lock();
+                    lock2.enableAsync().lock();
 
-                    IgniteFuture<Boolean> f2 = lock2.future();
+                    IgniteFuture<Boolean> f2 = lock2.enableAsync().future();
 
                     try {
                         // Can't acquire f2 because f1 is held.


Mime
View raw message