Search in sources :

Example 41 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class AtomicReferenceMigrationTest method testMultipleAtomicReferences.

@Test
public void testMultipleAtomicReferences() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    SimpleObject object = new SimpleObject(1);
    for (int i = 0; i < 100; i++) {
        IAtomicReference<SimpleObject> reference = instance1.getAtomicReference("test" + i);
        reference.set(object);
    }
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    warmUpPartitions(instance1, instance2);
    for (int i = 0; i < 100; i++) {
        IAtomicReference<SimpleObject> reference = instance2.getAtomicReference("test" + i);
        assertEquals(object, reference.get());
    }
    HazelcastInstance instance3 = factory.newHazelcastInstance();
    warmUpPartitions(instance1, instance2, instance3);
    for (int i = 0; i < 100; i++) {
        IAtomicReference<SimpleObject> reference = instance3.getAtomicReference("test" + i);
        assertEquals(object, reference.get());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class AtomicReferenceMigrationTest method testWhenInstancesShutdown.

@Test
public void testWhenInstancesShutdown() {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    IAtomicReference<SimpleObject> reference1 = instance1.getAtomicReference("test");
    SimpleObject object = new SimpleObject(1);
    reference1.set(object);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    instance1.shutdown();
    IAtomicReference<SimpleObject> reference2 = instance2.getAtomicReference("test");
    SimpleObject objectTest1 = reference2.get();
    assertEquals(object, objectTest1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 43 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class CountDownLatchAdvancedTest method testSimpleUsage.

@Test
public void testSimpleUsage() throws InterruptedException {
    final int k = 5;
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances();
    ICountDownLatch latch = instances[0].getCountDownLatch("test");
    latch.trySetCount(k - 1);
    assertEquals(k - 1, latch.getCount());
    new Thread() {

        public void run() {
            for (int i = 1; i < k; i++) {
                try {
                    sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                final ICountDownLatch l = instances[i].getCountDownLatch("test");
                l.countDown();
                assertEquals(k - 1 - i, l.getCount());
            }
        }
    }.start();
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
    assertEquals(0, latch.getCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TestThread(com.hazelcast.test.TestThread) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 44 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class ConditionAdvancedTest method testShutDownNode_whenOtherWaitingOnConditionAwait.

@Test(timeout = 60000, expected = HazelcastInstanceNotActiveException.class)
public void testShutDownNode_whenOtherWaitingOnConditionAwait() throws InterruptedException {
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    final HazelcastInstance instance = nodeFactory.newHazelcastInstance();
    nodeFactory.newHazelcastInstance();
    final String name = randomString();
    final ILock lock = instance.getLock(name);
    final ICondition condition = lock.newCondition("condition");
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            try {
                latch.await(1, TimeUnit.MINUTES);
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            instance.shutdown();
        }
    }).start();
    lock.lock();
    try {
        latch.countDown();
        condition.await();
    } catch (InterruptedException e) {
    }
    lock.unlock();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ILock(com.hazelcast.core.ILock) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ICondition(com.hazelcast.core.ICondition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 45 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class ConditionAdvancedTest method testDestroyLock_whenOtherWaitingOnConditionAwait.

@Test(timeout = 60000, expected = DistributedObjectDestroyedException.class)
public void testDestroyLock_whenOtherWaitingOnConditionAwait() throws InterruptedException {
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    final HazelcastInstance instance = nodeFactory.newHazelcastInstance();
    final ILock lock = instance.getLock(randomString());
    final ICondition condition = lock.newCondition("condition");
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            try {
                latch.await(30, TimeUnit.SECONDS);
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lock.destroy();
        }
    }).start();
    lock.lock();
    latch.countDown();
    condition.await();
    lock.unlock();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ILock(com.hazelcast.core.ILock) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ICondition(com.hazelcast.core.ICondition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)743 HazelcastInstance (com.hazelcast.core.HazelcastInstance)665 Test (org.junit.Test)632 QuickTest (com.hazelcast.test.annotation.QuickTest)618 ParallelTest (com.hazelcast.test.annotation.ParallelTest)598 Config (com.hazelcast.config.Config)361 MapConfig (com.hazelcast.config.MapConfig)146 MapStoreConfig (com.hazelcast.config.MapStoreConfig)101 CountDownLatch (java.util.concurrent.CountDownLatch)99 AssertTask (com.hazelcast.test.AssertTask)94 NightlyTest (com.hazelcast.test.annotation.NightlyTest)70 IMap (com.hazelcast.core.IMap)65 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)62 MapIndexConfig (com.hazelcast.config.MapIndexConfig)51 TransactionException (com.hazelcast.transaction.TransactionException)46 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43 Member (com.hazelcast.core.Member)41 NearCacheConfig (com.hazelcast.config.NearCacheConfig)40 Map (java.util.Map)38 Before (org.junit.Before)35