Search in sources :

Example 31 with Operation

use of com.hazelcast.spi.Operation 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)

Example 32 with Operation

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

the class OperationRunnerImplTest method runOperation_whenGeneric.

@Test
public void runOperation_whenGeneric() {
    final AtomicLong counter = new AtomicLong();
    final Object response = "someresponse";
    Operation op = new Operation() {

        @Override
        public void run() throws Exception {
            counter.incrementAndGet();
        }

        @Override
        public Object getResponse() {
            return response;
        }
    };
    op.setPartitionId(-1);
    op.setOperationResponseHandler(responseHandler);
    operationRunner.run(op);
    assertEquals(1, counter.get());
    verify(responseHandler).sendResponse(op, response);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 33 with Operation

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

the class Invocation_DetectHeartbeatTimeoutTest method whenCallTimeoutNotExpired.

@Test
public void whenCallTimeoutNotExpired() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance();
    HazelcastInstance remote = factory.newHazelcastInstance();
    OperationService opService = getOperationService(local);
    Operation operation = new SlowOperation(SECONDS.toMillis(60));
    InvocationFuture future = (InvocationFuture) opService.invokeOnPartition(null, operation, getPartitionId(remote));
    Invocation invocation = future.invocation;
    assertEquals(NO_TIMEOUT__CALL_TIMEOUT_NOT_EXPIRED, invocation.detectTimeout(SECONDS.toMillis(1)));
    assertFalse(future.isDone());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)

Example 34 with Operation

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

the class Invocation_DetectHeartbeatTimeoutTest method whenResponseAvailable.

@Test
public void whenResponseAvailable() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance();
    HazelcastInstance remote = factory.newHazelcastInstance();
    OperationService opService = getOperationService(local);
    Operation operation = new SlowOperation(SECONDS.toMillis(60));
    InvocationFuture future = (InvocationFuture) opService.invokeOnPartition(null, operation, getPartitionId(remote));
    Invocation invocation = future.invocation;
    invocation.pendingResponse = "foo";
    invocation.backupsAcksExpected = 1;
    assertEquals(NO_TIMEOUT__RESPONSE_AVAILABLE, invocation.detectTimeout(SECONDS.toMillis(1)));
    assertFalse(future.isDone());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)

Example 35 with Operation

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

the class MapProxySupport method loadInternal.

/**
     * Maps keys to corresponding partitions and sends operations to them.
     */
protected void loadInternal(Iterable<Data> dataKeys, boolean replaceExistingValues) {
    Map<Integer, List<Data>> partitionIdToKeys = getPartitionIdToKeysMap(dataKeys);
    Iterable<Entry<Integer, List<Data>>> entries = partitionIdToKeys.entrySet();
    for (Entry<Integer, List<Data>> entry : entries) {
        Integer partitionId = entry.getKey();
        List<Data> correspondingKeys = entry.getValue();
        Operation operation = createLoadAllOperation(correspondingKeys, replaceExistingValues);
        operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
    }
    waitUntilLoaded();
}
Also used : Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) Data(com.hazelcast.nio.serialization.Data) Operation(com.hazelcast.spi.Operation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) AddInterceptorOperation(com.hazelcast.map.impl.operation.AddInterceptorOperation) RemoveInterceptorOperation(com.hazelcast.map.impl.operation.RemoveInterceptorOperation) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Aggregations

Operation (com.hazelcast.spi.Operation)216 QuickTest (com.hazelcast.test.annotation.QuickTest)60 Test (org.junit.Test)60 OperationService (com.hazelcast.spi.OperationService)39 ParallelTest (com.hazelcast.test.annotation.ParallelTest)39 Future (java.util.concurrent.Future)19 Member (com.hazelcast.core.Member)18 Address (com.hazelcast.nio.Address)18 Data (com.hazelcast.nio.serialization.Data)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 AssertTask (com.hazelcast.test.AssertTask)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)15 ArrayList (java.util.ArrayList)15 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)14 NodeEngine (com.hazelcast.spi.NodeEngine)14 BackupAwareOperation (com.hazelcast.spi.BackupAwareOperation)13 BlockingOperation (com.hazelcast.spi.BlockingOperation)13 MapOperation (com.hazelcast.map.impl.operation.MapOperation)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Config (com.hazelcast.config.Config)10