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());
}
});
}
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());
}
});
}
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());
}
});
}
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;
}
});
}
}
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() {
}
});
}
Aggregations