Search in sources :

Example 1 with NoOpTaskActions

use of org.apache.flink.runtime.taskmanager.NoOpTaskActions in project flink by apache.

the class ResultPartitionTest method testAddOnFinishedPartition.

/**
 * Tests {@link ResultPartition#emitRecord} on a partition which has already finished.
 *
 * @param partitionType the result partition type to set up
 */
private void testAddOnFinishedPartition(final ResultPartitionType partitionType) throws Exception {
    TestResultPartitionConsumableNotifier notifier = new TestResultPartitionConsumableNotifier();
    BufferWritingResultPartition bufferWritingResultPartition = createResultPartition(partitionType);
    ResultPartitionWriter partitionWriter = ConsumableNotifyingResultPartitionWriterDecorator.decorate(Collections.singleton(PartitionTestUtils.createPartitionDeploymentDescriptor(partitionType)), new ResultPartitionWriter[] { bufferWritingResultPartition }, new NoOpTaskActions(), new JobID(), notifier)[0];
    try {
        partitionWriter.finish();
        notifier.reset();
        // partitionWriter.emitRecord() should fail
        partitionWriter.emitRecord(ByteBuffer.allocate(bufferSize), 0);
    } catch (IllegalStateException e) {
    // expected => ignored
    } finally {
        assertEquals(0, bufferWritingResultPartition.numBuffersOut.getCount());
        assertEquals(0, bufferWritingResultPartition.numBytesOut.getCount());
        assertEquals(0, bufferWritingResultPartition.getBufferPool().bestEffortGetNumOfUsedBuffers());
        // should not have notified either
        notifier.check(null, null, null, 0);
    }
}
Also used : ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) JobID(org.apache.flink.api.common.JobID)

Example 2 with NoOpTaskActions

use of org.apache.flink.runtime.taskmanager.NoOpTaskActions in project flink by apache.

the class ResultPartitionTest method testAddOnReleasedPartition.

/**
 * Tests {@link ResultPartition#emitRecord} on a partition which has already been released.
 *
 * @param partitionType the result partition type to set up
 */
private void testAddOnReleasedPartition(ResultPartitionType partitionType) throws Exception {
    TestResultPartitionConsumableNotifier notifier = new TestResultPartitionConsumableNotifier();
    BufferWritingResultPartition bufferWritingResultPartition = createResultPartition(partitionType);
    ResultPartitionWriter partitionWriter = ConsumableNotifyingResultPartitionWriterDecorator.decorate(Collections.singleton(PartitionTestUtils.createPartitionDeploymentDescriptor(partitionType)), new ResultPartitionWriter[] { bufferWritingResultPartition }, new NoOpTaskActions(), new JobID(), notifier)[0];
    try {
        partitionWriter.release(null);
        // partitionWriter.emitRecord() should silently drop the given record
        partitionWriter.emitRecord(ByteBuffer.allocate(bufferSize), 0);
    } finally {
        assertEquals(1, bufferWritingResultPartition.numBuffersOut.getCount());
        assertEquals(bufferSize, bufferWritingResultPartition.numBytesOut.getCount());
        // the buffer should be recycled for the result partition has already been released
        assertEquals(0, bufferWritingResultPartition.getBufferPool().bestEffortGetNumOfUsedBuffers());
        // should not have notified either
        notifier.check(null, null, null, 0);
    }
}
Also used : ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) JobID(org.apache.flink.api.common.JobID)

Example 3 with NoOpTaskActions

use of org.apache.flink.runtime.taskmanager.NoOpTaskActions in project flink by apache.

the class ResultPartitionTest method testNumBytesProducedCounter.

private void testNumBytesProducedCounter(boolean isBroadcast) throws IOException {
    TestResultPartitionConsumableNotifier notifier = new TestResultPartitionConsumableNotifier();
    JobID jobId = new JobID();
    TaskActions taskActions = new NoOpTaskActions();
    BufferWritingResultPartition bufferWritingResultPartition = createResultPartition(ResultPartitionType.BLOCKING);
    ResultPartitionWriter partitionWriter = ConsumableNotifyingResultPartitionWriterDecorator.decorate(Collections.singleton(PartitionTestUtils.createPartitionDeploymentDescriptor(ResultPartitionType.BLOCKING)), new ResultPartitionWriter[] { bufferWritingResultPartition }, taskActions, jobId, notifier)[0];
    if (isBroadcast) {
        partitionWriter.broadcastRecord(ByteBuffer.allocate(bufferSize));
        assertEquals(bufferSize, bufferWritingResultPartition.numBytesProduced.getCount());
        assertEquals(2 * bufferSize, bufferWritingResultPartition.numBytesOut.getCount());
    } else {
        partitionWriter.emitRecord(ByteBuffer.allocate(bufferSize), 0);
        assertEquals(bufferSize, bufferWritingResultPartition.numBytesProduced.getCount());
        assertEquals(bufferSize, bufferWritingResultPartition.numBytesOut.getCount());
    }
}
Also used : ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) TaskActions(org.apache.flink.runtime.taskmanager.TaskActions) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) JobID(org.apache.flink.api.common.JobID)

Example 4 with NoOpTaskActions

use of org.apache.flink.runtime.taskmanager.NoOpTaskActions in project flink by apache.

the class ResultPartitionTest method testAddOnPartition.

/**
 * Tests {@link ResultPartition#emitRecord} on a working partition.
 *
 * @param partitionType the result partition type to set up
 */
private void testAddOnPartition(final ResultPartitionType partitionType) throws Exception {
    TestResultPartitionConsumableNotifier notifier = new TestResultPartitionConsumableNotifier();
    JobID jobId = new JobID();
    TaskActions taskActions = new NoOpTaskActions();
    BufferWritingResultPartition bufferWritingResultPartition = createResultPartition(partitionType);
    ResultPartitionWriter partitionWriter = ConsumableNotifyingResultPartitionWriterDecorator.decorate(Collections.singleton(PartitionTestUtils.createPartitionDeploymentDescriptor(partitionType)), new ResultPartitionWriter[] { bufferWritingResultPartition }, taskActions, jobId, notifier)[0];
    try {
        // partitionWriter.emitRecord() will allocate a new buffer and copies the record to it
        partitionWriter.emitRecord(ByteBuffer.allocate(bufferSize), 0);
    } finally {
        assertEquals(1, bufferWritingResultPartition.numBuffersOut.getCount());
        assertEquals(bufferSize, bufferWritingResultPartition.numBytesOut.getCount());
        assertEquals(1, bufferWritingResultPartition.getBufferPool().bestEffortGetNumOfUsedBuffers());
        // should have been notified for pipelined partitions
        if (partitionType.isPipelined()) {
            notifier.check(jobId, partitionWriter.getPartitionId(), taskActions, 1);
        }
    }
}
Also used : ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) TaskActions(org.apache.flink.runtime.taskmanager.TaskActions) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) JobID(org.apache.flink.api.common.JobID)

Example 5 with NoOpTaskActions

use of org.apache.flink.runtime.taskmanager.NoOpTaskActions in project flink by apache.

the class ResultPartitionTest method testNotifyPartitionDataAvailable.

private void testNotifyPartitionDataAvailable(FutureConsumerWithException<ResultPartitionWriter, Exception> notificationCall) throws Exception {
    JobID jobId = new JobID();
    TaskActions taskActions = new NoOpTaskActions();
    {
        // Pipelined, send message => notify
        TestResultPartitionConsumableNotifier notifier = new TestResultPartitionConsumableNotifier();
        ResultPartitionWriter consumableNotifyingPartitionWriter = createConsumableNotifyingResultPartitionWriter(ResultPartitionType.PIPELINED, taskActions, jobId, notifier);
        notificationCall.accept(consumableNotifyingPartitionWriter);
        notifier.check(jobId, consumableNotifyingPartitionWriter.getPartitionId(), taskActions, 1);
    }
    {
        // Blocking, send message => don't notify
        TestResultPartitionConsumableNotifier notifier = new TestResultPartitionConsumableNotifier();
        ResultPartitionWriter partition = createConsumableNotifyingResultPartitionWriter(ResultPartitionType.BLOCKING, taskActions, jobId, notifier);
        notificationCall.accept(partition);
        notifier.check(null, null, null, 0);
    }
}
Also used : ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) TaskActions(org.apache.flink.runtime.taskmanager.TaskActions) NoOpTaskActions(org.apache.flink.runtime.taskmanager.NoOpTaskActions) JobID(org.apache.flink.api.common.JobID)

Aggregations

JobID (org.apache.flink.api.common.JobID)5 ResultPartitionWriter (org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter)5 NoOpTaskActions (org.apache.flink.runtime.taskmanager.NoOpTaskActions)5 TaskActions (org.apache.flink.runtime.taskmanager.TaskActions)3