Search in sources :

Example 36 with TestHazelcastInstanceFactory

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

Example 37 with TestHazelcastInstanceFactory

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

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);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TimedExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.TimedExpiryPolicyFactoryConfig) DurationConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig.DurationConfig) ExpiryPolicyFactoryConfig(com.hazelcast.config.CacheSimpleConfig.ExpiryPolicyFactoryConfig) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 39 with TestHazelcastInstanceFactory

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) IAtomicLong(com.hazelcast.core.IAtomicLong) 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 40 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)

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