@Test
  public void testProcessWithOccasionalBlocks() throws Exception {
    List elements = new ArrayList();
    elements.add(new ElementSymbol("a")); // $NON-NLS-1$

    HashSet blocked =
        new HashSet(Arrays.asList(new Integer[] {new Integer(0), new Integer(2), new Integer(7)}));
    int numBatches = 10;
    int batchRow = 1;
    int rowsPerBatch = 50;
    List[] expectedResults = new List[rowsPerBatch * (numBatches - blocked.size())];
    List batches = new ArrayList();
    for (int b = 0; b < numBatches; b++) {
      if (blocked.contains(new Integer(b))) {
        batches.add(BlockedException.INSTANCE);
      } else {
        List[] rows = new List[rowsPerBatch];
        for (int i = 0; i < rowsPerBatch; i++) {
          rows[i] = new ArrayList();
          rows[i].add(new Integer(batchRow));
          expectedResults[batchRow - 1] = rows[i];
          batchRow++;
        }

        TupleBatch batch = new TupleBatch(batchRow - rows.length, rows);
        if (b == numBatches - 1) {
          batch.setTerminationFlag(true);
        }
        batches.add(batch);
      }
    }

    FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
    helpTestProcessor(plan, expectedResults);
  }
  @Test
  public void testBlockNoResults() throws Exception {
    List elements = new ArrayList();
    elements.add(new ElementSymbol("a")); // $NON-NLS-1$

    List batches = new ArrayList();
    batches.add(BlockedException.INSTANCE);
    TupleBatch batch = new TupleBatch(1, new List[0]);
    batch.setTerminationFlag(true);
    batches.add(batch);

    FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
    helpTestProcessor(plan, new List[0]);
  }
Beispiel #3
0
  protected TupleBatch pullBatch() {
    TupleBatch batch = null;
    if (this.batchRows != null) {
      batch = new TupleBatch(this.beginBatch, this.batchRows);
      beginBatch += this.batchRows.size();
    } else {
      batch = new TupleBatch(this.beginBatch, Collections.EMPTY_LIST);
    }

    batch.setTerminationFlag(this.lastBatch);

    // Reset batch state
    this.batchRows = null;
    this.lastBatch = false;

    // Return batch
    return batch;
  }
Beispiel #4
0
  /** @see ProcessorPlan#nextBatch() */
  public TupleBatch nextBatchDirect()
      throws TeiidComponentException, TeiidProcessingException, BlockedException {

    // Already returned results?
    if (done) {
      // Already returned all results
      TupleBatch emptyTerminationBatch = new TupleBatch(beginBatch, new List[0]);
      emptyTerminationBatch.setTerminationFlag(true);
      return emptyTerminationBatch;
    }
    // First attempt to process
    if (this.finalTupleSource == null) {
      // Still need to process - this should either
      // throw a BlockedException or return a finalTupleSource
      this.finalTupleSource = processProcedure();
    }

    // Next, attempt to return batches if processing completed
    while (!isBatchFull()) {
      // May throw BlockedException and exit here
      List<?> tuple = this.finalTupleSource.nextTuple();
      if (tuple == null) {
        if (outParams != null) {
          VariableContext vc = getCurrentVariableContext();
          List<Object> paramTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
          int i = this.getOutputElements().size() - this.outParams.size();
          for (ElementSymbol param : outParams) {
            Object value = vc.getValue(param);
            checkNotNull(param, value);
            paramTuple.set(i++, value);
          }
          addBatchRow(paramTuple, true);
        }
        terminateBatches();
        done = true;
        break;
      }
      addBatchRow(tuple, false);
    }

    return pullBatch();
  }