Search in sources :

Example 6 with TestHazelcastInstanceFactory

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Before(org.junit.Before)

Example 7 with TestHazelcastInstanceFactory

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 8 with TestHazelcastInstanceFactory

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with TestHazelcastInstanceFactory

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;
    }
}
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 10 with TestHazelcastInstanceFactory

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);
}
Also used : Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

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