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));
}
});
}
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());
}
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);
}
});
}
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);
}
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);
}
});
}
Aggregations