use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CacheFromDifferentNodesTest method init.
@Before
public void init() {
factory = new TestHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(hz1);
cachingProvider2 = HazelcastServerCachingProvider.createCachingProvider(hz2);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CacheListenerTest method getCachingProvider.
protected CachingProvider getCachingProvider() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
warmUpPartitions(hz1, hz2);
waitAllForSafeState(hz1, hz2);
hazelcastInstance = hz1;
return HazelcastServerCachingProvider.createCachingProvider(hazelcastInstance);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CardinalityEstimatorAdvancedTest method testCardinalityEstimatorSpawnNodeInParallel.
@Test
public void testCardinalityEstimatorSpawnNodeInParallel() {
int total = 6;
int parallel = 2;
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(total + 1);
HazelcastInstance instance = nodeFactory.newHazelcastInstance();
final String name = "testSpawnNodeInParallel";
CardinalityEstimator estimator = instance.getCardinalityEstimator(name);
estimator.add(1L);
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 counter = new AtomicInteger(0);
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 {
counter.incrementAndGet();
instances[id] = nodeFactory.newHazelcastInstance();
instances[id].getCardinalityEstimator(name).add(String.valueOf(counter.get()));
} catch (Exception e) {
exceptionCount.incrementAndGet();
e.printStackTrace();
} finally {
countDownLatch.countDown();
}
}
});
}
assertOpenEventually(countDownLatch);
// 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) counter.get() - thrownExceptionCount;
CardinalityEstimator newEstimator = instance.getCardinalityEstimator(name);
assertEquals(expectedValue, newEstimator.estimate());
instance.shutdown();
instance = instances[0];
waitAllForSafeState(instances);
}
} finally {
ex.shutdownNow();
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CardinalityEstimatorAdvancedTest method testCardinalityEstimatorFailure_whenSwitchedToDense.
@Test
public void testCardinalityEstimatorFailure_whenSwitchedToDense() {
int k = 4;
int sparseLimit = 10000;
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(k + 1);
HazelcastInstance instance = nodeFactory.newHazelcastInstance();
String name = "testFailure_whenSwitchedToDense";
CardinalityEstimator estimator = instance.getCardinalityEstimator(name);
for (int i = 0; i < sparseLimit; i++) {
estimator.add(String.valueOf(i + 1));
}
long estimateSoFar = estimator.estimate();
for (int i = 0; i < k; i++) {
HazelcastInstance newInstance = nodeFactory.newHazelcastInstance();
waitAllForSafeState(instance, newInstance);
CardinalityEstimator newEstimator = newInstance.getCardinalityEstimator(name);
assertEquals(estimateSoFar, newEstimator.estimate());
// Add numbers with huge gaps in between to guarantee change of est.
newEstimator.add(String.valueOf(1 << (14 + i)));
estimateSoFar = newEstimator.estimate();
instance.shutdown();
instance = newInstance;
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CacheHazelcastInstanceAwareTest method createInstance.
protected HazelcastInstance createInstance() {
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory();
Config config = createConfig();
return instanceFactory.newHazelcastInstance(config);
}
Aggregations