Search in sources :

Example 71 with OperationService

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

the class Invocation_NestedRemoteTest method invokeOnPartition_outerGeneric_innerGeneric_forbidden.

@Test
public void invokeOnPartition_outerGeneric_innerGeneric_forbidden() {
    HazelcastInstance[] cluster = createHazelcastInstanceFactory(1).newInstances();
    HazelcastInstance local = cluster[0];
    OperationService operationService = getOperationService(local);
    InnerOperation innerOperation = new InnerOperation(RESPONSE, GENERIC_OPERATION);
    OuterOperation outerOperation = new OuterOperation(innerOperation, GENERIC_OPERATION);
    expected.expect(Exception.class);
    operationService.invokeOnPartition(null, outerOperation, outerOperation.getPartitionId());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 72 with OperationService

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

the class Invocation_NestedRemoteTest method invokeOnPartition_outerRemote_innerGeneric.

@Test
public void invokeOnPartition_outerRemote_innerGeneric() {
    HazelcastInstance[] cluster = createHazelcastInstanceFactory(2).newInstances();
    HazelcastInstance local = cluster[0];
    HazelcastInstance remote = cluster[1];
    OperationService operationService = getOperationService(local);
    int partitionId = getPartitionId(remote);
    InnerOperation innerOperation = new InnerOperation(RESPONSE, GENERIC_OPERATION);
    OuterOperation outerOperation = new OuterOperation(innerOperation, partitionId);
    InternalCompletableFuture future = operationService.invokeOnPartition(null, outerOperation, partitionId);
    assertEquals(RESPONSE, future.join());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 73 with OperationService

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

the class Invocation_NetworkSplitTest method testWaitingInvocations_whenNodeSplitFromCluster.

private void testWaitingInvocations_whenNodeSplitFromCluster(SplitAction splitAction) throws Exception {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    Node node1 = TestUtil.getNode(hz1);
    Node node2 = TestUtil.getNode(hz2);
    Node node3 = TestUtil.getNode(hz3);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz2);
    NodeEngineImpl nodeEngine3 = node3.getNodeEngine();
    OperationService operationService3 = nodeEngine3.getOperationService();
    Operation op = new AlwaysBlockingOperation();
    Future<Object> future = operationService3.invokeOnPartition("", op, partitionId);
    // just wait a little to make sure
    // operation is landed on wait-queue
    sleepSeconds(1);
    // execute the given split action
    splitAction.run(node1, node2, node3);
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = node3.getClusterService();
    clusterService3.merge(node1.address);
    assertClusterSizeEventually(3, hz1);
    assertClusterSizeEventually(3, hz2);
    assertClusterSizeEventually(3, hz3);
    try {
        future.get(1, TimeUnit.MINUTES);
        fail("Future.get() should fail with a MemberLeftException!");
    } catch (MemberLeftException e) {
        // expected
        EmptyStatement.ignore(e);
    } catch (Exception e) {
        fail(e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 74 with OperationService

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

the class Invocation_RetryTest method whenTargetMemberDiesThenOperationAbortedWithMembersLeftException.

@Test(expected = MemberLeftException.class)
public void whenTargetMemberDiesThenOperationAbortedWithMembersLeftException() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance();
    HazelcastInstance remote = factory.newHazelcastInstance();
    warmUpPartitions(local, remote);
    OperationService service = getOperationService(local);
    Operation op = new TargetOperation();
    Address address = new Address(remote.getCluster().getLocalMember().getSocketAddress());
    Future future = service.createInvocationBuilder(null, op, address).invoke();
    sleepSeconds(1);
    remote.getLifecycleService().terminate();
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Future(java.util.concurrent.Future) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) OperationService(com.hazelcast.spi.OperationService) PartitionAwareOperation(com.hazelcast.spi.PartitionAwareOperation) 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)

Example 75 with OperationService

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

the class Invocation_DetectHeartbeatTimeoutTest method whenExpiresEventually.

/**
     * This test checks if the invocation expires eventually after the operation did manage to execute and did manage to send
     * some heartbeats but for whatever reason the response was not received.
     *
     * We do this by sending in a void operation that runs for an long period (so there are heartbeats) but on completion it
     * doesn't send a response.
     */
@Test
public void whenExpiresEventually() {
    Config config = new Config();
    config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "5000");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    OperationService opService = getOperationService(local);
    Operation operation = new VoidOperation(SECONDS.toMillis(20));
    InvocationFuture future = (InvocationFuture) opService.invokeOnPartition(null, operation, getPartitionId(remote));
    Invocation invocation = future.invocation;
    assertDetectHeartbeatTimeoutEventually(invocation, NO_TIMEOUT__CALL_TIMEOUT_NOT_EXPIRED);
    assertDetectHeartbeatTimeoutEventually(invocation, NO_TIMEOUT__HEARTBEAT_TIMEOUT_NOT_EXPIRED);
    assertDetectHeartbeatTimeoutEventually(invocation, TIMEOUT);
}
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