Search in sources :

Example 91 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class ContainsValueOperationTest method setUp.

@Before
public void setUp() throws Exception {
    Config config = getConfig();
    member1 = factory.newHazelcastInstance(config);
    member2 = factory.newHazelcastInstance(config);
}
Also used : Config(com.hazelcast.config.Config) Before(org.junit.Before)

Example 92 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class NearCacheTest method testAfterLoadAllNearCacheIsInvalidated.

@Test
public void testAfterLoadAllNearCacheIsInvalidated() {
    int mapSize = 1000;
    String mapName = randomMapName();
    Config config = createNearCachedMapConfigWithMapStoreConfig(mapName);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Integer> map = instance.getMap(mapName);
    populateMap(map, mapSize);
    populateNearCache(map, mapSize);
    map.loadAll(true);
    assertEquals(0, getNearCacheStats(map).getOwnedEntryCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 93 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class NearCacheTest method testNearCacheInvalidationByUsingMapPutAll.

@Test
public void testNearCacheInvalidationByUsingMapPutAll() {
    int clusterSize = 3;
    int mapSize = 5000;
    String mapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig().setInvalidateOnChange(true));
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
    HazelcastInstance[] instances = factory.newInstances(config);
    final IMap<Integer, Integer> map = instances[0].getMap(mapName);
    populateMap(map, mapSize);
    populateNearCache(map, mapSize);
    // more-or-less (count / no_of_nodes) should be in the Near Cache now
    assertTrue(getNearCacheSize(map) > (mapSize / clusterSize - mapSize * 0.1));
    Map<Integer, Integer> invalidationMap = new HashMap<Integer, Integer>(mapSize);
    populateMap(invalidationMap, mapSize);
    // this should invalidate the Near Cache
    map.putAll(invalidationMap);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals("Invalidation is not working on putAll()", 0, getNearCacheSize(map));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 94 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class NearCacheTest method testGetAsync.

@Test
public void testGetAsync() {
    int mapSize = 1000;
    int expectedHits = 400;
    String mapName = "testGetAsyncWithNearCache";
    Config config = getConfig();
    config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig().setInvalidateOnChange(false));
    TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = hazelcastInstanceFactory.newHazelcastInstance(config);
    hazelcastInstanceFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = instance1.getMap(mapName);
    populateMap(map, mapSize);
    populateNearCache(map, mapSize);
    for (int i = 0; i < mapSize; i++) {
        map.getAsync(i);
    }
    long hits = getNearCacheStats(map).getHits();
    assertTrue(format("Near Cache hits should be > %d but were %d", expectedHits, hits), hits > expectedHits);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 95 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class NearCacheTest method testAfterExecuteOnEntriesNearCacheIsInvalidated.

@Test
public void testAfterExecuteOnEntriesNearCacheIsInvalidated() {
    int mapSize = 10;
    String mapName = randomMapName();
    Config config = createNearCachedMapConfig(mapName);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap(mapName);
    for (int i = 0; i < mapSize; i++) {
        map.put(i, new Employee(i, "", 0, true, 0D));
    }
    populateNearCache(map, mapSize);
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("salary").equal(0);
    map.executeOnEntries(new AbstractEntryProcessor<Integer, Employee>() {

        @Override
        public Object process(Map.Entry<Integer, Employee> entry) {
            Employee employee = entry.getValue();
            double currentSalary = employee.getSalary();
            double newSalary = currentSalary + 10;
            employee.setSalary(newSalary);
            return newSalary;
        }
    }, predicate);
    assertEquals(0, getNearCacheStats(map).getOwnedEntryCount());
}
Also used : EntryObject(com.hazelcast.query.EntryObject) MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Predicate(com.hazelcast.query.Predicate) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PredicateBuilder(com.hazelcast.query.PredicateBuilder) EntryObject(com.hazelcast.query.EntryObject) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Config (com.hazelcast.config.Config)1190 Test (org.junit.Test)838 HazelcastInstance (com.hazelcast.core.HazelcastInstance)815 QuickTest (com.hazelcast.test.annotation.QuickTest)718 ParallelTest (com.hazelcast.test.annotation.ParallelTest)648 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)361 MapConfig (com.hazelcast.config.MapConfig)341 MapStoreConfig (com.hazelcast.config.MapStoreConfig)211 CountDownLatch (java.util.concurrent.CountDownLatch)145 NightlyTest (com.hazelcast.test.annotation.NightlyTest)142 NearCacheConfig (com.hazelcast.config.NearCacheConfig)125 Before (org.junit.Before)115 AssertTask (com.hazelcast.test.AssertTask)113 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)93 MapIndexConfig (com.hazelcast.config.MapIndexConfig)91 ClientConfig (com.hazelcast.client.config.ClientConfig)83 IMap (com.hazelcast.core.IMap)81 GroupConfig (com.hazelcast.config.GroupConfig)69 ListenerConfig (com.hazelcast.config.ListenerConfig)60 JoinConfig (com.hazelcast.config.JoinConfig)59