Search in sources :

Example 1 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class FrozenPartitionTableTest method partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIsFrozen.

@Test
public void partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIsFrozen() {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
    HazelcastInstance[] instances = factory.newInstances(config, 3);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    Address hz3Address = getNode(hz3).getThisAddress();
    warmUpPartitions(instances);
    final Map<Integer, List<Address>> partitionTable = getPartitionTable(hz1);
    changeClusterStateEventually(hz2, ClusterState.FROZEN);
    terminateInstance(hz3);
    hz3 = factory.newHazelcastInstance(hz3Address);
    assertClusterSizeEventually(3, hz1);
    assertClusterSizeEventually(3, hz2);
    assertClusterSizeEventually(3, hz3);
    for (HazelcastInstance instance : Arrays.asList(hz1, hz2, hz3)) {
        final HazelcastInstance hz = instance;
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertPartitionTablesSame(partitionTable, getPartitionTable(hz));
            }
        });
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) ArrayList(java.util.ArrayList) List(java.util.List) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class LocalMapStatsTest method testHits_whenMultipleNodes.

@Test
public void testHits_whenMultipleNodes() throws InterruptedException {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance[] instances = factory.newInstances(getConfig());
    MultiMap<Object, Object> multiMap0 = instances[0].getMultiMap("testHits_whenMultipleNodes");
    MultiMap<Object, Object> multiMap1 = instances[1].getMultiMap("testHits_whenMultipleNodes");
    // InternalPartitionService is used in order to determine owners of these keys that we will use.
    InternalPartitionService partitionService = getNode(instances[0]).getPartitionService();
    Address address = partitionService.getPartitionOwner(partitionService.getPartitionId("test1"));
    boolean inFirstInstance = address.equals(getNode(instances[0]).getThisAddress());
    multiMap0.get("test0");
    multiMap0.put("test1", 1);
    multiMap1.get("test1");
    assertEquals(inFirstInstance ? 1 : 0, multiMap0.getLocalMultiMapStats().getHits());
    assertEquals(inFirstInstance ? 0 : 1, multiMap1.getLocalMultiMapStats().getHits());
    multiMap0.get("test1");
    multiMap1.get("test1");
    assertEquals(inFirstInstance ? 0 : 3, multiMap1.getLocalMultiMapStats().getHits());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class LocalMapStatsTest method testLocalMapStats_withMemberGroups.

@Test
public void testLocalMapStats_withMemberGroups() throws Exception {
    final String mapName = randomMapName();
    final String[] firstMemberGroup = { "127.0.0.1", "127.0.0.2" };
    final String[] secondMemberGroup = { "127.0.0.3" };
    final Config config = createConfig(mapName, firstMemberGroup, secondMemberGroup);
    final String[] addressArray = concatenateArrays(firstMemberGroup, secondMemberGroup);
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(addressArray);
    final HazelcastInstance node1 = factory.newHazelcastInstance(config);
    final HazelcastInstance node2 = factory.newHazelcastInstance(config);
    final HazelcastInstance node3 = factory.newHazelcastInstance(config);
    final IMap<Object, Object> test = node3.getMap(mapName);
    test.put(1, 1);
    assertBackupEntryCount(1, mapName, factory.getAllHazelcastInstances());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class MemberMapRecordStateStressTest method setUp.

@Before
public void setUp() throws Exception {
    factory = new TestHazelcastInstanceFactory();
    stop.set(false);
}
Also used : TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Before(org.junit.Before)

Example 5 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class NearCacheBatchInvalidationTest method testBatchInvalidationRemovesEntries.

@Test
public void testBatchInvalidationRemovesEntries() throws Exception {
    String mapName = randomMapName();
    Config config = newConfig(mapName);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    configureBatching(config, true, 12, 1);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance node1 = factory.newHazelcastInstance(config);
    HazelcastInstance node2 = factory.newHazelcastInstance(config);
    final IMap<Integer, Integer> map1 = node1.getMap(mapName);
    final IMap<Integer, Integer> map2 = node2.getMap(mapName);
    int size = 1000;
    // fill map-1
    for (int i = 0; i < size; i++) {
        map1.put(i, i);
    }
    // fill Near Cache on node-1
    for (int i = 0; i < size; i++) {
        map1.get(i);
    }
    // fill Near Cache on node-2
    for (int i = 0; i < size; i++) {
        map2.get(i);
    }
    // generate invalidation data
    for (int i = 0; i < size; i++) {
        map1.put(i, i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
            NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
            assertEquals(0, nearCache1.size() + nearCache2.size());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) NearCache(com.hazelcast.internal.nearcache.NearCache) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)948 HazelcastInstance (com.hazelcast.core.HazelcastInstance)827 Test (org.junit.Test)774 QuickTest (com.hazelcast.test.annotation.QuickTest)726 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)575 Config (com.hazelcast.config.Config)488 MapConfig (com.hazelcast.config.MapConfig)185 ParallelTest (com.hazelcast.test.annotation.ParallelTest)145 MapStoreConfig (com.hazelcast.config.MapStoreConfig)121 CountDownLatch (java.util.concurrent.CountDownLatch)108 AssertTask (com.hazelcast.test.AssertTask)97 NightlyTest (com.hazelcast.test.annotation.NightlyTest)86 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)81 Before (org.junit.Before)75 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)58 NearCacheConfig (com.hazelcast.config.NearCacheConfig)53 SlowTest (com.hazelcast.test.annotation.SlowTest)53 IndexConfig (com.hazelcast.config.IndexConfig)50 ArrayList (java.util.ArrayList)45 Map (java.util.Map)43