Search in sources :

Example 16 with MockComponentLog

use of org.apache.nifi.util.MockComponentLog in project nifi by apache.

the class TestDetectDuplicate method createClient.

private DistributedMapCacheClientImpl createClient() throws InitializationException {
    final DistributedMapCacheClientImpl client = new DistributedMapCacheClientImpl();
    final ComponentLog logger = new MockComponentLog("client", client);
    final MockControllerServiceInitializationContext clientInitContext = new MockControllerServiceInitializationContext(client, "client", logger, new MockStateManager(client));
    client.initialize(clientInitContext);
    return client;
}
Also used : MockControllerServiceInitializationContext(org.apache.nifi.util.MockControllerServiceInitializationContext) MockStateManager(org.apache.nifi.state.MockStateManager) MockComponentLog(org.apache.nifi.util.MockComponentLog) ComponentLog(org.apache.nifi.logging.ComponentLog) MockComponentLog(org.apache.nifi.util.MockComponentLog)

Example 17 with MockComponentLog

use of org.apache.nifi.util.MockComponentLog in project nifi by apache.

the class AMQPPublisherTest method validateSuccessfullPublishingAndUndeliverableRoutingKey.

@Test
public void validateSuccessfullPublishingAndUndeliverableRoutingKey() throws Exception {
    Map<String, List<String>> routingMap = new HashMap<>();
    routingMap.put("key1", Arrays.asList("queue1", "queue2"));
    Map<String, String> exchangeToRoutingKeymap = new HashMap<>();
    exchangeToRoutingKeymap.put("myExchange", "key1");
    Connection connection = new TestConnection(exchangeToRoutingKeymap, routingMap);
    ReturnListener retListener = mock(ReturnListener.class);
    connection.createChannel().addReturnListener(retListener);
    try (AMQPPublisher sender = new AMQPPublisher(connection, new MockComponentLog("foo", ""))) {
        sender.publish("hello".getBytes(), null, "key1", "myExchange");
    }
    verify(retListener, atMost(1)).handleReturn(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(BasicProperties.class), (byte[]) Mockito.any());
    connection.close();
}
Also used : ReturnListener(com.rabbitmq.client.ReturnListener) HashMap(java.util.HashMap) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) MockComponentLog(org.apache.nifi.util.MockComponentLog) Connection(com.rabbitmq.client.Connection) List(java.util.List) Test(org.junit.Test)

Example 18 with MockComponentLog

use of org.apache.nifi.util.MockComponentLog in project nifi by apache.

the class ITReportLineageToAtlas method test.

private void test(TestConfiguration tc) throws InitializationException, IOException {
    final ReportLineageToAtlas reportingTask = new ReportLineageToAtlas();
    final MockComponentLog logger = new MockComponentLog("reporting-task-id", reportingTask);
    final ReportingInitializationContext initializationContext = mock(ReportingInitializationContext.class);
    when(initializationContext.getLogger()).thenReturn(logger);
    final ConfigurationContext configurationContext = new MockConfigurationContext(tc.properties, null);
    final ValidationContext validationContext = mock(ValidationContext.class);
    when(validationContext.getProperty(any())).then(invocation -> new MockPropertyValue(tc.properties.get(invocation.getArguments()[0])));
    final ReportingContext reportingContext = mock(ReportingContext.class);
    final MockStateManager stateManager = new MockStateManager(reportingTask);
    final EventAccess eventAccess = mock(EventAccess.class);
    when(reportingContext.getProperties()).thenReturn(tc.properties);
    when(reportingContext.getProperty(any())).then(invocation -> new MockPropertyValue(tc.properties.get(invocation.getArguments()[0])));
    when(reportingContext.getStateManager()).thenReturn(stateManager);
    when(reportingContext.getEventAccess()).thenReturn(eventAccess);
    when(eventAccess.getGroupStatus(eq("root"))).thenReturn(tc.rootPgStatus);
    final ProvenanceRepository provenanceRepository = mock(ProvenanceRepository.class);
    when(eventAccess.getControllerStatus()).thenReturn(tc.rootPgStatus);
    when(eventAccess.getProvenanceRepository()).thenReturn(provenanceRepository);
    when(eventAccess.getProvenanceEvents(eq(-1L), anyInt())).thenReturn(tc.provenanceRecords);
    when(provenanceRepository.getMaxEventId()).thenReturn((long) tc.provenanceRecords.size() - 1);
    when(provenanceRepository.getEvent(anyLong())).then(invocation -> tc.provenanceRecords.get(((Long) invocation.getArguments()[0]).intValue()));
    // To mock this async method invocations, keep the requested event ids in a stack.
    final ComputeLineageSubmission lineageComputationSubmission = mock(ComputeLineageSubmission.class);
    when(provenanceRepository.submitLineageComputation(anyLong(), any())).thenAnswer(invocation -> {
        requestedLineageComputationIds.push((Long) invocation.getArguments()[0]);
        return lineageComputationSubmission;
    });
    when(lineageComputationSubmission.getResult()).then(invocation -> tc.lineageResults.get(requestedLineageComputationIds.pop()));
    final ComputeLineageSubmission expandParentsSubmission = mock(ComputeLineageSubmission.class);
    when(provenanceRepository.submitExpandParents(anyLong(), any())).thenAnswer(invocation -> {
        requestedExpandParentsIds.push(((Long) invocation.getArguments()[0]));
        return expandParentsSubmission;
    });
    when(expandParentsSubmission.getResult()).then(invocation -> tc.parentLineageResults.get(requestedExpandParentsIds.pop()));
    tc.properties.put(ATLAS_NIFI_URL, "http://localhost:8080/nifi");
    tc.properties.put(ATLAS_URLS, TARGET_ATLAS_URL);
    tc.properties.put(ATLAS_USER, "admin");
    tc.properties.put(ATLAS_PASSWORD, "admin");
    tc.properties.put(new PropertyDescriptor.Builder().name("hostnamePattern.example").dynamic(true).build(), ".*");
    reportingTask.initialize(initializationContext);
    reportingTask.validate(validationContext);
    reportingTask.setup(configurationContext);
    reportingTask.onTrigger(reportingContext);
    reportingTask.onUnscheduled();
    reportingTask.onStopped();
}
Also used : EventAccess(org.apache.nifi.reporting.EventAccess) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) MockComponentLog(org.apache.nifi.util.MockComponentLog) ComputeLineageSubmission(org.apache.nifi.provenance.lineage.ComputeLineageSubmission) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) ValidationContext(org.apache.nifi.components.ValidationContext) ReportingContext(org.apache.nifi.reporting.ReportingContext) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) MockStateManager(org.apache.nifi.state.MockStateManager) Matchers.anyLong(org.mockito.Matchers.anyLong) ProvenanceRepository(org.apache.nifi.provenance.ProvenanceRepository)

Example 19 with MockComponentLog

use of org.apache.nifi.util.MockComponentLog in project nifi by apache.

the class TestConsumeAzureEventHub method setupProcessor.

@Before
public void setupProcessor() {
    processor = new ConsumeAzureEventHub();
    final ProcessorInitializationContext initContext = Mockito.mock(ProcessorInitializationContext.class);
    final String componentId = "componentId";
    when(initContext.getIdentifier()).thenReturn(componentId);
    MockComponentLog componentLog = new MockComponentLog(componentId, processor);
    when(initContext.getLogger()).thenReturn(componentLog);
    processor.initialize(initContext);
    final ProcessSessionFactory processSessionFactory = Mockito.mock(ProcessSessionFactory.class);
    processor.setProcessSessionFactory(processSessionFactory);
    processor.setNamespaceName("namespace");
    sharedState = new SharedSessionState(processor, new AtomicLong(0));
    processSession = new MockProcessSession(sharedState, processor);
    when(processSessionFactory.createSession()).thenReturn(processSession);
    eventProcessor = processor.new EventProcessor();
    partitionContext = Mockito.mock(PartitionContext.class);
    when(partitionContext.getEventHubPath()).thenReturn("eventhub-name");
    when(partitionContext.getPartitionId()).thenReturn("partition-id");
    when(partitionContext.getConsumerGroupName()).thenReturn("consumer-group");
}
Also used : PartitionContext(com.microsoft.azure.eventprocessorhost.PartitionContext) SharedSessionState(org.apache.nifi.util.SharedSessionState) AtomicLong(java.util.concurrent.atomic.AtomicLong) MockComponentLog(org.apache.nifi.util.MockComponentLog) ProcessSessionFactory(org.apache.nifi.processor.ProcessSessionFactory) MockProcessSession(org.apache.nifi.util.MockProcessSession) ProcessorInitializationContext(org.apache.nifi.processor.ProcessorInitializationContext) Before(org.junit.Before)

Aggregations

MockComponentLog (org.apache.nifi.util.MockComponentLog)19 Test (org.junit.Test)15 MockFlowFile (org.apache.nifi.util.MockFlowFile)13 ProcessContext (org.apache.nifi.processor.ProcessContext)9 ProcessSession (org.apache.nifi.processor.ProcessSession)9 TestRunner (org.apache.nifi.util.TestRunner)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 HashMap (java.util.HashMap)4 MockStateManager (org.apache.nifi.state.MockStateManager)3 List (java.util.List)2 ComponentLog (org.apache.nifi.logging.ComponentLog)2 MockConfigurationContext (org.apache.nifi.util.MockConfigurationContext)2 Before (org.junit.Before)2 PartitionContext (com.microsoft.azure.eventprocessorhost.PartitionContext)1 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)1 Connection (com.rabbitmq.client.Connection)1 ReturnListener (com.rabbitmq.client.ReturnListener)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1