use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ConditionAbstractTest method testAwaitExpiration_whenLockIsNotAcquired.
@Test
public void testAwaitExpiration_whenLockIsNotAcquired() throws InterruptedException {
String lockName = newName();
String conditionName = newName();
final ILock lock = callerInstance.getLock(lockName);
final ICondition condition = lock.newCondition(conditionName);
final AtomicInteger expires = new AtomicInteger(0);
final int awaitCount = 10;
final CountDownLatch awaitLatch = new CountDownLatch(awaitCount);
for (int i = 0; i < awaitCount; i++) {
new Thread(new Runnable() {
public void run() {
try {
lock.lock();
awaitLatch.countDown();
boolean signalled = condition.await(1, TimeUnit.SECONDS);
assertFalse(signalled);
expires.incrementAndGet();
} catch (InterruptedException ignored) {
} finally {
lock.unlock();
}
}
}).start();
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(awaitCount, expires.get());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class HazelcastInstanceFactoryTest method testTestHazelcastInstanceFactory_withTwoFactories.
@Test
public void testTestHazelcastInstanceFactory_withTwoFactories() {
TestHazelcastInstanceFactory instanceFactory1 = new TestHazelcastInstanceFactory();
TestHazelcastInstanceFactory instanceFactory2 = new TestHazelcastInstanceFactory();
try {
final HazelcastInstance instance11 = instanceFactory1.newHazelcastInstance();
final HazelcastInstance instance12 = instanceFactory1.newHazelcastInstance();
final HazelcastInstance instance13 = instanceFactory1.newHazelcastInstance();
final HazelcastInstance instance21 = instanceFactory2.newHazelcastInstance();
final HazelcastInstance instance22 = instanceFactory2.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, instance21.getCluster().getMembers().size());
assertEquals(2, instance22.getCluster().getMembers().size());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(3, instance11.getCluster().getMembers().size());
assertEquals(3, instance12.getCluster().getMembers().size());
assertEquals(3, instance13.getCluster().getMembers().size());
}
});
} finally {
instanceFactory1.terminateAll();
instanceFactory2.terminateAll();
}
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class HazelcastInstanceFactoryTest method testTestHazelcastInstanceFactory.
@Test
public void testTestHazelcastInstanceFactory() {
TestHazelcastInstanceFactory instanceFactory = new TestHazelcastInstanceFactory();
try {
final HazelcastInstance instance1 = instanceFactory.newHazelcastInstance();
final HazelcastInstance instance2 = instanceFactory.newHazelcastInstance();
final HazelcastInstance instance3 = instanceFactory.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(3, instance1.getCluster().getMembers().size());
assertEquals(3, instance2.getCluster().getMembers().size());
assertEquals(3, instance3.getCluster().getMembers().size());
}
});
} finally {
instanceFactory.terminateAll();
}
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class DistributedExecutorServiceTest method testExecutorConfigCache_whenUsedExecutorShutdown_thenConfigRemoved.
@Test
public void testExecutorConfigCache_whenUsedExecutorShutdown_thenConfigRemoved() throws Exception {
final IExecutorService executorService = hz.getExecutorService(EXECUTOR_NAME);
Future future = executorService.submit(new EmptyRunnable());
future.get();
executorService.shutdown();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(executorService.isShutdown());
}
});
assertTrue("Executor config cache should not contain cached configuration for executor that was already shutdown", distributedExecutorService.executorConfigCache.isEmpty());
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ExecutorServiceLiteMemberTest method test_executeRunnable_onAllLiteMembers.
@Test
public void test_executeRunnable_onAllLiteMembers() {
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
final HazelcastInstance other = factory.newHazelcastInstance();
final String name = randomString();
final IExecutorService executor = other.getExecutorService(name);
executor.executeOnMembers(new ResultSettingRunnable(name), LITE_MEMBER_SELECTOR);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final IMap<Object, Object> results = lite1.getMap(name);
assertEquals(2, results.size());
assertTrue(results.containsKey(lite1.getCluster().getLocalMember()));
assertTrue(results.containsKey(lite2.getCluster().getLocalMember()));
}
});
}
Aggregations