Skip to content

Commit

Permalink
IGNITE-59 Support lock, lockAll: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sevdokimov-gg committed Jan 15, 2015
1 parent caf8808 commit ea40627
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Expand Up @@ -49,10 +49,10 @@ public abstract class GridCacheLockAbstractTest extends GridCommonAbstractTest {
private static Ignite ignite2; private static Ignite ignite2;


/** (for convenience). */ /** (for convenience). */
private static GridCache<Integer, String> cache1; private static IgniteCache<Integer, String> cache1;


/** (for convenience). */ /** (for convenience). */
private static GridCache<Integer, String> cache2; private static IgniteCache<Integer, String> cache2;


/** Ip-finder. */ /** Ip-finder. */
private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
Expand Down Expand Up @@ -104,8 +104,8 @@ protected GridCacheConfiguration cacheConfiguration() {
ignite1 = startGrid(1); ignite1 = startGrid(1);
ignite2 = startGrid(2); ignite2 = startGrid(2);


cache1 = ignite1.cache(null); cache1 = ignite1.jcache(null);
cache2 = ignite2.cache(null); cache2 = ignite2.jcache(null);
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
Expand All @@ -127,8 +127,8 @@ protected GridCacheConfiguration cacheConfiguration() {


cache2.flagsOn(GridCacheFlag.SYNC_COMMIT).removeAll(); cache2.flagsOn(GridCacheFlag.SYNC_COMMIT).removeAll();


assert cache1.isEmpty() : "Cache is not empty: " + cache1.entrySet(); assert cache1.size() == 0 : "Cache is not empty: " + cache1;
assert cache2.isEmpty() : "Cache is not empty: " + cache2.entrySet(); assert cache2.size() == 0 : "Cache is not empty: " + cache2;
} }


/** /**
Expand Down Expand Up @@ -172,9 +172,6 @@ private boolean locked(Iterable<Integer> keys, int idx) {
*/ */
@SuppressWarnings({"TooBroadScope"}) @SuppressWarnings({"TooBroadScope"})
public void testLockSingleThread() throws Exception { public void testLockSingleThread() throws Exception {
final IgniteCache<Integer, String> cache1 = ignite1.jcache(null);
final IgniteCache<Integer, String> cache2 = ignite1.jcache(null);

int k = 1; int k = 1;
String v = String.valueOf(k); String v = String.valueOf(k);


Expand Down Expand Up @@ -208,9 +205,6 @@ public void testLockSingleThread() throws Exception {
*/ */
@SuppressWarnings({"TooBroadScope"}) @SuppressWarnings({"TooBroadScope"})
public void testLock() throws Exception { public void testLock() throws Exception {
final IgniteCache<Integer, String> cache1 = ignite1.jcache(null);
final IgniteCache<Integer, String> cache2 = ignite1.jcache(null);

final int kv = 1; final int kv = 1;


final CountDownLatch l1 = new CountDownLatch(1); final CountDownLatch l1 = new CountDownLatch(1);
Expand Down Expand Up @@ -299,9 +293,6 @@ public void testLock() throws Exception {
* @throws Exception If test failed. * @throws Exception If test failed.
*/ */
public void testLockAndPut() throws Exception { public void testLockAndPut() throws Exception {
final IgniteCache<Integer, String> cache1 = ignite1.jcache(null);
final IgniteCache<Integer, String> cache2 = ignite1.jcache(null);

final CountDownLatch l1 = new CountDownLatch(1); final CountDownLatch l1 = new CountDownLatch(1);
final CountDownLatch l2 = new CountDownLatch(1); final CountDownLatch l2 = new CountDownLatch(1);


Expand Down Expand Up @@ -388,7 +379,7 @@ public void testLockAndPut() throws Exception {
public void testLockTimeoutTwoThreads() throws Exception { public void testLockTimeoutTwoThreads() throws Exception {
int keyCnt = 1; int keyCnt = 1;


final Collection<Integer> keys = new ArrayList<>(keyCnt); final Set<Integer> keys = new HashSet<>();


for (int i = 1; i <= keyCnt; i++) for (int i = 1; i <= keyCnt; i++)
keys.add(i); keys.add(i);
Expand All @@ -400,7 +391,7 @@ public void testLockTimeoutTwoThreads() throws Exception {
@Nullable @Override public Object call() throws Exception { @Nullable @Override public Object call() throws Exception {
info("Before lock for keys."); info("Before lock for keys.");


assert cache1.lockAll(keys, 0); cache1.lockAll(keys).lock();


info("After lock for keys."); info("After lock for keys.");


Expand Down Expand Up @@ -428,7 +419,7 @@ public void testLockTimeoutTwoThreads() throws Exception {


info("Before unlock keys in thread 1: " + keys); info("Before unlock keys in thread 1: " + keys);


cache1.unlockAll(keys); cache1.lockAll(keys).unlock();


info("Unlocked entry for keys."); info("Unlocked entry for keys.");
} }
Expand All @@ -448,11 +439,11 @@ public void testLockTimeoutTwoThreads() throws Exception {


// This call should not acquire the lock since // This call should not acquire the lock since
// other thread is holding it. // other thread is holding it.
assert !cache1.lockAll(keys, -1); assert !cache1.lockAll(keys).tryLock();


info("Before unlock keys in thread 2: " + keys); info("Before unlock keys in thread 2: " + keys);


cache1.unlockAll(keys); cache1.lockAll(keys).unlock();


// The keys should still be locked. // The keys should still be locked.
for (Integer key : keys) for (Integer key : keys)
Expand Down
Expand Up @@ -70,15 +70,17 @@ public void testLockAtomicCache() throws IgniteCheckedException {


final Ignite g0 = G.start(cfg); final Ignite g0 = G.start(cfg);


final IgniteCache<Object, Object> cache = g0.jcache(null);

GridTestUtils.assertThrows(log, new Callable<Object>() { GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception { @Override public Object call() throws Exception {
return g0.jcache(null).lock(1).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS); return cache.lock(1).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} }
}, IgniteCheckedException.class, "Locks are not supported"); }, IgniteCheckedException.class, "Locks are not supported");


GridTestUtils.assertThrows(log, new Callable<Object>() { GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override public Object call() throws Exception { @Override public Object call() throws Exception {
return g0.cache(null).lockAll(Arrays.asList(1), Long.MAX_VALUE); return cache.lockAll(Collections.singleton(1)).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} }
}, IgniteCheckedException.class, "Locks are not supported"); }, IgniteCheckedException.class, "Locks are not supported");


Expand Down

0 comments on commit ea40627

Please sign in to comment.