Search in sources :

Example 66 with AssertTask

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

the class InvocationMonitor_GetLastMemberHeartbeatMillisTest method whenRemote.

@Test
public void whenRemote() {
    final long startMillis = System.currentTimeMillis();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(startMillis + SECONDS.toMillis(5) < invocationMonitor.getLastMemberHeartbeatMillis(remoteAddress));
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 67 with AssertTask

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

the class Invocation_BlockingTest method sync_whenOperationTimeout.

// ====================================================================
//
// ====================================================================
@Test
public void sync_whenOperationTimeout() {
    int callTimeout = 5000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(factory.getAllHazelcastInstances());
    NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
    String key = generateKeyOwnedBy(remote);
    InternalLockNamespace namespace = new InternalLockNamespace(key);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we lock the lock by another thread
    InternalOperationService opService = nodeEngine.getOperationService();
    int otherThreadId = 2;
    opService.invokeOnPartition(new LockOperation(namespace, nodeEngine.toData(key), otherThreadId, -1, -1).setPartitionId(partitionId)).join();
    // then we execute a lock operation that won't be executed because lock is already acquired
    // we are going to do some waiting (3x call timeout)
    int threadId = 1;
    Operation op = new LockOperation(namespace, nodeEngine.toData(key), threadId, -1, 3 * callTimeout).setPartitionId(partitionId);
    final InternalCompletableFuture<Object> future = opService.invokeOnPartition(op);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(future.isDone());
        }
    });
    assertEquals(Boolean.FALSE, future.join());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) Config(com.hazelcast.config.Config) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) IsLockedOperation(com.hazelcast.concurrent.lock.operations.IsLockedOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 68 with AssertTask

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

the class Invocation_BlockingTest method async_whenOperationTimeout.

@Test
public void async_whenOperationTimeout() {
    int callTimeout = 5000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(factory.getAllHazelcastInstances());
    NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
    String key = generateKeyOwnedBy(remote);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we lock the lock by another thread
    InternalOperationService opService = nodeEngine.getOperationService();
    int otherThreadId = 2;
    opService.invokeOnPartition(new LockOperation(new InternalLockNamespace(key), nodeEngine.toData(key), otherThreadId, -1, -1).setPartitionId(partitionId)).join();
    // then we execute a lock operation that won't be executed because lock is already acquired
    // we are going to do some waiting (3x call timeout)
    int threadId = 1;
    Operation op = new LockOperation(new InternalLockNamespace(key), nodeEngine.toData(key), threadId, -1, 3 * callTimeout).setPartitionId(partitionId);
    final InternalCompletableFuture<Object> future = opService.invokeOnPartition(op);
    final ExecutionCallback<Object> callback = getExecutionCallbackMock();
    future.andThen(callback);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(callback).onResponse(Boolean.FALSE);
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) Config(com.hazelcast.config.Config) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) IsLockedOperation(com.hazelcast.concurrent.lock.operations.IsLockedOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 69 with AssertTask

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

the class OperationFailureTest method onFailure_shouldBeCalled_whenBackupExecutionFails.

@Test
public void onFailure_shouldBeCalled_whenBackupExecutionFails() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz = factory.newHazelcastInstance();
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    warmUpPartitions(hz, hz2);
    NodeEngineImpl nodeEngine = getNodeEngineImpl(hz);
    nodeEngine.getOperationService().invokeOnPartition(null, new EmptyBackupAwareOperation(), 0);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNotNull(backupOperationFailure.get());
        }
    });
    Throwable failure = backupOperationFailure.getAndSet(null);
    assertInstanceOf(ExpectedRuntimeException.class, failure);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) WrongTargetException(com.hazelcast.spi.exception.WrongTargetException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 70 with AssertTask

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

the class Invocation_TaskDoneTest method when_invocationFutureCanceled_thenCallbackRunsEventually.

@Test
public void when_invocationFutureCanceled_thenCallbackRunsEventually() throws InterruptedException {
    // Given
    final LatchAwaitOperation latchAwaitOp = new LatchAwaitOperation();
    final DoneCallback cb = new DoneCallback();
    final ICompletableFuture<Object> fut = operationService.createInvocationBuilder("mockService", latchAwaitOp, 0).setDoneCallback(cb).invoke();
    final FailedLatchExecutionCallback canceledCallback = new FailedLatchExecutionCallback();
    fut.andThen(canceledCallback);
    // When
    fut.cancel(true);
    assertOpenEventually(canceledCallback.latch);
    // Then
    assertFalse(cb.done);
    latchAwaitOp.latch.countDown();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(cb.done);
        }
    });
}
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