コード例 #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());
  }