Search in sources :

Example 31 with OperationService

use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.

the class Invocation_TimeoutTest method async_whenEventuallyHeartbeatTimeout_thenOperationTimeoutException.

@Test
public void async_whenEventuallyHeartbeatTimeout_thenOperationTimeoutException() throws Exception {
    long callTimeoutMs = 5000;
    Config config = new Config().setProperty(GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeoutMs);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    OperationService opService = getOperationService(local);
    ICompletableFuture<Object> future = opService.invokeOnPartition(null, new VoidOperation(callTimeoutMs * 5), getPartitionId(remote));
    final ExecutionCallback<Object> callback = getExecutionCallbackMock();
    future.andThen(callback);
    assertEventuallyFailsWithHeartbeatTimeout(callback);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 32 with OperationService

use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.

the class Invocation_TimeoutTest method async_whenCallTimeout_thenOperationTimeoutException.

@Test
public void async_whenCallTimeout_thenOperationTimeoutException() throws Exception {
    long callTimeoutMs = 60000;
    Config config = new Config().setProperty(GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeoutMs);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    OperationService opService = getOperationService(local);
    int partitionId = getPartitionId(remote);
    long slowOperationDurationMs = (long) (callTimeoutMs * 1.1);
    opService.invokeOnPartition(new SlowOperation(slowOperationDurationMs).setPartitionId(partitionId));
    ICompletableFuture<Object> future = opService.invokeOnPartition(new DummyOperation().setPartitionId(partitionId));
    ExecutionCallback<Object> callback = getExecutionCallbackMock();
    future.andThen(callback);
    assertEventuallyFailsWithCallTimeout(callback);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 33 with OperationService

use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.

the class Invocation_TimeoutTest method sync_whenEventuallyHeartbeatTimeout_thenOperationTimeoutException.

// ==================== eventually operation heartbeat timeout ===============================================================
// This test verifies that an Invocation is going to timeout when initially there was a heartbeat, but eventually this
// heartbeat stops
//
// This is done by creating a void operation that runs for an extended period and on completion, the void operation doesn't
// send a response.
// ===========================================================================================================================
@Test
public void sync_whenEventuallyHeartbeatTimeout_thenOperationTimeoutException() throws Exception {
    long callTimeoutMs = 5000;
    Config config = new Config().setProperty(GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeoutMs);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    OperationService opService = getOperationService(local);
    Future future = opService.invokeOnPartition(null, new VoidOperation(callTimeoutMs * 5), getPartitionId(remote));
    try {
        future.get(10 * callTimeoutMs, MILLISECONDS);
        fail();
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        assertInstanceOf(OperationTimeoutException.class, cause);
        assertContains(cause.getMessage(), "operation-heartbeat-timeout");
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) Future(java.util.concurrent.Future) ICompletableFuture(com.hazelcast.core.ICompletableFuture) OperationService(com.hazelcast.spi.OperationService) ExecutionException(java.util.concurrent.ExecutionException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 34 with OperationService

use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.

the class Invocation_TimeoutTest method async_whenLongRunningOperation.

@Test
public void async_whenLongRunningOperation() throws InterruptedException, ExecutionException, TimeoutException {
    long callTimeout = 5000;
    Config config = new Config().setProperty(GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    OperationService opService = getOperationService(local);
    ICompletableFuture<Object> future = opService.invokeOnPartition(null, new SlowOperation(6 * callTimeout, RESPONSE), getPartitionId(remote));
    final ExecutionCallback<Object> callback = getExecutionCallbackMock();
    future.andThen(callback);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(callback).onResponse(RESPONSE);
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 35 with OperationService

use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.

the class SystemOperationPrecedenseTest method testPartitionUnaware.

@Test
public void testPartitionUnaware() {
    HazelcastInstance hz = createHazelcastInstance();
    OperationService opService = getNode(hz).nodeEngine.getOperationService();
    int pendingOperations = 10000;
    final CountDownLatch latch = new CountDownLatch(1);
    //we are going to fill up the partition first with tons of normal operations with take a lot of time
    for (int k = 0; k < pendingOperations; k++) {
        opService.execute(new NormalPartitionUnawareOperation());
    }
    //then we place the system operation
    opService.execute(new UrgentPartitionUnawareOperation(latch));
    //if the system operation would be given urgency, we should only wait for 1 operation to be processed before
    //our system operation is processed.
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(0, latch.getCount());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

OperationService (com.hazelcast.spi.OperationService)135 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)48 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 HazelcastInstance (com.hazelcast.core.HazelcastInstance)45 Operation (com.hazelcast.spi.Operation)39 NodeEngine (com.hazelcast.spi.NodeEngine)30 Address (com.hazelcast.nio.Address)26 Future (java.util.concurrent.Future)26 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 Config (com.hazelcast.config.Config)21 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)21 Member (com.hazelcast.core.Member)19 Data (com.hazelcast.nio.serialization.Data)14 ArrayList (java.util.ArrayList)11 Node (com.hazelcast.instance.Node)7 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)7 ExecutionException (java.util.concurrent.ExecutionException)7 TimeoutException (java.util.concurrent.TimeoutException)7 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)6