Search in sources :

Example 1 with IntegerTaskEvent

use of org.apache.flink.runtime.event.task.IntegerTaskEvent in project flink by apache.

the class NettyMessageSerializationTest method testEncodeDecode.

@Test
public void testEncodeDecode() {
    {
        Buffer buffer = spy(new Buffer(MemorySegmentFactory.allocateUnpooledSegment(1024), mock(BufferRecycler.class)));
        ByteBuffer nioBuffer = buffer.getNioBuffer();
        for (int i = 0; i < 1024; i += 4) {
            nioBuffer.putInt(i);
        }
        NettyMessage.BufferResponse expected = new NettyMessage.BufferResponse(buffer, random.nextInt(), new InputChannelID());
        NettyMessage.BufferResponse actual = encodeAndDecode(expected);
        // Verify recycle has been called on buffer instance
        verify(buffer, times(1)).recycle();
        final ByteBuf retainedSlice = actual.getNettyBuffer();
        // Ensure not recycled and same size as original buffer
        assertEquals(1, retainedSlice.refCnt());
        assertEquals(1024, retainedSlice.readableBytes());
        nioBuffer = retainedSlice.nioBuffer();
        for (int i = 0; i < 1024; i += 4) {
            assertEquals(i, nioBuffer.getInt());
        }
        // Release the retained slice
        actual.releaseBuffer();
        assertEquals(0, retainedSlice.refCnt());
        assertEquals(expected.sequenceNumber, actual.sequenceNumber);
        assertEquals(expected.receiverId, actual.receiverId);
    }
    {
        {
            IllegalStateException expectedError = new IllegalStateException();
            InputChannelID receiverId = new InputChannelID();
            NettyMessage.ErrorResponse expected = new NettyMessage.ErrorResponse(expectedError, receiverId);
            NettyMessage.ErrorResponse actual = encodeAndDecode(expected);
            assertEquals(expected.cause.getClass(), actual.cause.getClass());
            assertEquals(expected.cause.getMessage(), actual.cause.getMessage());
            assertEquals(receiverId, actual.receiverId);
        }
        {
            IllegalStateException expectedError = new IllegalStateException("Illegal illegal illegal");
            InputChannelID receiverId = new InputChannelID();
            NettyMessage.ErrorResponse expected = new NettyMessage.ErrorResponse(expectedError, receiverId);
            NettyMessage.ErrorResponse actual = encodeAndDecode(expected);
            assertEquals(expected.cause.getClass(), actual.cause.getClass());
            assertEquals(expected.cause.getMessage(), actual.cause.getMessage());
            assertEquals(receiverId, actual.receiverId);
        }
        {
            IllegalStateException expectedError = new IllegalStateException("Illegal illegal illegal");
            NettyMessage.ErrorResponse expected = new NettyMessage.ErrorResponse(expectedError);
            NettyMessage.ErrorResponse actual = encodeAndDecode(expected);
            assertEquals(expected.cause.getClass(), actual.cause.getClass());
            assertEquals(expected.cause.getMessage(), actual.cause.getMessage());
            assertNull(actual.receiverId);
            assertTrue(actual.isFatalError());
        }
    }
    {
        NettyMessage.PartitionRequest expected = new NettyMessage.PartitionRequest(new ResultPartitionID(new IntermediateResultPartitionID(), new ExecutionAttemptID()), random.nextInt(), new InputChannelID());
        NettyMessage.PartitionRequest actual = encodeAndDecode(expected);
        assertEquals(expected.partitionId, actual.partitionId);
        assertEquals(expected.queueIndex, actual.queueIndex);
        assertEquals(expected.receiverId, actual.receiverId);
    }
    {
        NettyMessage.TaskEventRequest expected = new NettyMessage.TaskEventRequest(new IntegerTaskEvent(random.nextInt()), new ResultPartitionID(new IntermediateResultPartitionID(), new ExecutionAttemptID()), new InputChannelID());
        NettyMessage.TaskEventRequest actual = encodeAndDecode(expected);
        assertEquals(expected.event, actual.event);
        assertEquals(expected.partitionId, actual.partitionId);
        assertEquals(expected.receiverId, actual.receiverId);
    }
    {
        NettyMessage.CancelPartitionRequest expected = new NettyMessage.CancelPartitionRequest(new InputChannelID());
        NettyMessage.CancelPartitionRequest actual = encodeAndDecode(expected);
        assertEquals(expected.receiverId, actual.receiverId);
    }
    {
        NettyMessage.CloseRequest expected = new NettyMessage.CloseRequest();
        NettyMessage.CloseRequest actual = encodeAndDecode(expected);
        assertEquals(expected.getClass(), actual.getClass());
    }
}
Also used : Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) ByteBuffer(java.nio.ByteBuffer) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) IntegerTaskEvent(org.apache.flink.runtime.event.task.IntegerTaskEvent) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) BufferRecycler(org.apache.flink.runtime.io.network.buffer.BufferRecycler) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) Test(org.junit.Test)

Example 2 with IntegerTaskEvent

use of org.apache.flink.runtime.event.task.IntegerTaskEvent in project flink by apache.

the class TaskEventHandlerTest method testEventNotificationManager.

/**
	 * Tests the publish/subscribe mechanisms implemented in the {@link TaskEventHandler}.
	 */
@Test
public void testEventNotificationManager() {
    final TaskEventHandler evm = new TaskEventHandler();
    final TestEventListener listener = new TestEventListener();
    evm.subscribe(listener, StringTaskEvent.class);
    final StringTaskEvent stringTaskEvent1 = new StringTaskEvent("Test 1");
    final StringTaskEvent stringTaskEvent2 = new StringTaskEvent("Test 2");
    evm.publish(stringTaskEvent1);
    evm.publish(new IntegerTaskEvent(5));
    assertNotNull(listener.getLastReceivedEvent());
    StringTaskEvent receivedStringEvent = (StringTaskEvent) listener.getLastReceivedEvent();
    assertEquals(stringTaskEvent1, receivedStringEvent);
    evm.unsubscribe(listener, StringTaskEvent.class);
    evm.publish(stringTaskEvent2);
    assertNotNull(listener.getLastReceivedEvent());
    receivedStringEvent = (StringTaskEvent) listener.getLastReceivedEvent();
    assertEquals(stringTaskEvent1, receivedStringEvent);
}
Also used : IntegerTaskEvent(org.apache.flink.runtime.event.task.IntegerTaskEvent) StringTaskEvent(org.apache.flink.runtime.event.task.StringTaskEvent) TaskEventHandler(org.apache.flink.runtime.io.network.api.TaskEventHandler) Test(org.junit.Test)

Aggregations

IntegerTaskEvent (org.apache.flink.runtime.event.task.IntegerTaskEvent)2 Test (org.junit.Test)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBuffer (java.nio.ByteBuffer)1 StringTaskEvent (org.apache.flink.runtime.event.task.StringTaskEvent)1 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)1 TaskEventHandler (org.apache.flink.runtime.io.network.api.TaskEventHandler)1 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)1 BufferRecycler (org.apache.flink.runtime.io.network.buffer.BufferRecycler)1 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)1 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)1 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)1