Search in sources :

Example 6 with StandardProcessorInitializationContext

use of org.apache.nifi.processor.StandardProcessorInitializationContext in project nifi by apache.

the class TestStandardProcessorNode method createProcessorNode.

private StandardProcessorNode createProcessorNode(final Processor processor, final ReloadComponent reloadComponent) {
    final String uuid = UUID.randomUUID().toString();
    final ValidationContextFactory validationContextFactory = createValidationContextFactory();
    final NiFiProperties niFiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", null);
    final ProcessScheduler processScheduler = Mockito.mock(ProcessScheduler.class);
    final TerminationAwareLogger componentLog = Mockito.mock(TerminationAwareLogger.class);
    final Bundle systemBundle = SystemBundle.create(niFiProperties);
    ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
    ExtensionManager.createInstanceClassLoader(processor.getClass().getName(), uuid, systemBundle, null);
    ProcessorInitializationContext initContext = new StandardProcessorInitializationContext(uuid, componentLog, null, null, null);
    processor.initialize(initContext);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(processor, systemBundle.getBundleDetails().getCoordinate(), componentLog);
    return new StandardProcessorNode(loggableComponent, uuid, validationContextFactory, processScheduler, null, niFiProperties, new StandardComponentVariableRegistry(variableRegistry), reloadComponent);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ModifiesClasspathNoAnnotationProcessor(org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor) Processor(org.apache.nifi.processor.Processor) ModifiesClasspathProcessor(org.apache.nifi.test.processors.ModifiesClasspathProcessor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) Bundle(org.apache.nifi.bundle.Bundle) SystemBundle(org.apache.nifi.nar.SystemBundle) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) ProcessorInitializationContext(org.apache.nifi.processor.ProcessorInitializationContext) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext)

Example 7 with StandardProcessorInitializationContext

use of org.apache.nifi.processor.StandardProcessorInitializationContext in project nifi by apache.

the class TestStandardProcessorNode method testStart.

@Test(timeout = 10000)
public void testStart() throws InterruptedException {
    final ProcessorThatThrowsExceptionOnScheduled processor = new ProcessorThatThrowsExceptionOnScheduled();
    final String uuid = UUID.randomUUID().toString();
    ProcessorInitializationContext initContext = new StandardProcessorInitializationContext(uuid, null, null, null, null);
    processor.initialize(initContext);
    final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
    final BundleCoordinate coordinate = Mockito.mock(BundleCoordinate.class);
    final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(processor, coordinate, null);
    final StandardProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, createValidationContextFactory(), null, null, NiFiProperties.createBasicNiFiProperties(null, null), new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
    final ScheduledExecutorService taskScheduler = new FlowEngine(1, "TestClasspathResources", true);
    final StandardProcessContext processContext = new StandardProcessContext(procNode, null, null, null, () -> false);
    final SchedulingAgentCallback schedulingAgentCallback = new SchedulingAgentCallback() {

        @Override
        public void onTaskComplete() {
        }

        @Override
        public Future<?> scheduleTask(final Callable<?> task) {
            return taskScheduler.submit(task);
        }

        @Override
        public void trigger() {
            Assert.fail("Should not have completed");
        }
    };
    procNode.start(taskScheduler, 20000L, processContext, schedulingAgentCallback, true);
    Thread.sleep(1000L);
    assertEquals(1, processor.onScheduledCount);
    assertEquals(1, processor.onUnscheduledCount);
    assertEquals(1, processor.onStoppedCount);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ModifiesClasspathNoAnnotationProcessor(org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor) Processor(org.apache.nifi.processor.Processor) ModifiesClasspathProcessor(org.apache.nifi.test.processors.ModifiesClasspathProcessor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) FlowEngine(org.apache.nifi.engine.FlowEngine) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ProcessorInitializationContext(org.apache.nifi.processor.ProcessorInitializationContext) StandardProcessorInitializationContext(org.apache.nifi.processor.StandardProcessorInitializationContext) Callable(java.util.concurrent.Callable) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) Test(org.junit.Test)

Aggregations

Processor (org.apache.nifi.processor.Processor)7 StandardProcessorInitializationContext (org.apache.nifi.processor.StandardProcessorInitializationContext)7 AbstractProcessor (org.apache.nifi.processor.AbstractProcessor)6 StandardComponentVariableRegistry (org.apache.nifi.registry.variable.StandardComponentVariableRegistry)6 Test (org.junit.Test)5 LoggableComponent (org.apache.nifi.controller.LoggableComponent)4 ProcessorNode (org.apache.nifi.controller.ProcessorNode)4 ReloadComponent (org.apache.nifi.controller.ReloadComponent)4 StandardProcessorNode (org.apache.nifi.controller.StandardProcessorNode)4 FailOnScheduledProcessor (org.apache.nifi.controller.scheduling.processors.FailOnScheduledProcessor)4 StandardValidationContextFactory (org.apache.nifi.processor.StandardValidationContextFactory)4 ProcessorInitializationContext (org.apache.nifi.processor.ProcessorInitializationContext)3 Bundle (org.apache.nifi.bundle.Bundle)2 ModifiesClasspathNoAnnotationProcessor (org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor)2 ModifiesClasspathProcessor (org.apache.nifi.test.processors.ModifiesClasspathProcessor)2 HashMap (java.util.HashMap)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)1