Search in sources :

Example 96 with Operation

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

the class OperationExecutorImpl_GetOperationRunnerTest method test_whenCallerIsNormalThread_andGenericOperation_thenReturnAdHocRunner.

@Test
public void test_whenCallerIsNormalThread_andGenericOperation_thenReturnAdHocRunner() {
    initExecutor();
    Operation op = new DummyOperation(-1);
    OperationRunner operationRunner = executor.getOperationRunner(op);
    DummyOperationRunnerFactory f = (DummyOperationRunnerFactory) handlerFactory;
    assertSame(f.adhocHandler, operationRunner);
}
Also used : OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 97 with Operation

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

the class OperationExecutorImpl_IsInvocationAllowedTest method test_whenPartitionOperation_andCallingFromOperationHostileThread_andAsync.

@Test
public void test_whenPartitionOperation_andCallingFromOperationHostileThread_andAsync() {
    initExecutor();
    final Operation operation = new DummyOperation(1);
    FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return executor.isInvocationAllowed(operation, true);
        }
    });
    DummyOperationHostileThread thread = new DummyOperationHostileThread(futureTask);
    thread.start();
    assertEqualsEventually(futureTask, FALSE);
}
Also used : FutureTask(java.util.concurrent.FutureTask) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 98 with Operation

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

the class OperationExecutorImpl_IsInvocationAllowedTest method test_whenPartitionOperation_andCallingFromOperationHostileThread.

@Test
public void test_whenPartitionOperation_andCallingFromOperationHostileThread() {
    initExecutor();
    final Operation operation = new DummyOperation(1);
    FutureTask<Boolean> futureTask = new FutureTask<Boolean>(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return executor.isInvocationAllowed(operation, false);
        }
    });
    DummyOperationHostileThread thread = new DummyOperationHostileThread(futureTask);
    thread.start();
    assertEqualsEventually(futureTask, FALSE);
}
Also used : FutureTask(java.util.concurrent.FutureTask) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 99 with Operation

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

the class OperationExecutorImpl_RunOrExecuteTest method whenPartitionOperation_andCallingFromOperationHostileThread.

@Test
public void whenPartitionOperation_andCallingFromOperationHostileThread() {
    initExecutor();
    final AtomicReference<Thread> executingThread = new AtomicReference<Thread>();
    final Operation operation = new ThreadCapturingOperation(executingThread).setPartitionId(0);
    DummyOperationHostileThread thread = new DummyOperationHostileThread(new Runnable() {

        @Override
        public void run() {
            executor.runOrExecute(operation);
        }
    });
    thread.start();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertInstanceOf(PartitionOperationThread.class, executingThread.get());
        }
    });
}
Also used : PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) AssertTask(com.hazelcast.test.AssertTask) AtomicReference(java.util.concurrent.atomic.AtomicReference) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 100 with Operation

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

the class OperationExecutorImpl_RunOrExecuteTest method whenPartitionOperation_andCallingFromGenericThread.

@Test
public void whenPartitionOperation_andCallingFromGenericThread() {
    initExecutor();
    final AtomicReference<Thread> executingThread = new AtomicReference<Thread>();
    final Operation operation = new ThreadCapturingOperation(executingThread).setPartitionId(0);
    executor.execute(new PartitionSpecificRunnable() {

        @Override
        public int getPartitionId() {
            return -1;
        }

        @Override
        public void run() {
            executor.runOrExecute(operation);
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertInstanceOf(PartitionOperationThread.class, executingThread.get());
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) AtomicReference(java.util.concurrent.atomic.AtomicReference) Operation(com.hazelcast.spi.Operation) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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