Search in sources :

Example 36 with AssertTask

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

the class ReducerTaskSchedulerTest method requestExecution_whenTriggeredWhileAlreadyRequested_thenExecuteTaskTwice.

@Test
public void requestExecution_whenTriggeredWhileAlreadyRequested_thenExecuteTaskTwice() {
    scheduler.requestExecution();
    scheduler.requestExecution();
    scheduler.requestExecution();
    semaphore.release();
    semaphore.release();
    semaphore.release();
    assertTrueEventually(new AssertTask() {

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

Example 37 with AssertTask

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

the class MultiMapLockTest method testTryLockLeaseTime_lockIsReleasedEventually.

@Test
public void testTryLockLeaseTime_lockIsReleasedEventually() throws InterruptedException {
    final MultiMap multiMap = getMultiMapForLock();
    final String key = randomString();
    multiMap.tryLock(key, 1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Assert.assertFalse(multiMap.isLocked(key));
        }
    }, 30);
}
Also used : MultiMap(com.hazelcast.core.MultiMap) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 38 with AssertTask

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

the class PartitionLostListenerRegistrationTest method assertRegistrationsSizeEventually.

private void assertRegistrationsSizeEventually(final HazelcastInstance instance, final int expectedSize) {
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrueEventually(new AssertTask() {

                @Override
                public void run() throws Exception {
                    final InternalEventService eventService = getNode(instance).getNodeEngine().getEventService();
                    assertEquals(expectedSize, eventService.getRegistrations(SERVICE_NAME, PARTITION_LOST_EVENT_TOPIC).size());
                }
            });
        }
    });
}
Also used : InternalEventService(com.hazelcast.spi.impl.eventservice.InternalEventService) AssertTask(com.hazelcast.test.AssertTask)

Example 39 with AssertTask

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

the class TcpIpConnection_BaseTest method write_whenNonUrgent.

@Test
public void write_whenNonUrgent() {
    TcpIpConnection c = connect(connManagerA, addressB);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    boolean result = c.write(packet);
    assertTrue(result);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, packetsB.size());
        }
    });
    Packet found = packetsB.get(0);
    assertEquals(packet, found);
}
Also used : Packet(com.hazelcast.nio.Packet) AssertTask(com.hazelcast.test.AssertTask) Test(org.junit.Test)

Example 40 with AssertTask

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

the class TcpIpConnection_BaseTest method lastWriteTimeMillis_whenPacketWritten.

@Test
public void lastWriteTimeMillis_whenPacketWritten() {
    TcpIpConnection connAB = connect(connManagerA, addressB);
    // we need to sleep some so that the lastWriteTime of the connection gets nice and old.
    // we need this so we can determine the lastWriteTime got updated
    sleepSeconds(LAST_READ_WRITE_SLEEP_SECONDS);
    Packet packet = new Packet(serializationService.toBytes("foo"));
    connAB.write(packet);
    // wait for the packet to get written.
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, packetsB.size());
        }
    });
    long lastWriteTimeMs = connAB.lastWriteTimeMillis();
    long nowMs = currentTimeMillis();
    // make sure that the lastWrite time is within the given MARGIN_OF_ERROR_MS
    // last write time should be equal or smaller than now
    assertTrue("nowMs = " + nowMs + ", lastWriteTimeMs = " + lastWriteTimeMs, lastWriteTimeMs <= nowMs);
    // last write time should be larger or equal than the now - MARGIN_OF_ERROR_MS
    assertTrue("nowMs = " + nowMs + ", lastWriteTimeMs = " + lastWriteTimeMs, lastWriteTimeMs >= nowMs - MARGIN_OF_ERROR_MS);
}
Also used : Packet(com.hazelcast.nio.Packet) AssertTask(com.hazelcast.test.AssertTask) Test(org.junit.Test)

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