Search in sources :

Example 96 with AssertTask

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());
        }
    });
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) TestThread(com.hazelcast.test.TestThread) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertTask(com.hazelcast.test.AssertTask) ILock(com.hazelcast.core.ILock) ICondition(com.hazelcast.core.ICondition) Test(org.junit.Test)

Example 97 with AssertTask

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 98 with AssertTask

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 99 with AssertTask

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());
}
Also used : Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 100 with AssertTask

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()));
        }
    });
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ExecutionException(java.util.concurrent.ExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

AssertTask (com.hazelcast.test.AssertTask)575 Test (org.junit.Test)489 QuickTest (com.hazelcast.test.annotation.QuickTest)428 ParallelTest (com.hazelcast.test.annotation.ParallelTest)347 HazelcastInstance (com.hazelcast.core.HazelcastInstance)263 Config (com.hazelcast.config.Config)113 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)94 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)75 ExecutionException (java.util.concurrent.ExecutionException)57 MapConfig (com.hazelcast.config.MapConfig)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 IOException (java.io.IOException)46 CountDownLatch (java.util.concurrent.CountDownLatch)42 IMap (com.hazelcast.core.IMap)39 NearCacheConfig (com.hazelcast.config.NearCacheConfig)38 TimeoutException (java.util.concurrent.TimeoutException)33 ClientConfig (com.hazelcast.client.config.ClientConfig)32 MapStoreConfig (com.hazelcast.config.MapStoreConfig)29 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)20