Search in sources :

Example 6 with OperationRunner

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);
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) AssertTask(com.hazelcast.test.AssertTask) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with OperationRunner

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());
        }
    });
}
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 8 with OperationRunner

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);
}
Also used : ILogger(com.hazelcast.logging.ILogger) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner)

Example 9 with OperationRunner

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());
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) OperationRunnerFactory(com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory) AssertTask(com.hazelcast.test.AssertTask) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with OperationRunner

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);
}
Also used : OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)13 Operation (com.hazelcast.spi.Operation)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 AssertTask (com.hazelcast.test.AssertTask)4 Packet (com.hazelcast.nio.Packet)3 OperationHostileThread (com.hazelcast.spi.impl.operationexecutor.OperationHostileThread)2 OperationRunnerFactory (com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory)2 HazelcastThreadGroup (com.hazelcast.instance.HazelcastThreadGroup)1 NodeExtension (com.hazelcast.instance.NodeExtension)1 MPSCQueue (com.hazelcast.internal.util.concurrent.MPSCQueue)1 ILogger (com.hazelcast.logging.ILogger)1 UrgentSystemOperation (com.hazelcast.spi.UrgentSystemOperation)1 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)1 PartitionOperationThread (com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread)1 Backup (com.hazelcast.spi.impl.operationservice.impl.operations.Backup)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1