示例#1
0
  @Test
  public void testAbruptFinish() {
    List<Type> types = ImmutableList.<Type>of(VARCHAR, BIGINT, BIGINT);
    ValuesOperator source =
        new ValuesOperator(
            driverContext.addOperatorContext(0, new PlanNodeId("test"), "values"),
            types,
            rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());

    PageConsumerOperator sink = createSinkOperator(source);
    Driver driver = new Driver(driverContext, source, sink);

    assertSame(driver.getDriverContext(), driverContext);

    assertFalse(driver.isFinished());
    driver.close();
    assertTrue(driver.isFinished());

    // finish is only called in normal operations
    assertFalse(source.isFinished());
    assertFalse(sink.isFinished());

    // close is always called (values operator doesn't have a closed state)
    assertTrue(sink.isClosed());
  }
示例#2
0
  @Test
  public void testAddSourceFinish() {
    PlanNodeId sourceId = new PlanNodeId("source");
    final List<Type> types = ImmutableList.<Type>of(VARCHAR, BIGINT, BIGINT);
    TableScanOperator source =
        new TableScanOperator(
            driverContext.addOperatorContext(99, new PlanNodeId("test"), "values"),
            sourceId,
            new PageSourceProvider() {
              @Override
              public ConnectorPageSource createPageSource(
                  Session session, Split split, List<ColumnHandle> columns) {
                return new FixedPageSource(
                    rowPagesBuilder(types).addSequencePage(10, 20, 30, 40).build());
              }
            },
            types,
            ImmutableList.<ColumnHandle>of());

    PageConsumerOperator sink = createSinkOperator(source);
    Driver driver = new Driver(driverContext, source, sink);

    assertSame(driver.getDriverContext(), driverContext);

    assertFalse(driver.isFinished());
    assertFalse(driver.processFor(new Duration(1, TimeUnit.MILLISECONDS)).isDone());
    assertFalse(driver.isFinished());

    driver.updateSource(
        new TaskSource(
            sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, newMockSplit())), true));

    assertFalse(driver.isFinished());
    assertTrue(driver.processFor(new Duration(1, TimeUnit.SECONDS)).isDone());
    assertTrue(driver.isFinished());

    assertTrue(sink.isFinished());
    assertTrue(source.isFinished());
  }