Search in sources :

Example 56 with TestHazelcastInstanceFactory

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

the class AtomicLongBackupTest method init.

@Before
public void init() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    instance1 = factory.newHazelcastInstance();
    instance2 = factory.newHazelcastInstance();
    warmUpPartitions(instance1, instance2);
    partitionId = instance1.getPartitionService().getPartition(name).getPartitionId();
    atomicLong = instance1.getAtomicLong(name);
}
Also used : TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Before(org.junit.Before)

Example 57 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 58 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 59 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 60 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)

Aggregations

TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)948 HazelcastInstance (com.hazelcast.core.HazelcastInstance)827 Test (org.junit.Test)774 QuickTest (com.hazelcast.test.annotation.QuickTest)726 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)575 Config (com.hazelcast.config.Config)488 MapConfig (com.hazelcast.config.MapConfig)185 ParallelTest (com.hazelcast.test.annotation.ParallelTest)145 MapStoreConfig (com.hazelcast.config.MapStoreConfig)121 CountDownLatch (java.util.concurrent.CountDownLatch)108 AssertTask (com.hazelcast.test.AssertTask)97 NightlyTest (com.hazelcast.test.annotation.NightlyTest)86 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)81 Before (org.junit.Before)75 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)58 NearCacheConfig (com.hazelcast.config.NearCacheConfig)53 SlowTest (com.hazelcast.test.annotation.SlowTest)53 IndexConfig (com.hazelcast.config.IndexConfig)50 ArrayList (java.util.ArrayList)45 Map (java.util.Map)43