Search in sources :

Example 16 with OperationService

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

the class OperationServiceImpl_timeoutTest method testOperationTimeoutForLongRunningRemoteOperation.

@Test
public void testOperationTimeoutForLongRunningRemoteOperation() throws Exception {
    int callTimeoutMillis = 3000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeoutMillis);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    // invoke on the "remote" member
    Address remoteAddress = getNode(hz2).getThisAddress();
    OperationService operationService = getNode(hz1).getNodeEngine().getOperationService();
    ICompletableFuture<Boolean> future = operationService.invokeOnTarget(null, new SleepingOperation(callTimeoutMillis * 5), remoteAddress);
    // wait more than operation timeout
    sleepAtLeastMillis(callTimeoutMillis * 3);
    assertTrue(future.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) 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 17 with OperationService

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

the class OperationServiceImpl_timeoutTest method testOperationTimeout.

private void testOperationTimeout(int memberCount, boolean async) {
    assertTrue(memberCount > 0);
    Config config = new Config();
    config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(memberCount);
    HazelcastInstance[] instances = factory.newInstances(config);
    warmUpPartitions(instances);
    final HazelcastInstance hz = instances[memberCount - 1];
    Node node = TestUtil.getNode(hz);
    NodeEngine nodeEngine = node.nodeEngine;
    OperationService operationService = nodeEngine.getOperationService();
    int partitionId = (int) (Math.random() * node.getPartitionService().getPartitionCount());
    InternalCompletableFuture<Object> future = operationService.invokeOnPartition(null, new TimedOutBackupAwareOperation(), partitionId);
    final CountDownLatch latch = new CountDownLatch(1);
    if (async) {
        future.andThen(new ExecutionCallback<Object>() {

            @Override
            public void onResponse(Object response) {
            }

            @Override
            public void onFailure(Throwable t) {
                if (t instanceof OperationTimeoutException) {
                    latch.countDown();
                }
            }
        });
    } else {
        try {
            future.join();
            fail("Should throw OperationTimeoutException!");
        } catch (OperationTimeoutException ignored) {
            latch.countDown();
        }
    }
    assertOpenEventually("Should throw OperationTimeoutException", latch);
    for (HazelcastInstance instance : instances) {
        OperationServiceImpl_BasicTest.assertNoLitterInOpService(instance);
    }
}
Also used : OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) CountDownLatch(java.util.concurrent.CountDownLatch) NodeEngine(com.hazelcast.spi.NodeEngine) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 18 with OperationService

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

the class InvocationFuture_GetNewInstanceTest method invocationToRemoteMember.

@Test
public void invocationToRemoteMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    Address remoteAddress = getAddress(remote);
    OperationService operationService = getOperationService(local);
    Future future = operationService.createInvocationBuilder(null, op, remoteAddress).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data) Operation(com.hazelcast.spi.Operation) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with OperationService

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

the class InvocationFuture_GetNewInstanceTest method invocationToLocalMember.

@Test
public void invocationToLocalMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    OperationService service = getOperationService(local);
    Future future = service.createInvocationBuilder(null, op, localNode.address).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Node(com.hazelcast.instance.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data) Operation(com.hazelcast.spi.Operation) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with OperationService

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

the class Invocation_DetectHeartbeatTimeoutTest method whenCallTimeoutDisabled.

@Test
public void whenCallTimeoutDisabled() {
    Config config = new Config();
    config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "1000");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance();
    HazelcastInstance remote = factory.newHazelcastInstance();
    OperationService opService = getOperationService(local);
    Operation operation = new VoidOperation();
    InvocationFuture future = (InvocationFuture) opService.createInvocationBuilder(null, operation, getPartitionId(remote)).setCallTimeout(Long.MAX_VALUE).invoke();
    Invocation invocation = future.invocation;
    assertEquals(Long.MAX_VALUE, invocation.op.getCallTimeout());
    assertEquals(Long.MAX_VALUE, invocation.callTimeoutMillis);
    assertEquals(NO_TIMEOUT__CALL_TIMEOUT_DISABLED, invocation.detectTimeout(SECONDS.toMillis(1)));
    assertFalse(future.isDone());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) OperationService(com.hazelcast.spi.OperationService) Operation(com.hazelcast.spi.Operation) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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