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);
}
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));
}
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));
}
});
}
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));
}
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);
}
Aggregations