Search in sources :

Example 16 with AssertTask

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

the class ListenerTest method testEntryListenerEvent_withMapReplaceFail.

@Test
public void testEntryListenerEvent_withMapReplaceFail() throws Exception {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    final IMap<Integer, Object> map = instance.getMap(randomString());
    final CounterEntryListener listener = new CounterEntryListener();
    map.addEntryListener(listener, true);
    final int putTotal = 1000;
    final int oldVal = 1;
    for (int i = 0; i < putTotal; i++) {
        map.put(i, oldVal);
    }
    final int replaceTotal = 1000;
    final int newVal = 2;
    for (int i = 0; i < replaceTotal; i++) {
        map.replace(i, "WrongValue", newVal);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            for (int i = 0; i < replaceTotal; i++) {
                assertEquals(oldVal, map.get(i));
            }
            assertEquals(putTotal, listener.addCount.get());
            assertEquals(0, listener.updateCount.get());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with AssertTask

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

the class EvictionTest method testEvictionAfterRemove.

/**
     * Test for the issue 537.
     * Eviction event is fired for an object already removed
     */
@Test
public void testEvictionAfterRemove() throws InterruptedException {
    IMap<Object, Object> map = createSimpleMap();
    final AtomicInteger count = new AtomicInteger(0);
    map.addEntryListener(new EntryAdapter<Object, Object>() {

        @Override
        public void entryEvicted(EntryEvent<Object, Object> event) {
            count.incrementAndGet();
        }
    }, true);
    // ttl is 2 seconds.
    map.put(1, 1, 2, TimeUnit.SECONDS);
    final int expected = (map.remove(1) == null ? 1 : 0);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(expected, count.get());
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with AssertTask

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

the class EntryProcessorTest method executionOrderTest.

@Test
public void executionOrderTest() {
    Config cfg = getConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
    final int maxTasks = 20;
    final Object key = "key";
    final IMap<Object, List<Integer>> processorMap = instance1.getMap(MAP_NAME);
    processorMap.put(key, new ArrayList<Integer>());
    for (int i = 0; i < maxTasks; i++) {
        processorMap.submitToKey(key, new SimpleEntryProcessor(i));
    }
    List<Integer> expectedOrder = new ArrayList<Integer>();
    for (int i = 0; i < maxTasks; i++) {
        expectedOrder.add(i);
    }
    assertTrueEventually(new AssertTask() {

        public void run() throws Exception {
            List<Integer> actualOrder = processorMap.get(key);
            assertEquals("failed to execute all entry processor tasks", maxTasks, actualOrder.size());
        }
    });
    List<Integer> actualOrder = processorMap.get(key);
    assertEquals("entry processor tasks executed in unexpected order", expectedOrder, actualOrder);
}
Also used : MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) EntryObject(com.hazelcast.query.EntryObject) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with AssertTask

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

the class MapLockTest method testTryLockLeaseTime_lockIsReleasedEventually.

@Test
public void testTryLockLeaseTime_lockIsReleasedEventually() throws InterruptedException {
    final IMap<String, String> map = getMap();
    final String key = randomString();
    map.tryLock(key, 1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse(map.isLocked(key));
        }
    }, 30);
}
Also used : AssertTask(com.hazelcast.test.AssertTask) TransactionException(com.hazelcast.transaction.TransactionException) NightlyTest(com.hazelcast.test.annotation.NightlyTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with AssertTask

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

the class EvictionTest method testIssue585SetWithoutTTL.

@Test
public void testIssue585SetWithoutTTL() throws InterruptedException {
    final IMap<String, String> map = createSimpleMap();
    final String key = "key";
    map.set(key, "value", 5, TimeUnit.SECONDS);
    // this `set` operation should not affect existing ttl.
    // so "key" should be expired after 1 seconds.
    map.set(key, "value2");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNull("Key should be expired after 1 seconds", map.get(key));
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) 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