Search in sources :

Example 46 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapLockTest method testUnlock_whenLockedByOther.

@Test(expected = IllegalMonitorStateException.class)
public void testUnlock_whenLockedByOther() throws Exception {
    final MultiMap mm = client.getMultiMap(randomString());
    final Object key = "key";
    mm.lock(key);
    UnLockThread t = new UnLockThread(mm, key);
    t.start();
    assertJoinable(t);
    throw t.exception;
}
Also used : MultiMap(com.hazelcast.core.MultiMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 47 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapLockTest method testForceUnlock_whenKeyLockedByOther.

@Test
public void testForceUnlock_whenKeyLockedByOther() throws Exception {
    final MultiMap mm = client.getMultiMap(randomString());
    final Object key = "key";
    mm.lock(key);
    final CountDownLatch forceUnlock = new CountDownLatch(1);
    new Thread() {

        public void run() {
            mm.forceUnlock(key);
            forceUnlock.countDown();
        }
    }.start();
    assertOpenEventually(forceUnlock);
    assertFalse(mm.isLocked(key));
}
Also used : MultiMap(com.hazelcast.core.MultiMap) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 48 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapLockTest method testTryLockLeaseTime_whenLockAcquiredByOther.

@Test(timeout = 60000)
public void testTryLockLeaseTime_whenLockAcquiredByOther() throws InterruptedException {
    final MultiMap multiMap = getMultiMapForLock();
    final String key = randomString();
    Thread thread = new Thread() {

        public void run() {
            multiMap.lock(key);
        }
    };
    thread.start();
    thread.join();
    boolean isLocked = multiMap.tryLock(key, 1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
    Assert.assertFalse(isLocked);
}
Also used : MultiMap(com.hazelcast.core.MultiMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 49 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapLockTest method testUnlock_whenNotLocked.

@Test(expected = IllegalMonitorStateException.class)
public void testUnlock_whenNotLocked() throws Exception {
    final MultiMap mm = client.getMultiMap(randomString());
    mm.unlock("NOT_LOCKED");
}
Also used : MultiMap(com.hazelcast.core.MultiMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 50 with MultiMap

use of com.hazelcast.core.MultiMap in project hazelcast by hazelcast.

the class ClientMultiMapLockTest method testUnlock_whenRentrantlyLockedBySelf.

@Test
public void testUnlock_whenRentrantlyLockedBySelf() throws Exception {
    final MultiMap mm = client.getMultiMap(randomString());
    final Object key = "key";
    mm.lock(key);
    mm.lock(key);
    mm.unlock(key);
    assertTrue(mm.isLocked(key));
}
Also used : MultiMap(com.hazelcast.core.MultiMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MultiMap (com.hazelcast.core.MultiMap)118 Test (org.junit.Test)117 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)106 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)12 Map (java.util.Map)11 Config (com.hazelcast.config.Config)9 TransactionalMultiMap (com.hazelcast.core.TransactionalMultiMap)9 JobTracker (com.hazelcast.mapreduce.JobTracker)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 HashMap (java.util.HashMap)9 TransactionContext (com.hazelcast.transaction.TransactionContext)8 SlowTest (com.hazelcast.test.annotation.SlowTest)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AssertTask (com.hazelcast.test.AssertTask)5 Collection (java.util.Collection)5 List (java.util.List)5 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4