Search in sources :

Example 11 with MultiMap

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

the class ClientMultiMapListenersTest method testListenerOnKeyEntryAddEvent.

@Test
public void testListenerOnKeyEntryAddEvent() throws InterruptedException {
    final Object key = "key";
    final int maxItems = 42;
    final MultiMap mm = client.getMultiMap(randomString());
    MyEntryListener listener = new CountDownValueNotNullListener(maxItems);
    mm.addEntryListener(listener, key, true);
    for (int i = 0; i < maxItems; i++) {
        mm.put(key, i);
    }
    assertOpenEventually(listener.addLatch);
}
Also used : MultiMap(com.hazelcast.core.MultiMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with MultiMap

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

the class ClientMultiMapLockTest method testLockTTL.

@Test
public void testLockTTL() throws Exception {
    final MultiMap mm = client.getMultiMap(randomString());
    final Object key = "Key";
    mm.lock(key, 30, TimeUnit.SECONDS);
    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)

Example 13 with MultiMap

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

the class ClientMultiMapLockTest method testLockTTLExpired_whenLockedBySelf.

@Test
public void testLockTTLExpired_whenLockedBySelf() throws Exception {
    final MultiMap mm = client.getMultiMap(randomString());
    final Object key = "Key";
    mm.lock(key);
    mm.lock(key, 1, TimeUnit.SECONDS);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse(mm.isLocked(key));
        }
    });
}
Also used : MultiMap(com.hazelcast.core.MultiMap) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with MultiMap

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

the class ClientMultiMapLockTest method testTryLockWaitingOnLockedKey_thenKeyUnlockedByOtherThread.

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

        public void run() {
            try {
                if (mm.tryLock(key, 10, TimeUnit.SECONDS)) {
                    tryLockReturnsTrue.countDown();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }.start();
    mm.unlock(key);
    assertOpenEventually(tryLockReturnsTrue);
    assertTrue(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 15 with MultiMap

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

the class ClientMultiMapListenerStressTest method listenerAddStressTest.

@Test
public void listenerAddStressTest() throws InterruptedException {
    final PutItemsThread[] putThreads = new PutItemsThread[NUMBER_OF_CLIENTS * THREADS_PER_CLIENT];
    int idx = 0;
    for (int i = 0; i < NUMBER_OF_CLIENTS; i++) {
        HazelcastInstance client = hazelcastFactory.newHazelcastClient();
        for (int j = 0; j < THREADS_PER_CLIENT; j++) {
            PutItemsThread t = new PutItemsThread(client);
            putThreads[idx++] = t;
        }
    }
    for (int i = 0; i < putThreads.length; i++) {
        putThreads[i].start();
    }
    MultiMap multiMap = server.getMultiMap(MAP_NAME);
    assertJoinable(MAX_SECONDS, putThreads);
    final int expectedSize = PutItemsThread.MAX_ITEMS * putThreads.length;
    assertEquals(expectedSize, multiMap.size());
    assertReceivedEventsSize(expectedSize, putThreads);
}
Also used : MultiMap(com.hazelcast.core.MultiMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

MultiMap (com.hazelcast.core.MultiMap)117 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