示例#1
0
 public MockProcessSession(final SharedSessionState sharedState, final Processor processor) {
   this.sharedState = sharedState;
   this.processorQueue = sharedState.getFlowFileQueue();
   provenanceReporter =
       new MockProvenanceReporter(
           this, sharedState, processor.getIdentifier(), processor.getClass().getSimpleName());
 }
  StandardProcessorTestRunner(final Processor processor) {
    this.processor = processor;
    this.idGenerator = new AtomicLong(0L);
    this.sharedState = new SharedSessionState(processor, idGenerator);
    this.flowFileQueue = sharedState.getFlowFileQueue();
    this.sessionFactory = new MockSessionFactory(sharedState, processor);
    this.processorStateManager = new MockStateManager(processor);
    this.context = new MockProcessContext(processor, processorStateManager);

    detectDeprecatedAnnotations(processor);

    final MockProcessorInitializationContext mockInitContext =
        new MockProcessorInitializationContext(processor, context);
    processor.initialize(mockInitContext);
    logger = mockInitContext.getLogger();

    try {
      ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, processor);
    } catch (final Exception e) {
      Assert.fail("Could not invoke methods annotated with @OnAdded annotation due to: " + e);
    }

    triggerSerially = null != processor.getClass().getAnnotation(TriggerSerially.class);

    ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, processor);
  }
示例#3
0
 @Override
 public MockFlowFile create() {
   final MockFlowFile flowFile = new MockFlowFile(sharedState.nextFlowFileId());
   currentVersions.put(flowFile.getId(), flowFile);
   beingProcessed.add(flowFile.getId());
   return flowFile;
 }
示例#4
0
 @Override
 public MockFlowFile clone(final FlowFile flowFile) {
   validateState(flowFile);
   final MockFlowFile newFlowFile = new MockFlowFile(sharedState.nextFlowFileId(), flowFile);
   currentVersions.put(newFlowFile.getId(), newFlowFile);
   beingProcessed.add(newFlowFile.getId());
   return newFlowFile;
 }
示例#5
0
  @Override
  public void adjustCounter(final String name, final long delta, final boolean immediate) {
    if (immediate) {
      sharedState.adjustCounter(name, delta);
      return;
    }

    Long counter = counterMap.get(name);
    if (counter == null) {
      counter = delta;
      counterMap.put(name, counter);
      return;
    }

    counter = counter + delta;
    counterMap.put(name, counter);
  }
示例#6
0
  @Override
  public void commit() {
    if (!beingProcessed.isEmpty()) {
      throw new FlowFileHandlingException(
          "Cannot commit session because the following FlowFiles have not been removed or transferred: "
              + beingProcessed);
    }
    committed = true;
    beingProcessed.clear();
    currentVersions.clear();
    originalVersions.clear();

    for (final Map.Entry<String, Long> entry : counterMap.entrySet()) {
      sharedState.adjustCounter(entry.getKey(), entry.getValue());
    }

    counterMap.clear();
  }
示例#7
0
  @Override
  public MockFlowFile clone(final FlowFile flowFile, final long offset, final long size) {
    validateState(flowFile);
    if (offset + size > flowFile.getSize()) {
      throw new FlowFileHandlingException(
          "Specified offset of "
              + offset
              + " and size "
              + size
              + " exceeds size of "
              + flowFile.toString());
    }

    final MockFlowFile newFlowFile = new MockFlowFile(sharedState.nextFlowFileId(), flowFile);
    final byte[] newContent =
        Arrays.copyOfRange(
            ((MockFlowFile) flowFile).getData(), (int) offset, (int) (offset + size));
    newFlowFile.setData(newContent);

    currentVersions.put(newFlowFile.getId(), newFlowFile);
    beingProcessed.add(newFlowFile.getId());
    return newFlowFile;
  }
 @Override
 public void clearProvenanceEvents() {
   sharedState.clearProvenanceEvents();
 }
 @Override
 public List<ProvenanceEventRecord> getProvenanceEvents() {
   return sharedState.getProvenanceEvents();
 }
 @Override
 public Long getCounterValue(final String name) {
   return sharedState.getCounterValue(name);
 }
 /**
  * @deprecated The ProvenanceReporter should not be accessed through the test runner, as it does
  *     not expose the events that were emitted.
  */
 @Override
 @Deprecated
 public ProvenanceReporter getProvenanceReporter() {
   return sharedState.getProvenanceReporter();
 }