Search in sources :

Example 51 with AssertTask

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

the class ReplicatedMapListenerTest method testEntryAdded.

@Test
public void testEntryAdded() throws Exception {
    ReplicatedMap<Object, Object> replicatedMap = createClusterAndGetRandomReplicatedMap();
    final EventCountingListener listener = new EventCountingListener();
    replicatedMap.addEntryListener(listener);
    replicatedMap.put(1, 1);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, listener.addCount.get());
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 52 with AssertTask

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

the class ReplicatedMapLiteMemberTest method testLiteMembersWithReplicatedMap.

@Test
public void testLiteMembersWithReplicatedMap() throws Exception {
    final Config config = buildConfig(false);
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance lite = nodeFactory.newHazelcastInstance(buildConfig(true));
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
    map1.put("key", "value");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(instance2.getReplicatedMap("default").containsKey("key"));
        }
    });
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            final ReplicatedMapService service = getReplicatedMapService(lite);
            assertEquals(0, service.getAllReplicatedRecordStores("default").size());
        }
    }, 5);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) 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 53 with AssertTask

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

the class ReplicatedMapTest method testSize.

private void testSize(Config config) throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
    final int partitionCount = getPartitionService(instance1).getPartitionCount();
    final Set<String> keys = generateRandomKeys(instance1, partitionCount);
    final SimpleEntry<String, String>[] testValues = buildTestValues(keys);
    int half = testValues.length / 2;
    for (int i = 0; i < testValues.length; i++) {
        final ReplicatedMap<String, String> map = i < half ? map1 : map2;
        final SimpleEntry<String, String> entry = testValues[i];
        map.put(entry.getKey(), entry.getValue());
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(keys.size(), map1.size());
            assertEquals(keys.size(), map2.size());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SimpleEntry(java.util.AbstractMap.SimpleEntry) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException)

Example 54 with AssertTask

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

the class ReplicatedMapTest method testKeySet_notIncludes_removedKeys.

@Test
public void testKeySet_notIncludes_removedKeys() throws Exception {
    HazelcastInstance node = createHazelcastInstance();
    final ReplicatedMap<Integer, Integer> map = node.getReplicatedMap("default");
    map.put(1, Integer.MAX_VALUE);
    map.put(2, Integer.MIN_VALUE);
    map.remove(1);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Set<Integer> keys = new HashSet<Integer>(map.keySet());
            assertFalse(keys.contains(1));
        }
    }, 20);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashSet(java.util.HashSet) Set(java.util.Set) AssertTask(com.hazelcast.test.AssertTask) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 55 with AssertTask

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

the class ReplicatedMapTest method testRemove.

private void testRemove(Config config) throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
    final int partitionCount = getPartitionService(instance1).getPartitionCount();
    final Set<String> keys = generateRandomKeys(instance1, partitionCount);
    for (String key : keys) {
        map1.put(key, "bar");
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (String key : keys) {
                assertEquals("map1 should return value for key " + key, "bar", map1.get(key));
                assertEquals("map2 should return value for key " + key, "bar", map2.get(key));
            }
        }
    });
    for (String key : keys) {
        map2.remove(key);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (String key : keys) {
                assertFalse("map1 should not contain key " + key, map1.containsKey(key));
                assertFalse("map2 should not contain key " + key, map2.containsKey(key));
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException)

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