コード例 #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());
 }
コード例 #2
0
  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;
  }
コード例 #8
0
 @Override
 public void clearProvenanceEvents() {
   sharedState.clearProvenanceEvents();
 }
コード例 #9
0
 @Override
 public List<ProvenanceEventRecord> getProvenanceEvents() {
   return sharedState.getProvenanceEvents();
 }
コード例 #10
0
 @Override
 public Long getCounterValue(final String name) {
   return sharedState.getCounterValue(name);
 }
コード例 #11
0
 /**
  * @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();
 }