コード例 #1
0
  /**
   * Tests basic correctness of buffer-or-event interleaving and correct <code>null</code> return
   * value after receiving all end-of-partition events.
   *
   * <p>For buffer-or-event instances, it is important to verify that they have been set off to the
   * correct logical index.
   */
  @Test(timeout = 120 * 1000)
  public void testBasicGetNextLogic() throws Exception {
    // Setup
    final String testTaskName = "Test Task";
    final SingleInputGate ig1 =
        new SingleInputGate(
            testTaskName,
            new JobID(),
            new ExecutionAttemptID(),
            new IntermediateDataSetID(),
            0,
            3,
            mock(TaskActions.class),
            new UnregisteredTaskMetricsGroup.DummyTaskIOMetricGroup());
    final SingleInputGate ig2 =
        new SingleInputGate(
            testTaskName,
            new JobID(),
            new ExecutionAttemptID(),
            new IntermediateDataSetID(),
            0,
            5,
            mock(TaskActions.class),
            new UnregisteredTaskMetricsGroup.DummyTaskIOMetricGroup());

    final UnionInputGate union = new UnionInputGate(new SingleInputGate[] {ig1, ig2});

    assertEquals(
        ig1.getNumberOfInputChannels() + ig2.getNumberOfInputChannels(),
        union.getNumberOfInputChannels());

    final TestInputChannel[][] inputChannels =
        new TestInputChannel[][] {
          TestInputChannel.createInputChannels(ig1, 3), TestInputChannel.createInputChannels(ig2, 5)
        };

    inputChannels[0][0].readBuffer(); // 0 => 0
    inputChannels[0][0].readEndOfPartitionEvent(); // 0 => 0
    inputChannels[1][2].readBuffer(); // 2 => 5
    inputChannels[1][2].readEndOfPartitionEvent(); // 2 => 5
    inputChannels[1][0].readBuffer(); // 0 => 3
    inputChannels[1][1].readBuffer(); // 1 => 4
    inputChannels[0][1].readBuffer(); // 1 => 1
    inputChannels[1][3].readBuffer(); // 3 => 6
    inputChannels[0][1].readEndOfPartitionEvent(); // 1 => 1
    inputChannels[1][3].readEndOfPartitionEvent(); // 3 => 6
    inputChannels[0][2].readBuffer(); // 1 => 2
    inputChannels[0][2].readEndOfPartitionEvent(); // 1 => 2
    inputChannels[1][4].readBuffer(); // 4 => 7
    inputChannels[1][4].readEndOfPartitionEvent(); // 4 => 7
    inputChannels[1][1].readEndOfPartitionEvent(); // 0 => 3
    inputChannels[1][0].readEndOfPartitionEvent(); // 0 => 3

    SingleInputGateTest.verifyBufferOrEvent(union, true, 0);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 0);
    SingleInputGateTest.verifyBufferOrEvent(union, true, 5);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 5);
    SingleInputGateTest.verifyBufferOrEvent(union, true, 3);
    SingleInputGateTest.verifyBufferOrEvent(union, true, 4);
    SingleInputGateTest.verifyBufferOrEvent(union, true, 1);
    SingleInputGateTest.verifyBufferOrEvent(union, true, 6);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 1);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 6);
    SingleInputGateTest.verifyBufferOrEvent(union, true, 2);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 2);
    SingleInputGateTest.verifyBufferOrEvent(union, true, 7);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 7);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 4);
    SingleInputGateTest.verifyBufferOrEvent(union, false, 3);

    // Return null when the input gate has received all end-of-partition events
    assertTrue(union.isFinished());
    assertNull(union.getNextBufferOrEvent());
  }
コード例 #2
0
  /** Creates an input gate and all of its input channels. */
  public static SingleInputGate create(
      String owningTaskName,
      JobID jobId,
      ExecutionAttemptID executionId,
      InputGateDeploymentDescriptor igdd,
      NetworkEnvironment networkEnvironment) {

    final IntermediateDataSetID consumedResultId = checkNotNull(igdd.getConsumedResultId());

    final int consumedSubpartitionIndex = igdd.getConsumedSubpartitionIndex();
    checkArgument(consumedSubpartitionIndex >= 0);

    final InputChannelDeploymentDescriptor[] icdd =
        checkNotNull(igdd.getInputChannelDeploymentDescriptors());

    final SingleInputGate inputGate =
        new SingleInputGate(
            owningTaskName,
            jobId,
            executionId,
            consumedResultId,
            consumedSubpartitionIndex,
            icdd.length,
            networkEnvironment.getPartitionStateChecker());

    // Create the input channels. There is one input channel for each consumed partition.
    final InputChannel[] inputChannels = new InputChannel[icdd.length];

    for (int i = 0; i < inputChannels.length; i++) {

      final ResultPartitionID partitionId = icdd[i].getConsumedPartitionId();
      final ResultPartitionLocation partitionLocation = icdd[i].getConsumedPartitionLocation();

      if (partitionLocation.isLocal()) {
        inputChannels[i] =
            new LocalInputChannel(
                inputGate,
                i,
                partitionId,
                networkEnvironment.getPartitionManager(),
                networkEnvironment.getTaskEventDispatcher(),
                networkEnvironment.getPartitionRequestInitialAndMaxBackoff());
      } else if (partitionLocation.isRemote()) {
        inputChannels[i] =
            new RemoteInputChannel(
                inputGate,
                i,
                partitionId,
                partitionLocation.getConnectionId(),
                networkEnvironment.getConnectionManager(),
                networkEnvironment.getPartitionRequestInitialAndMaxBackoff());
      } else if (partitionLocation.isUnknown()) {
        inputChannels[i] =
            new UnknownInputChannel(
                inputGate,
                i,
                partitionId,
                networkEnvironment.getPartitionManager(),
                networkEnvironment.getTaskEventDispatcher(),
                networkEnvironment.getConnectionManager(),
                networkEnvironment.getPartitionRequestInitialAndMaxBackoff());
      } else {
        throw new IllegalStateException("Unexpected partition location.");
      }

      inputGate.setInputChannel(partitionId.getPartitionId(), inputChannels[i]);
    }

    LOG.debug("Created input channels {} from {}.", Arrays.toString(inputChannels), igdd);

    return inputGate;
  }