IGNITE-59 Support lock, lockAll. Make async oprtations work via 
IgniteAsyncSupport.


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

Branch: refs/heads/ignite-54
Commit: cbb74d610a42083fb220e2171eddfe99be19502d
Parents: 9b3cd61
Author: sevdokimov <sevdoki...@gridgain.com>
Authored: Mon Jan 19 21:19:54 2015 +0300
Committer: sevdokimov <sevdoki...@gridgain.com>
Committed: Mon Jan 19 21:19:54 2015 +0300

----------------------------------------------------------------------
 .../main/java/org/apache/ignite/CacheLock.java  |  45 ++----
 .../processors/cache/CacheLockAsyncImpl.java    | 144 +++++++++++++++++++
 .../processors/cache/CacheLockImpl.java         |  36 +++--
 .../cache/GridCacheAbstractFullApiSelfTest.java |  55 ++++---
 .../GridCacheMultiNodeLockAbstractTest.java     |  58 +++++---
 .../dht/GridCacheColocatedDebugTest.java        |  16 ++-
 .../near/GridCachePartitionedLockSelfTest.java  |  15 +-
 .../GridCacheLocalMultithreadedSelfTest.java    |  24 ++--
 8 files changed, 281 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/modules/core/src/main/java/org/apache/ignite/CacheLock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/CacheLock.java 
b/modules/core/src/main/java/org/apache/ignite/CacheLock.java
index 9be14e0..f395261 100644
--- a/modules/core/src/main/java/org/apache/ignite/CacheLock.java
+++ b/modules/core/src/main/java/org/apache/ignite/CacheLock.java
@@ -18,8 +18,6 @@
 package org.apache.ignite;
 
 import org.apache.ignite.lang.*;
-import org.apache.ignite.transactions.*;
-import org.gridgain.grid.cache.*;
 
 import java.util.concurrent.*;
 import java.util.concurrent.locks.*;
@@ -27,7 +25,7 @@ import java.util.concurrent.locks.*;
 /**
  * Lock associated with some cache keys.
  */
-public interface CacheLock extends Lock {
+public interface CacheLock extends Lock, IgniteAsyncSupport {
     /**
      * Checks if any node holds lock on at least one key associated with this 
{@code CacheLock}.
      * <p>
@@ -50,37 +48,14 @@ public interface CacheLock extends Lock {
      */
     public boolean isLockedByThread();
 
-    /**
-     * Asynchronously acquires lock on a cached object with keys associated 
with this {@code CacheLock}.
-     * <h2 class="header">Transactions</h2>
-     * Locks are not transactional and should not be used from within 
transactions. If you do
-     * need explicit locking within transaction, then you should use
-     * {@link IgniteTxConcurrency#PESSIMISTIC} concurrency control for 
transaction
-     * which will acquire explicit locks for relevant cache operations.
-     * <h2 class="header">Cache Flags</h2>
-     * This method is not available if any of the following flags are set on 
projection:
-     * {@link GridCacheFlag#LOCAL}, {@link GridCacheFlag#READ}.
-     *
-     * @return Future for the lock operation. The future will return {@code 
true}.
-     */
-    public IgniteFuture<Boolean> lockAsync();
+    /** {@inheritDoc} */
+    @IgniteAsyncSupported
+    @Override public void lock();
 
-    /**
-     * Asynchronously acquires lock on a cached object with given keys 
associated with this {@code CacheLock}.
-     * <h2 class="header">Transactions</h2>
-     * Locks are not transactional and should not be used from within 
transactions. If you do
-     * need explicit locking within transaction, then you should use
-     * {@link IgniteTxConcurrency#PESSIMISTIC} concurrency control for 
transaction
-     * which will acquire explicit locks for relevant cache operations.
-     * <h2 class="header">Cache Flags</h2>
-     * This method is not available if any of the following flags are set on 
projection:
-     * {@link GridCacheFlag#LOCAL}, {@link GridCacheFlag#READ}.
-     *
-     * @param timeout The maximum time to wait for the lock. If the time is 
less than or equal to zero, the method will
-     *      not wait at all.
-     * @param unit The time unit of the {@code timeout} argument.
-     * @return Future for the lock operation. The future will return {@code 
true} whenever locks are acquired before
-     *      timeout is expired, {@code false} otherwise.
-     */
-    public IgniteFuture<Boolean> lockAsync(long timeout, TimeUnit unit);
+    /** {@inheritDoc} */
+    @IgniteAsyncSupported
+    @Override public boolean tryLock(long time, TimeUnit unit) throws 
InterruptedException;
+
+    /** {@inheritDoc} */
+    @Override public CacheLock enableAsync();
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/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
new file mode 100644
index 0000000..4b058bd
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockAsyncImpl.java
@@ -0,0 +1,144 @@
+/*
+ * 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;
+
+import org.apache.ignite.*;
+import org.apache.ignite.lang.*;
+import org.gridgain.grid.*;
+import org.gridgain.grid.kernal.processors.cache.*;
+import org.jetbrains.annotations.*;
+
+import javax.cache.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.locks.*;
+
+/**
+ *
+ * @param <K>
+ */
+class CacheLockAsyncImpl<K> implements CacheLock {
+    /** */
+    private final GridCacheProjectionEx<K, ?> delegate;
+
+    /** */
+    private final Collection<? extends K> keys;
+
+    /** Future for previous asynchronous operation. */
+    protected ThreadLocal<IgniteFuture<?>> curFut;
+
+    /**
+     * @param delegate Delegate.
+     * @param keys Keys.
+     */
+    CacheLockAsyncImpl(GridCacheProjectionEx<K, ?> delegate, Collection<? 
extends K> keys) {
+        this.delegate = delegate;
+        this.keys = keys;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isLocked() {
+        for (K key : keys) {
+            if (!delegate.isLocked(key))
+                return false;
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isLockedByThread() {
+        for (K key : keys) {
+            if (!delegate.isLockedByThread(key))
+                return false;
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lock() {
+        IgniteFuture<Boolean> fut = delegate.lockAllAsync(keys, 0);
+
+        curFut.set(fut);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lockInterruptibly() throws InterruptedException {
+        tryLock(-1, TimeUnit.MILLISECONDS);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean tryLock() {
+        try {
+            return delegate.lockAll(keys, -1);
+        }
+        catch (IgniteCheckedException e) {
+            throw new CacheException(e.getMessage(), e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean tryLock(long time, TimeUnit unit) {
+        if (time <= 0)
+            return tryLock();
+
+        IgniteFuture<Boolean> fut = delegate.lockAllAsync(keys, 
unit.toMillis(time));
+
+        curFut.set(fut);
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlock() {
+        try {
+            delegate.unlockAll(keys);
+        }
+        catch (IgniteCheckedException e) {
+            throw new CacheException(e.getMessage(), e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @NotNull @Override public Condition newCondition() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheLock enableAsync() {
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isAsync() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <R> IgniteFuture<R> future() {
+        IgniteFuture<?> fut = curFut.get();
+
+        if (fut == null)
+            throw new IllegalStateException("Asynchronous operation not 
started.");
+
+        curFut.set(null);
+
+        return (IgniteFuture<R>)fut;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
index f60b157..e80c7f8 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
@@ -39,6 +39,9 @@ class CacheLockImpl<K> implements CacheLock {
     /** */
     private final Collection<? extends K> keys;
 
+    /** */
+    private volatile CacheLockAsyncImpl<K> async;
+
     /**
      * @param delegate Delegate.
      * @param keys Keys.
@@ -69,16 +72,6 @@ class CacheLockImpl<K> implements CacheLock {
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteFuture<Boolean> lockAsync() {
-        return delegate.lockAllAsync(keys, 0);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteFuture<Boolean> lockAsync(long timeout, TimeUnit 
unit) {
-        return delegate.lockAllAsync(keys, unit.toMillis(timeout));
-    }
-
-    /** {@inheritDoc} */
     @Override public void lock() {
         try {
             delegate.lockAll(keys, 0);
@@ -157,4 +150,27 @@ class CacheLockImpl<K> implements CacheLock {
     @NotNull @Override public Condition newCondition() {
         throw new UnsupportedOperationException();
     }
+
+    /** {@inheritDoc} */
+    @Override public CacheLock enableAsync() {
+        CacheLockAsyncImpl<K> async = this.async;
+
+        if (async == null) {
+            async = new CacheLockAsyncImpl<>(delegate, keys);
+
+            this.async = async;
+        }
+
+        return async;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isAsync() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <R> IgniteFuture<R> future() {
+        throw new IllegalStateException("Asynchronous mode is not enabled.");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
 
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
index 2fb802b..57f9c59 100644
--- 
a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
+++ 
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
@@ -3346,23 +3346,28 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
     @SuppressWarnings("BusyWait")
     public void testLockAsync() throws Exception {
         if (lockingEnabled()) {
-            cache().put("key", 1);
+            IgniteCache<String, Integer> cache = jcache();
+
+            CacheLock lock = cache.lock("key");
+
+            cache.put("key", 1);
 
-            assert !cache().isLocked("key");
+            assert !lock.isLocked();
 
-            cache().lockAsync("key", 0).get();
+            lock.enableAsync().lock();
+            lock.enableAsync().future().get();
 
-            assert cache().isLocked("key");
+            assert lock.isLocked();
 
-            cache().unlock("key");
+            lock.unlock();
 
             for (int i = 0; i < 100; i++)
-                if (cache().isLocked("key"))
+                if (lock.isLocked())
                     Thread.sleep(10);
                 else
                     break;
 
-            assert !cache().isLocked("key");
+            assert !cache.isLocked("key");
         }
     }
 
@@ -3456,23 +3461,29 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
     @SuppressWarnings("BusyWait")
     public void testLockAsyncWithTimeout() throws Exception {
         if (lockingEnabled()) {
-            cache().put("key", 1);
+            final IgniteCache<String, Integer> cache = jcache();
 
-            assert !cache().isLocked("key");
+            cache.put("key", 1);
 
-            cache().lockAsync("key", 1000).get();
+            final CacheLock lock = cache.lock("key");
 
-            assert cache().isLocked("key");
-            assert cache().isLockedByThread("key");
+            assert !cache.isLocked("key");
+
+            lock.enableAsync().tryLock(1000, MILLISECONDS);
+            lock.enableAsync().future().get();
+
+            assert cache.isLocked("key");
+            assert cache.isLockedByThread("key");
 
             final CountDownLatch latch = new CountDownLatch(1);
 
             IgniteCompute comp = forLocal(dfltIgnite).enableAsync();
 
             comp.call(new Callable<Boolean>() {
-                @Override
-                public Boolean call() throws Exception {
-                    IgniteFuture<Boolean> f = cache().lockAsync("key", 1000);
+                @Override public Boolean call() throws Exception {
+                    lock.enableAsync().tryLock(1000, MILLISECONDS);
+
+                    IgniteFuture<Boolean> f = lock.enableAsync().future();
 
                     try {
                         f.get(100);
@@ -3487,7 +3498,7 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
                     try {
                         assert f.get();
                     } finally {
-                        cache().unlock("key");
+                        lock.unlock();
                     }
 
                     return true;
@@ -3499,21 +3510,21 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
                 // Let another thread start.
             latch.await();
 
-            assert cache().isLocked("key");
-            assert cache().isLockedByThread("key");
+            assert cache.isLocked("key");
+            assert cache.isLockedByThread("key");
 
-            cache().unlock("key");
+            lock.unlock();
 
             assert f.get();
 
             for (int i = 0; i < 100; i++)
-                if (cache().isLocked("key") || cache().isLockedByThread("key"))
+                if (cache.isLocked("key") || cache.isLockedByThread("key"))
                     Thread.sleep(10);
                 else
                     break;
 
-            assert !cache().isLocked("key");
-            assert !cache().isLockedByThread("key");
+            assert !cache.isLocked("key");
+            assert !cache.isLockedByThread("key");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/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 1374be2..257d260 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
@@ -17,6 +17,7 @@
 
 package org.gridgain.grid.kernal.processors.cache.distributed;
 
+import com.google.common.collect.*;
 import org.apache.ignite.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
@@ -375,10 +376,15 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
      * @throws Exception If test fails.
      */
     public void testMultiNodeLockAsync() throws Exception {
-        GridCache<Integer, String> cache1 = ignite1.cache(null);
-        GridCache<Integer, String> cache2 = ignite2.cache(null);
+        IgniteCache<Integer, String> cache1 = ignite1.jcache(null);
+        IgniteCache<Integer, String> cache2 = ignite2.jcache(null);
+
+        CacheLock lock1_1 = cache1.lock(1);
+        CacheLock lock2_1 = cache2.lock(1);
+
+        lock1_1.enableAsync().lock();
 
-        assert cache1.lockAsync(1, 0L).get();
+        assert lock1_1.enableAsync().<Boolean>future().get();
 
         try {
             assert cache1.isLocked(1);
@@ -387,15 +393,17 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
             assert cache2.isLocked(1);
             assert !cache2.isLockedByThread(1);
 
-            assert !cache2.lockAsync(1, -1L).get();
+            lock2_1.enableAsync().tryLock(-1, TimeUnit.MILLISECONDS);
+
+            assert !lock2_1.enableAsync().<Boolean>future().get();
         }
         finally {
-            cache1.unlockAll(F.asList(1));
+            lock1_1.unlock();
         }
 
         checkUnlocked(cache1, 1);
 
-        assert cache2.lockAsync(1, 0L).get();
+        lock2_1.lock();
 
         CountDownLatch latch = new CountDownLatch(1);
 
@@ -408,10 +416,12 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
             assert cache2.isLocked(1);
             assert cache2.isLockedByThread(1);
 
-            assert !cache1.lockAsync(1, -1L).get();
+            lock1_1.enableAsync().tryLock(-1, TimeUnit.MILLISECONDS);
+
+            assert !lock1_1.enableAsync().<Boolean>future().get();
         }
         finally {
-            cache2.unlockAll(F.asList(1));
+            lock2_1.unlock();
         }
 
         latch.await();
@@ -502,16 +512,18 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
      * @throws Exception If test fails.
      */
     public void testMultiNodeLockAsyncWithKeyLists() throws Exception {
-        GridCache<Integer, String> cache1 = ignite1.cache(null);
-        GridCache<Integer, String> cache2 = ignite2.cache(null);
+        IgniteCache<Integer, String> cache1 = ignite1.jcache(null);
+        IgniteCache<Integer, String> cache2 = ignite2.jcache(null);
 
-        Collection<Integer> keys1 = new ArrayList<>();
-        Collection<Integer> keys2 = new ArrayList<>();
+        Collection<Integer> keys1 = Lists.newArrayList(1, 2, 3);
+        Collection<Integer> keys2 = Lists.newArrayList(2, 3, 4);
 
-        Collections.addAll(keys1, 1, 2, 3);
-        Collections.addAll(keys2, 2, 3, 4);
+        CacheLock lock1_1 = cache1.lockAll(keys1);
+        CacheLock lock2_2 = cache2.lockAll(keys2);
+
+        lock1_1.enableAsync().lock();
 
-        IgniteFuture<Boolean> f1 = cache1.lockAllAsync(keys1, 0);
+        IgniteFuture<Boolean> f1 = lock1_1.enableAsync().future();
 
         try {
             assert f1.get();
@@ -520,7 +532,9 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
 
             checkRemoteLocked(cache2, keys1);
 
-            IgniteFuture<Boolean> f2 = cache2.lockAllAsync(keys2, -1);
+            lock2_2.tryLock(-1, TimeUnit.MILLISECONDS);
+
+            IgniteFuture<Boolean> f2 = lock2_2.future();
 
             assert !f2.get();
 
@@ -532,7 +546,7 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
             checkRemoteLocked(cache2, keys1);
         }
         finally {
-            cache1.unlockAll(keys1);
+            lock1_1.unlock();
         }
 
         checkUnlocked(cache1, keys1);
@@ -541,7 +555,9 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
 
         addListener(ignite1, new UnlockListener(latch, keys2));
 
-        IgniteFuture<Boolean> f2 = cache2.lockAllAsync(keys2, 0);
+        lock2_2.enableAsync().lock();
+
+        IgniteFuture<Boolean> f2 = lock2_2.enableAsync().future();
 
         try {
             assert f2.get();
@@ -552,9 +568,7 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
 
             checkUnlocked(cache1, 1);
 
-            f1 = cache1.lockAllAsync(keys2, -1);
-
-            assert !f1.get();
+            assert !cache1.lockAll(keys2).tryLock();
 
             checkLocked(cache2, keys2);
 
@@ -564,7 +578,7 @@ public abstract class GridCacheMultiNodeLockAbstractTest 
extends GridCommonAbstr
             checkRemoteLocked(cache1, keys2);
         }
         finally {
-            cache2.unlockAll(keys2);
+            lock2_2.unlock();
         }
 
         latch.await();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridCacheColocatedDebugTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridCacheColocatedDebugTest.java
 
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridCacheColocatedDebugTest.java
index acc565c..1b6209d 100644
--- 
a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridCacheColocatedDebugTest.java
+++ 
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/dht/GridCacheColocatedDebugTest.java
@@ -372,7 +372,9 @@ public class GridCacheColocatedDebugTest extends 
GridCommonAbstractTest {
             IgniteFuture<?> unlockFut = multithreadedAsync(new Runnable() {
                 @Override public void run() {
                     try {
-                        assert g0.cache(null).lock(key, 0);
+                        CacheLock lock = g0.jcache(null).lock(key);
+
+                        lock.lock();
 
                         try {
                             lockLatch.countDown();
@@ -380,7 +382,7 @@ public class GridCacheColocatedDebugTest extends 
GridCommonAbstractTest {
                             U.await(unlockLatch);
                         }
                         finally {
-                            g0.cache(null).unlock(key);
+                            lock.unlock();
                         }
                     }
                     catch (IgniteCheckedException e) {
@@ -392,10 +394,14 @@ public class GridCacheColocatedDebugTest extends 
GridCommonAbstractTest {
 
             U.await(lockLatch);
 
-            assert g0.cache(null).isLocked(key);
-            assert !g0.cache(null).isLockedByThread(key) : "Key can not be 
locked by current thread.";
+            assert g0.jcache(null).isLocked(key);
+            assert !g0.jcache(null).isLockedByThread(key) : "Key can not be 
locked by current thread.";
+
+            CacheLock lock = g0.jcache(null).lock(key);
+
+            lock.enableAsync().lock();
 
-            IgniteFuture<Boolean> lockFut = g0.cache(null).lockAsync(key, 0);
+            IgniteFuture<Boolean> lockFut = lock.enableAsync().future();
 
             assert g0.cache(null).isLocked(key);
             assert !lockFut.isDone() : "Key can not be locked by current 
thread.";

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java
 
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java
index a0be693..3df071b 100644
--- 
a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java
+++ 
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java
@@ -62,7 +62,7 @@ public class GridCachePartitionedLockSelfTest extends 
GridCacheLockAbstractTest
     /**
      * @throws IgniteCheckedException If failed.
      */
-    public void testLockAtomicCache() throws IgniteCheckedException {
+    public void testLockAtomicCache() throws Exception {
         IgniteConfiguration cfg = new IgniteConfiguration();
 
         cfg.setGridName(getTestGridName(0));
@@ -85,21 +85,16 @@ public class GridCachePartitionedLockSelfTest extends 
GridCacheLockAbstractTest
             }
         }, CacheException.class, "Locks are not supported");
 
-        final IgniteFuture<Boolean> lockFut1 = g0.cache(null).lockAsync(1, 
Long.MAX_VALUE);
+        CacheLock lock = g0.jcache(null).lock(1);
 
-        GridTestUtils.assertThrows(log, new Callable<Object>() {
-            @Override public Object call() throws Exception {
-                return lockFut1.get();
-            }
-        }, IgniteCheckedException.class, "Locks are not supported");
+        lock.enableAsync().tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
 
-        final IgniteFuture<Boolean> lockFut2 = 
g0.cache(null).lockAllAsync(Arrays.asList(1), Long.MAX_VALUE);
+        final IgniteFuture<Boolean> lockFut1 = lock.enableAsync().future();
 
         GridTestUtils.assertThrows(log, new Callable<Object>() {
             @Override public Object call() throws Exception {
-                return lockFut2.get();
+                return lockFut1.get();
             }
         }, IgniteCheckedException.class, "Locks are not supported");
-
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cbb74d61/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 624c5be..cc79f38 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
@@ -346,6 +346,8 @@ 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);
@@ -353,7 +355,7 @@ public class GridCacheLocalMultithreadedSelfTest extends 
GridCommonAbstractTest
         Thread t1 = new GridTestThread(new Callable<Object>() {
             /** {@inheritDoc} */
             @Override public Object call() throws Exception {
-                assert cache.lock(1, 0L);
+                cache.lock(1).lock();
 
                 l1.countDown();
 
@@ -362,7 +364,7 @@ public class GridCacheLocalMultithreadedSelfTest extends 
GridCommonAbstractTest
 
                 l2.await();
 
-                cache.unlock(1);
+                cache.lock(1).unlock();
 
                 l3.countDown();
 
@@ -378,7 +380,9 @@ public class GridCacheLocalMultithreadedSelfTest extends 
GridCommonAbstractTest
                 try {
                     l1.await();
 
-                    IgniteFuture<Boolean> f1 = cache.lockAsync(1, 0L);
+                    CacheLock lock1 = cache.enableAsync().lock(1);
+
+                    IgniteFuture<Boolean> f1 = cache.enableAsync().future();
 
                     try {
                         f1.get(100, TimeUnit.MILLISECONDS);
@@ -389,7 +393,11 @@ public class GridCacheLocalMultithreadedSelfTest extends 
GridCommonAbstractTest
                         info("Correctly received timeout exception: " + e);
                     }
 
-                    IgniteFuture<Boolean> f2 = cache.lockAsync(2, 0L);
+                    CacheLock lock2 = cache.lock(2);
+
+                    lock2.lock();
+
+                    IgniteFuture<Boolean> f2 = lock2.future();
 
                     try {
                         // Can't acquire f2 because f1 is held.
@@ -402,8 +410,8 @@ public class GridCacheLocalMultithreadedSelfTest extends 
GridCommonAbstractTest
                         info("Correctly received timeout exception: " + e);
                     }
 
-                    assert cache.isLocked(1);
-                    assert !cache.isLockedByThread(1);
+                    assert lock1.isLocked();
+                    assert !lock1.isLockedByThread();
 
                     // TODO uncomment after GG-3756 fix
                     //assert cache.isLocked(2);
@@ -423,8 +431,8 @@ public class GridCacheLocalMultithreadedSelfTest extends 
GridCommonAbstractTest
                     assert cache.isLocked(2);
                     assert cache.isLockedByThread(2);
 
-                    cache.unlock(1);
-                    cache.unlock(2);
+                    lock1.unlock();
+                    lock2.unlock();
 
                     assert !cache.isLocked(1);
                     assert !cache.isLockedByThread(1);

Reply via email to