Search in sources :

Example 1 with PartitionSpecificRunnable

use of com.hazelcast.spi.impl.PartitionSpecificRunnable in project hazelcast by hazelcast.

the class OperationExecutorImpl_ExecutePartitionSpecificRunnableTest method whenPartitionSpecific.

@Test
public void whenPartitionSpecific() {
    initExecutor();
    final AtomicReference<Thread> executingThead = new AtomicReference<Thread>();
    PartitionSpecificRunnable task = new PartitionSpecificRunnable() {

        @Override
        public void run() {
            executingThead.set(Thread.currentThread());
        }

        @Override
        public int getPartitionId() {
            return 0;
        }
    };
    executor.execute(task);
    assertTrueEventually(new AssertTask() {

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

Example 2 with PartitionSpecificRunnable

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

Example 3 with PartitionSpecificRunnable

use of com.hazelcast.spi.impl.PartitionSpecificRunnable in project hazelcast by hazelcast.

the class OperationThreadTest method testExecute_withInvalid_partitionId.

private void testExecute_withInvalid_partitionId(Object task) {
    handlerFactory = mock(OperationRunnerFactory.class);
    OperationRunner handler = mock(OperationRunner.class);
    when(handlerFactory.createGenericRunner()).thenReturn(handler);
    when(handlerFactory.createPartitionRunner(anyInt())).thenReturn(handler);
    initExecutor();
    if (task instanceof Operation) {
        executor.execute((Operation) task);
    } else if (task instanceof PartitionSpecificRunnable) {
        executor.execute((PartitionSpecificRunnable) task);
    } else if (task instanceof Packet) {
        executor.handle((Packet) task);
    } else {
        fail("invalid task!");
    }
    final Runnable emptyRunnable = new Runnable() {

        @Override
        public void run() {
        }
    };
    executor.executeOnPartitionThreads(emptyRunnable);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, executor.getPriorityQueueSize());
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) OperationRunnerFactory(com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) AssertTask(com.hazelcast.test.AssertTask) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) Operation(com.hazelcast.spi.Operation) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable)

Example 4 with PartitionSpecificRunnable

use of com.hazelcast.spi.impl.PartitionSpecificRunnable in project hazelcast by hazelcast.

the class LockServiceImpl method destroyDistributedObject.

@Override
public void destroyDistributedObject(String objectId) {
    final Data key = nodeEngine.getSerializationService().toData(objectId, StringPartitioningStrategy.INSTANCE);
    final int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    final LockStoreImpl lockStore = containers[partitionId].getLockStore(new InternalLockNamespace(objectId));
    if (lockStore != null) {
        InternalOperationService operationService = (InternalOperationService) nodeEngine.getOperationService();
        operationService.execute(new PartitionSpecificRunnable() {

            @Override
            public void run() {
                lockStore.forceUnlock(key);
            }

            @Override
            public int getPartitionId() {
                return partitionId;
            }
        });
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 5 with PartitionSpecificRunnable

use of com.hazelcast.spi.impl.PartitionSpecificRunnable in project hazelcast by hazelcast.

the class OperationThreadTest method executePartitionSpecificRunnable_withInvalid_partitionId.

@Test
public void executePartitionSpecificRunnable_withInvalid_partitionId() {
    final int partitionId = Integer.MAX_VALUE;
    testExecute_withInvalid_partitionId(new PartitionSpecificRunnable() {

        @Override
        public int getPartitionId() {
            return partitionId;
        }

        @Override
        public void run() {
        }
    });
}
Also used : PartitionSpecificRunnable(com.hazelcast.spi.impl.PartitionSpecificRunnable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)7 AssertTask (com.hazelcast.test.AssertTask)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Operation (com.hazelcast.spi.Operation)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Packet (com.hazelcast.nio.Packet)2 Data (com.hazelcast.nio.serialization.Data)1 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)1 OperationRunnerFactory (com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory)1 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)1 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1