use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class IdGeneratorStressTest method setup.
@Before
public void setup() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
instances = factory.newInstances();
name = randomString();
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class SemaphoreAdvancedTest method testSemaphoreWithFailuresAndJoin.
@Test(timeout = 300000)
public void testSemaphoreWithFailuresAndJoin() {
final String semaphoreName = randomString();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
final HazelcastInstance instance1 = factory.newHazelcastInstance();
final HazelcastInstance instance2 = factory.newHazelcastInstance();
final ISemaphore semaphore = instance1.getSemaphore(semaphoreName);
final CountDownLatch countDownLatch = new CountDownLatch(1);
assertTrue(semaphore.init(0));
final Thread thread = new Thread() {
public void run() {
for (int i = 0; i < 2; i++) {
try {
semaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
countDownLatch.countDown();
}
};
thread.start();
instance2.shutdown();
semaphore.release();
HazelcastInstance instance3 = factory.newHazelcastInstance();
ISemaphore semaphore1 = instance3.getSemaphore(semaphoreName);
semaphore1.release();
try {
assertTrue(countDownLatch.await(15, TimeUnit.SECONDS));
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
thread.interrupt();
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CacheConfigTest method testGetPreConfiguredCache.
@Test
public void testGetPreConfiguredCache() {
Config config = new Config();
config.addCacheConfig(new CacheSimpleConfig().setName("test"));
int count = 4;
TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(count);
for (int i = 0; i < count; i++) {
HazelcastInstance instance = factory.newHazelcastInstance(config);
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(instance);
CacheManager cacheManager = provider.getCacheManager();
Cache<Object, Object> cache = cacheManager.getCache("test");
assertNotNull("Pre-configured cache cannot be retrieved on instance: " + i, cache);
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class AtomicLongAdvancedTest method testAtomicLongSpawnNodeInParallel.
@Test
public void testAtomicLongSpawnNodeInParallel() throws InterruptedException {
int total = 6;
int parallel = 2;
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(total + 1);
HazelcastInstance instance = nodeFactory.newHazelcastInstance();
final String name = "testAtomicLongSpawnNodeInParallel";
IAtomicLong atomicLong = instance.getAtomicLong(name);
atomicLong.set(100);
final ExecutorService ex = Executors.newFixedThreadPool(parallel);
try {
for (int i = 0; i < total / parallel; i++) {
final HazelcastInstance[] instances = new HazelcastInstance[parallel];
final CountDownLatch countDownLatch = new CountDownLatch(parallel);
final AtomicInteger exceptionCount = new AtomicInteger(0);
for (int j = 0; j < parallel; j++) {
final int id = j;
ex.execute(new Runnable() {
public void run() {
try {
instances[id] = nodeFactory.newHazelcastInstance();
instances[id].getAtomicLong(name).incrementAndGet();
} catch (Exception e) {
exceptionCount.incrementAndGet();
e.printStackTrace();
} finally {
countDownLatch.countDown();
}
}
});
}
assertOpenEventually(countDownLatch);
waitAllForSafeState(nodeFactory.getAllHazelcastInstances());
// if there is an exception while incrementing in parallel threads, find number of exceptions
// and subtract the number from expectedValue.
final int thrownExceptionCount = exceptionCount.get();
final long expectedValue = (long) 100 + (i + 1) * parallel - thrownExceptionCount;
IAtomicLong newAtomicLong = instance.getAtomicLong(name);
assertEquals(expectedValue, newAtomicLong.get());
instance.shutdown();
instance = instances[0];
}
} finally {
ex.shutdownNow();
}
}
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);
}
Aggregations