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