Search in sources :

Example 31 with AssertTask

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

the class NearCacheTest method testMapClear_clearsLocalNearCache.

@Test
public void testMapClear_clearsLocalNearCache() {
    int size = 1000;
    final String mapName = randomMapName();
    Config config = createNearCachedMapConfig(mapName);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    final HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    final HazelcastInstance instance3 = factory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = instance1.getMap(mapName);
    populateMap(map, size);
    populateNearCache(map, size);
    map.clear();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(0, getNearCacheSize(instance1.getMap(mapName)));
            assertEquals(0, getNearCacheSize(instance2.getMap(mapName)));
            assertEquals(0, getNearCacheSize(instance3.getMap(mapName)));
        }
    });
}
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) 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 32 with AssertTask

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

the class NearCacheLiteMemberTest method assertNullNearCacheEntryEventually.

private static void assertNullNearCacheEntryEventually(final HazelcastInstance instance, String mapName, Object key) {
    final NearCache<Object, Object> nearCache = getNearCache(instance, mapName);
    final Data keyData = toData(instance, key);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertNull(toObject(instance, nearCache.get(keyData)));
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) Data(com.hazelcast.nio.serialization.Data)

Example 33 with AssertTask

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

the class QueryAdvancedTest method testQueryAfterInitialLoad.

// issue 1404 "to be fixed by issue 1404"
@Test
public void testQueryAfterInitialLoad() {
    final int size = 100;
    String name = "default";
    Config config = getConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new MapStoreAdapter<Integer, Employee>() {

        @Override
        public Map<Integer, Employee> loadAll(Collection<Integer> keys) {
            Map<Integer, Employee> map = new HashMap<Integer, Employee>();
            for (Integer key : keys) {
                Employee emp = new Employee();
                emp.setActive(true);
                map.put(key, emp);
            }
            return map;
        }

        @Override
        public Set<Integer> loadAllKeys() {
            Set<Integer> set = new HashSet<Integer>();
            for (int i = 0; i < size; i++) {
                set.add(i);
            }
            return set;
        }
    });
    config.getMapConfig(name).setMapStoreConfig(mapStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IMap map = instance.getMap(name);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection values = map.values(new SqlPredicate("active = true"));
            assertEquals(size, values.size());
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) MapStoreConfig(com.hazelcast.config.MapStoreConfig) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IMap(com.hazelcast.core.IMap) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) 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)

Example 34 with AssertTask

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

the class MultiMapListenerTest method testListeners.

@Test
public void testListeners() throws Exception {
    int count = 4;
    String name = randomMapName();
    Config config = new Config();
    config.getMultiMapConfig(name).setValueCollectionType(MultiMapConfig.ValueCollectionType.LIST);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(count);
    HazelcastInstance[] instances = factory.newInstances(config);
    final Set<String> keys = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
    EntryListener<String, String> listener = new EntryAdapter<String, String>() {

        public void entryAdded(EntryEvent<String, String> event) {
            keys.add(event.getKey());
        }

        public void entryRemoved(EntryEvent<String, String> event) {
            keys.remove(event.getKey());
        }

        @Override
        public void mapCleared(MapEvent event) {
            keys.clear();
        }
    };
    final MultiMap<String, String> multiMap = instances[0].getMultiMap(name);
    final String id = multiMap.addLocalEntryListener(listener);
    multiMap.put("key1", "val1");
    multiMap.put("key2", "val2");
    multiMap.put("key3", "val3");
    multiMap.put("key4", "val4");
    multiMap.put("key5", "val5");
    multiMap.put("key6", "val6");
    multiMap.put("key7", "val7");
    multiMap.put("key8", "val8");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertContainsAll(multiMap.localKeySet(), keys);
        }
    });
    if (keys.size() != 0) {
        multiMap.remove(keys.iterator().next());
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertContainsAll(multiMap.localKeySet(), keys);
        }
    });
    multiMap.removeEntryListener(id);
    getMultiMap(instances, name).clear();
    keys.clear();
    final String id2 = multiMap.addEntryListener(listener, true);
    getMultiMap(instances, name).put("key3", "val3");
    getMultiMap(instances, name).put("key3", "val33");
    getMultiMap(instances, name).put("key4", "val4");
    getMultiMap(instances, name).remove("key3", "val33");
    assertSizeEventually(1, keys);
    getMultiMap(instances, name).clear();
    assertSizeEventually(0, keys);
    multiMap.removeEntryListener(id2);
    multiMap.addEntryListener(listener, "key7", true);
    getMultiMap(instances, name).put("key2", "val2");
    getMultiMap(instances, name).put("key3", "val3");
    getMultiMap(instances, name).put("key7", "val7");
    assertSizeEventually(1, keys);
}
Also used : MultiMapConfig(com.hazelcast.config.MultiMapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) MapEvent(com.hazelcast.core.MapEvent) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryEvent(com.hazelcast.core.EntryEvent) 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 35 with AssertTask

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

the class TxnMultiMapTest method testListener.

@Test
public void testListener() throws InterruptedException {
    String mapName = "mm";
    long key = 1L;
    String value = "value";
    String value2 = "value2";
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    final CountingEntryListener<Object, Object> listener = new CountingEntryListener<Object, Object>();
    MultiMap<Object, Object> map = instance1.getMultiMap(mapName);
    map.addEntryListener(listener, true);
    TransactionContext ctx1 = instance2.newTransactionContext();
    ctx1.beginTransaction();
    ctx1.getMultiMap(mapName).put(key, value);
    ctx1.commitTransaction();
    TransactionContext ctx2 = instance2.newTransactionContext();
    ctx2.beginTransaction();
    ctx2.getMultiMap(mapName).remove(key, value);
    ctx2.commitTransaction();
    TransactionContext ctx3 = instance2.newTransactionContext();
    ctx3.beginTransaction();
    ctx3.getMultiMap(mapName).put(key, value2);
    ctx3.commitTransaction();
    TransactionContext ctx4 = instance1.newTransactionContext();
    ctx4.beginTransaction();
    ctx4.getMultiMap(mapName).remove(key, value2);
    ctx4.commitTransaction();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(2, listener.getAddedCount());
            assertEquals(2, listener.getRemovedCount());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TransactionException(com.hazelcast.transaction.TransactionException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) 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