use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationExecutorImpl_HandlePacketTest method test_whenGenericOperationPacket.
@Test
public void test_whenGenericOperationPacket() {
initExecutor();
final DummyOperation operation = new DummyOperation(Operation.GENERIC_PARTITION_ID);
final Packet packet = new Packet(serializationService.toBytes(operation), operation.getPartitionId()).setPacketType(Packet.Type.OPERATION);
executor.handle(packet);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
OperationRunner[] genericHandlers = executor.getGenericOperationRunners();
boolean found = false;
for (OperationRunner h : genericHandlers) {
DummyOperationRunner dummyOperationHandler = (DummyOperationRunner) h;
if (dummyOperationHandler.packets.contains(packet)) {
found = true;
break;
}
}
assertTrue("Packet is not found on any of the generic handlers", found);
}
});
}
use of com.hazelcast.spi.impl.operationexecutor.OperationRunner 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.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationThreadTest method createNewOperationThread.
private PartitionOperationThread createNewOperationThread(OperationQueue mockOperationQueue) {
ILogger mockLogger = mock(ILogger.class);
OperationRunner[] runners = new OperationRunner[0];
return new PartitionOperationThread("threadName", 0, mockOperationQueue, mockLogger, threadGroup, nodeExtension, runners);
}
use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationThreadTest method testOOME_whenDeserializing.
@Test
public void testOOME_whenDeserializing() throws Exception {
handlerFactory = mock(OperationRunnerFactory.class);
OperationRunner handler = mock(OperationRunner.class);
when(handlerFactory.createGenericRunner()).thenReturn(handler);
when(handlerFactory.createPartitionRunner(anyInt())).thenReturn(handler);
initExecutor();
DummyOperation operation = new DummyOperation(Operation.GENERIC_PARTITION_ID);
Packet packet = new Packet(serializationService.toBytes(operation), operation.getPartitionId()).setPacketType(Packet.Type.OPERATION);
doThrow(new OutOfMemoryError()).when(handler).run(packet);
final int oldCount = OutOfMemoryErrorDispatcher.getOutOfMemoryErrorCount();
executor.handle(packet);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(oldCount + 1, OutOfMemoryErrorDispatcher.getOutOfMemoryErrorCount());
}
});
}
use of com.hazelcast.spi.impl.operationexecutor.OperationRunner in project hazelcast by hazelcast.
the class OperationExecutorImpl_GetOperationRunnerTest method test_whenPartitionSpecificOperation_thenReturnCorrectPartitionOperationRunner.
@Test
public void test_whenPartitionSpecificOperation_thenReturnCorrectPartitionOperationRunner() {
initExecutor();
int partitionId = 0;
Operation op = new DummyOperation(partitionId);
OperationRunner runner = executor.getOperationRunner(op);
assertSame(executor.getPartitionOperationRunners()[partitionId], runner);
}
Aggregations