Search in sources :

Example 26 with AssertTask

use of com.hazelcast.test.AssertTask 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)

Example 27 with AssertTask

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

the class NearCacheLiteMemberTest method testPutAll.

public static void testPutAll(HazelcastInstance instance, HazelcastInstance lite, String mapName) {
    IMap<Object, Object> map = instance.getMap(mapName);
    IMap<Object, Object> liteMap = lite.getMap(mapName);
    NearCachedMapProxyImpl proxy = (NearCachedMapProxyImpl) liteMap;
    NearCache liteNearCache = proxy.getNearCache();
    SerializationService serializationService = ((SerializationServiceSupport) instance).getSerializationService();
    int count = 100;
    // fill the near cache with the same data as below so we can detect when it is emptied
    for (int i = 0; i < count; i++) {
        liteNearCache.put(serializationService.toData(i), i);
    }
    final NearCacheStats stats = liteNearCache.getNearCacheStats();
    assertEquals(100, stats.getOwnedEntryCount());
    Map<Object, Object> localMap = new HashMap<Object, Object>();
    for (int i = 0; i < count; i++) {
        localMap.put(i, i);
    }
    map.putAll(localMap);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, stats.getOwnedEntryCount());
        }
    });
    for (int i = 0; i < count; i++) {
        liteMap.get(i);
    }
    assertLiteMemberNearCacheNonEmpty(lite, mapName);
}
Also used : HashMap(java.util.HashMap) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) NearCache(com.hazelcast.internal.nearcache.NearCache) SerializationService(com.hazelcast.spi.serialization.SerializationService) NearCacheStats(com.hazelcast.monitor.NearCacheStats) SerializationServiceSupport(com.hazelcast.spi.impl.SerializationServiceSupport) AssertTask(com.hazelcast.test.AssertTask)

Example 28 with AssertTask

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

the class PostJoinMapOperationTest method testPostJoinMapOperation_mapWithIndex.

// This test is meant to verify that a query will be executed *with an index* on the joining node
// See also QueryIndexMigrationTest, which tests that results are as expected.
@Test
public void testPostJoinMapOperation_mapWithIndex() throws InterruptedException {
    TestHazelcastInstanceFactory hzFactory = createHazelcastInstanceFactory(2);
    // given: a map with index on a single-node HazelcastInstance
    HazelcastInstance hz1 = hzFactory.newHazelcastInstance();
    IMap<String, Person> map = hz1.getMap("map");
    map.put("foo", new Person("foo", 32));
    map.put("bar", new Person("bar", 70));
    map.addIndex("age", true);
    // when: new node joins and original node is terminated
    HazelcastInstance hz2 = hzFactory.newHazelcastInstance();
    waitAllForSafeState(hz1, hz2);
    hzFactory.terminate(hz1);
    waitAllForSafeState(hz2);
    // then: once all migrations are committed, the query is executed *with* the index and
    // returns the expected results.
    final IMap<String, Person> mapOnNode2 = hz2.getMap("map");
    final AtomicInteger invocationCounter = new AtomicInteger(0);
    // eventually index should be created after join
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection<Person> personsWithAgePredicate = mapOnNode2.values(new AgePredicate(invocationCounter));
            assertEquals("isIndexed should have located an index", 1, invocationCounter.get());
            assertEquals("index should return 1 match", 1, personsWithAgePredicate.size());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with AssertTask

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

the class NearCacheTest method testNearCacheInvalidation_whenMaxSizeExceeded.

private void testNearCacheInvalidation_whenMaxSizeExceeded(EvictionPolicy evictionPolicy) {
    int mapSize = 2000;
    final int maxSize = 1000;
    final IMap<Integer, Integer> map = getMapConfiguredWithMaxSizeAndPolicy(evictionPolicy, maxSize);
    populateMap(map, mapSize);
    populateNearCache(map, mapSize);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            long ownedEntryCount = getNearCacheStats(map).getOwnedEntryCount();
            assertEquals(maxSize, ownedEntryCount);
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask)

Example 30 with AssertTask

use of com.hazelcast.test.AssertTask 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)

Aggregations

AssertTask (com.hazelcast.test.AssertTask)575 Test (org.junit.Test)489 QuickTest (com.hazelcast.test.annotation.QuickTest)428 ParallelTest (com.hazelcast.test.annotation.ParallelTest)347 HazelcastInstance (com.hazelcast.core.HazelcastInstance)263 Config (com.hazelcast.config.Config)113 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)94 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)75 ExecutionException (java.util.concurrent.ExecutionException)57 MapConfig (com.hazelcast.config.MapConfig)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 IOException (java.io.IOException)46 CountDownLatch (java.util.concurrent.CountDownLatch)42 IMap (com.hazelcast.core.IMap)39 NearCacheConfig (com.hazelcast.config.NearCacheConfig)38 TimeoutException (java.util.concurrent.TimeoutException)33 ClientConfig (com.hazelcast.client.config.ClientConfig)32 MapStoreConfig (com.hazelcast.config.MapStoreConfig)29 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)20