Search in sources :

Example 46 with AssertTask

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

the class RingbufferAbstractTest method readOne_whenOneAfterTail_thenBlock.

@Test
public void readOne_whenOneAfterTail_thenBlock() throws Exception {
    ringbuffer.add("1");
    ringbuffer.add("2");
    final long tail = ringbuffer.tailSequence();
    // first we do the invocation. This invocation is going to block
    final Future f = spawn(new Callable<String>() {

        @Override
        public String call() throws Exception {
            return ringbuffer.readOne(tail + 1);
        }
    });
    // then we check if the future is not going to complete.
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse(f.isDone());
        }
    }, 2);
    // then we add the item
    ringbuffer.add("3");
    // and eventually the future should complete
    assertCompletesEventually(f);
    assertEquals("3", f.get());
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) AssertTask(com.hazelcast.test.AssertTask) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 47 with AssertTask

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

the class ReplicatedMapHitsAndLastAccessTimeTest method testHitsAndLastAccessTimeIsSetToAnyValueAfterStartTime.

private void testHitsAndLastAccessTimeIsSetToAnyValueAfterStartTime(Config config) throws Exception {
    final long startTime = Clock.currentTimeMillis();
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    warmUpPartitions(instance1, instance2);
    final String mapName = randomMapName();
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap(mapName);
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap(mapName);
    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 (Map.Entry<String, String> entry : map1.entrySet()) {
                assertRecord(getReplicatedRecord(map1, entry.getKey()), startTime);
            }
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (Map.Entry<String, String> entry : map2.entrySet()) {
                assertRecord(getReplicatedRecord(map2, entry.getKey()), startTime);
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 48 with AssertTask

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

the class ReplicatedMapListenerTest method testRegisterListenerViaConfiguration.

@Test
public void testRegisterListenerViaConfiguration() throws Exception {
    String mapName = randomMapName();
    Config config = new Config();
    ReplicatedMapConfig replicatedMapConfig = config.getReplicatedMapConfig(mapName);
    EntryListenerConfig listenerConfig = new EntryListenerConfig();
    final EventCountingListener listener = new EventCountingListener();
    listenerConfig.setImplementation(listener);
    replicatedMapConfig.addEntryListenerConfig(listenerConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    ReplicatedMap<Object, Object> replicatedMap = instance.getReplicatedMap(mapName);
    replicatedMap.put(3, 3);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, listener.addCount.get());
            assertEquals(3, listener.keys.peek());
        }
    }, 10);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) ReplicatedMapConfig(com.hazelcast.config.ReplicatedMapConfig) AssertTask(com.hazelcast.test.AssertTask) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 49 with AssertTask

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

the class ReplicatedMapListenerTest method testListenToKeyWithPredicate.

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

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

Example 50 with AssertTask

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

the class ReplicatedMapListenerTest method testMapClear.

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

        @Override
        public void run() throws Exception {
            assertEquals(1, listener.mapClearCount.get());
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) 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