Search in sources :

Example 1 with Offload

use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.

the class OperationRunnerImpl method call.

private void call(Operation op) throws Exception {
    CallStatus callStatus = op.call();
    switch(callStatus.ordinal()) {
        case RESPONSE_ORDINAL:
            int backupAcks = backupHandler.sendBackups(op);
            Object response = op.getResponse();
            if (backupAcks > 0) {
                response = new NormalResponse(response, op.getCallId(), backupAcks, op.isUrgent());
            }
            try {
                op.sendResponse(response);
            } catch (ResponseAlreadySentException e) {
                logOperationError(op, e);
            }
            afterRun(op);
            break;
        case VOID_ORDINAL:
            backupHandler.sendBackups(op);
            afterRun(op);
            break;
        case OFFLOAD_ORDINAL:
            op.afterRun();
            Offload offload = (Offload) callStatus;
            offload.init(nodeEngine, operationService.asyncOperations);
            offload.start();
            break;
        case WAIT_ORDINAL:
            nodeEngine.getOperationParker().park((BlockingOperation) op);
            break;
        default:
            throw new IllegalStateException();
    }
}
Also used : CallStatus(com.hazelcast.spi.impl.operationservice.CallStatus) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ResponseAlreadySentException(com.hazelcast.spi.exception.ResponseAlreadySentException) Offload(com.hazelcast.spi.impl.operationservice.Offload)

Example 2 with Offload

use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.

the class Invocation_OffloadedTest method whenStartThrowsException_thenExceptionPropagated.

@Test(expected = ExpectedRuntimeException.class)
public void whenStartThrowsException_thenExceptionPropagated() {
    InternalCompletableFuture f = localOperationService.invokeOnPartition(new OffloadingOperation(op -> new Offload(op) {

        @Override
        public void start() {
            throw new ExpectedRuntimeException();
        }
    }));
    assertCompletesEventually(f);
    f.joinInternal();
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) Offload(com.hazelcast.spi.impl.operationservice.Offload) CallStatus(com.hazelcast.spi.impl.operationservice.CallStatus) QuickTest(com.hazelcast.test.annotation.QuickTest) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Operation(com.hazelcast.spi.impl.operationservice.Operation) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Offload(com.hazelcast.spi.impl.operationservice.Offload) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with Offload

use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.

the class Invocation_OffloadedTest method whenOffloaded_thenAsyncOperationRegisteredOnStart_andUnregisteredOnCompletion.

@Test
public void whenOffloaded_thenAsyncOperationRegisteredOnStart_andUnregisteredOnCompletion() {
    OffloadingOperation source = new OffloadingOperation(op -> new Offload(op) {

        @Override
        public void start() {
            // we make sure that the operation is registered
            assertTrue(localOperationService.asyncOperations.contains(offloadedOperation()));
            offloadedOperation().sendResponse("someresponse");
        }
    });
    InternalCompletableFuture<String> f = localOperationService.invokeOnPartition(source);
    assertCompletesEventually(f);
    // make sure the source operation isn't registered anymore
    assertFalse(localOperationService.asyncOperations.contains(source));
}
Also used : Offload(com.hazelcast.spi.impl.operationservice.Offload) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with Offload

use of com.hazelcast.spi.impl.operationservice.Offload in project hazelcast by hazelcast.

the class Invocation_OffloadedTest method whenCompletesInStart.

@Test
public void whenCompletesInStart() throws Exception {
    final String response = "someresponse";
    OffloadingOperation source = new OffloadingOperation(op -> new Offload(op) {

        @Override
        public void start() {
            offloadedOperation().sendResponse("someresponse");
        }
    });
    InternalCompletableFuture<String> f = localOperationService.invokeOnPartition(source);
    assertCompletesEventually(f);
    assertEquals(response, f.get());
    // make sure the source operation isn't registered anymore
    assertFalse(localOperationService.asyncOperations.contains(source));
}
Also used : Offload(com.hazelcast.spi.impl.operationservice.Offload) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Offload (com.hazelcast.spi.impl.operationservice.Offload)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 CallStatus (com.hazelcast.spi.impl.operationservice.CallStatus)2 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ResponseAlreadySentException (com.hazelcast.spi.exception.ResponseAlreadySentException)1 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 NormalResponse (com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse)1 ClusterProperty (com.hazelcast.spi.properties.ClusterProperty)1 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)1 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)1 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)1 HazelcastTestSupport (com.hazelcast.test.HazelcastTestSupport)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1