Search in sources :

Example 71 with MultiMap

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

the class ClientMultiMapListenersTest method testListeners_clearAllFromNode.

@Test
public void testListeners_clearAllFromNode() {
    final String name = randomString();
    final MultiMap mm = client.getMultiMap(name);
    MyEntryListener listener = new CountDownValueNullListener(1);
    mm.addEntryListener(listener, false);
    mm.put("key", "value");
    server.getMultiMap(name).clear();
    assertOpenEventually(listener.addLatch);
    assertOpenEventually(listener.clearLatch);
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with MultiMap

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

the class ClientMultiMapListenersTest method testListenerEntryAddEvent.

@Test
public void testListenerEntryAddEvent() throws InterruptedException {
    final int maxKeys = 12;
    final int maxItems = 3;
    final MultiMap mm = client.getMultiMap(randomString());
    MyEntryListener listener = new CountDownValueNotNullListener(maxKeys * maxItems);
    mm.addEntryListener(listener, true);
    for (int i = 0; i < maxKeys; i++) {
        for (int j = 0; j < maxKeys; j++) {
            mm.put(i, j);
        }
    }
    assertOpenEventually(listener.addLatch);
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 73 with MultiMap

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

the class ClientMultiMapLockTest method testIsLocked_whenNotLocked.

@Test
public void testIsLocked_whenNotLocked() {
    final MultiMap mm = client.getMultiMap(randomString());
    final Object key = "KeyNotLocked";
    final boolean result = mm.isLocked(key);
    assertFalse(result);
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with MultiMap

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

the class ClientMultiMapLockTest method testLockTTLExpires_thenOtherThreadCanObtain.

@Test
public void testLockTTLExpires_thenOtherThreadCanObtain() {
    final MultiMap mm = client.getMultiMap(randomString());
    final Object key = "Key";
    mm.lock(key, 2, TimeUnit.SECONDS);
    final CountDownLatch tryLockSuccess = new CountDownLatch(1);
    new Thread() {

        public void run() {
            try {
                if (mm.tryLock(key, 10, TimeUnit.SECONDS)) {
                    tryLockSuccess.countDown();
                }
            } catch (InterruptedException e) {
                fail(e.getMessage());
            }
        }
    }.start();
    assertOpenEventually(tryLockSuccess);
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 75 with MultiMap

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

the class ClientMultiMapLockTest method testTryLockLeaseTime_lockIsReleasedEventually.

@Test
public void testTryLockLeaseTime_lockIsReleasedEventually() throws InterruptedException {
    final MultiMap multiMap = getMultiMapForLock();
    final String key = randomString();
    multiMap.tryLock(key, 1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            Assert.assertFalse(multiMap.isLocked(key));
        }
    }, 30);
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MultiMap (com.hazelcast.multimap.MultiMap)93 Test (org.junit.Test)93 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)92 QuickTest (com.hazelcast.test.annotation.QuickTest)92 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)11 TransactionContext (com.hazelcast.transaction.TransactionContext)8 TransactionalMultiMap (com.hazelcast.transaction.TransactionalMultiMap)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 Collection (java.util.Collection)6 Set (java.util.Set)5 TreeSet (java.util.TreeSet)5 AssertTask (com.hazelcast.test.AssertTask)4 UUID (java.util.UUID)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 EntryAdapter (com.hazelcast.core.EntryAdapter)2 EntryEvent (com.hazelcast.core.EntryEvent)2 EntryListener (com.hazelcast.core.EntryListener)2 ArrayList (java.util.ArrayList)2 ClientConnectionRegistration (com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration)1 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)1