Search in sources :

Example 1 with InfluxDatabaseService_2

use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.

the class AbstractTestGetInfluxDatabase_2 method before.

@Before
public void before() throws IOException, GeneralSecurityException, InitializationException {
    InfluxDBClient mockInfluxDBClient = Mockito.mock(InfluxDBClient.class);
    mockQueryApi = Mockito.mock(QueryApi.class);
    Mockito.doAnswer(invocation -> mockQueryApi).when(mockInfluxDBClient).getQueryApi();
    Mockito.doAnswer(invocation -> {
        if (queryOnErrorValue != null) {
            // noinspection unchecked
            Consumer<Exception> onError = invocation.getArgument(3, Consumer.class);
            onError.accept(queryOnErrorValue);
        }
        queryOnResponseRecords.forEach(record -> {
            // noinspection unchecked
            BiConsumer<Cancellable, String> onRecord = invocation.getArgument(2, BiConsumer.class);
            onRecord.accept(Mockito.mock(Cancellable.class), record);
        });
        boolean wasException = queryOnErrorValue != null;
        try {
            return queryAnswer.answer(invocation);
        } catch (Exception e) {
            wasException = true;
            throw e;
        } finally {
            if (!wasException) {
                Runnable onComplete = invocation.getArgument(4, Runnable.class);
                onComplete.run();
            }
        }
    }).when(mockQueryApi).queryRaw(Mockito.any(Query.class), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any());
    processor = Mockito.spy(new GetInfluxDatabase_2());
    runner = TestRunners.newTestRunner(processor);
    runner.setProperty(GetInfluxDatabase_2.ORG, "my-org");
    runner.setProperty(GetInfluxDatabase_2.QUERY, "from(bucket:\"my-bucket\") |> range(start: 0) |> last()");
    runner.setProperty(GetInfluxDatabase_2.INFLUX_DB_SERVICE, "influxdb-service");
    InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
    Mockito.doAnswer(invocation -> mockInfluxDBClient).when(influxDatabaseService).create();
    runner.addControllerService("influxdb-service", influxDatabaseService);
    runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
    runner.enableControllerService(influxDatabaseService);
    MockProcessContext context = new MockProcessContext(processor);
    MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
    logger = initContext.getLogger();
    processor.initialize(initContext);
    processor.onScheduled(runner.getProcessContext());
    processor.initWriterFactory(runner.getProcessContext());
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient) QueryApi(com.influxdb.client.QueryApi) Query(com.influxdb.client.domain.Query) InfluxDatabaseService_2(org.influxdata.nifi.services.InfluxDatabaseService_2) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) Cancellable(com.influxdb.Cancellable) MockProcessorInitializationContext(org.apache.nifi.util.MockProcessorInitializationContext) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) InitializationException(org.apache.nifi.reporting.InitializationException) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException) MockProcessContext(org.apache.nifi.util.MockProcessContext) Before(org.junit.Before)

Example 2 with InfluxDatabaseService_2

use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.

the class AbstractTestPutInfluxDatabaseRecord_2 method before.

@Before
public void before() throws InitializationException, IOException, GeneralSecurityException {
    MockitoAnnotations.initMocks(this);
    mockWriteApi = Mockito.mock(WriteApiBlocking.class);
    mockInfluxDBClient = Mockito.mock(InfluxDBClient.class);
    Mockito.doAnswer(invocation -> mockWriteApi).when(mockInfluxDBClient).getWriteApiBlocking();
    processor = Mockito.spy(new PutInfluxDatabaseRecord_2());
    runner = TestRunners.newTestRunner(processor);
    runner.setProperty(PutInfluxDatabaseRecord_2.ORG, "my-org");
    runner.setProperty(PutInfluxDatabaseRecord_2.BUCKET, "my-bucket");
    runner.setProperty(InfluxDBUtils.MEASUREMENT, "nifi-measurement");
    runner.setProperty(InfluxDBUtils.FIELDS, "nifi-field");
    runner.setProperty(AbstractInfluxDatabaseProcessor.RECORD_READER_FACTORY, "recordReader");
    runner.setProperty(PutInfluxDatabaseRecord_2.INFLUX_DB_SERVICE, "influxdb-service");
    recordReader = new MockRecordParser();
    runner.addControllerService("recordReader", recordReader);
    runner.enableControllerService(recordReader);
    InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
    Mockito.doAnswer(invocation -> mockInfluxDBClient).when(influxDatabaseService).create();
    Mockito.doAnswer(invocation -> {
        Mockito.doAnswer(writeAnswer).when(mockWriteApi).writePoints(Mockito.any(), Mockito.any(), pointCapture.capture());
        return mockInfluxDBClient;
    }).when(influxDatabaseService).create();
    runner.addControllerService("influxdb-service", influxDatabaseService);
    runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
    runner.enableControllerService(influxDatabaseService);
    MockProcessContext context = new MockProcessContext(processor);
    MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
    logger = initContext.getLogger();
    processor.initialize(initContext);
    /**
     * Manually call onScheduled because it si not called by
     * org.apache.nifi.util.StandardProcessorTestRunner#run(int, boolean, boolean, long).
     * Bug in Mockito-CGLIB (https://github.com/mockito/mockito/issues/204)... remove after upgrade Mockito to 2.x
     */
    processor.onScheduled(runner.getProcessContext());
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient) InfluxDatabaseService_2(org.influxdata.nifi.services.InfluxDatabaseService_2) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) WriteApiBlocking(com.influxdb.client.WriteApiBlocking) MockProcessorInitializationContext(org.apache.nifi.util.MockProcessorInitializationContext) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) MockProcessContext(org.apache.nifi.util.MockProcessContext) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) Before(org.junit.Before)

Example 3 with InfluxDatabaseService_2

use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.

the class ITGetInfluxDatabaseRecord_2 method setUp.

@Before
public void setUp() throws Exception {
    init();
    GetInfluxDatabaseRecord_2 putInfluxDatabase_2 = new GetInfluxDatabaseRecord_2();
    runner = TestRunners.newTestRunner(putInfluxDatabase_2);
    runner.setValidateExpressionUsage(false);
    runner.setProperty(GetInfluxDatabaseRecord_2.INFLUX_DB_SERVICE, "influxdb-service");
    runner.setProperty(GetInfluxDatabaseRecord_2.ORG, organization.getId());
    runner.setProperty(GetInfluxDatabaseRecord_2.QUERY, "from(bucket:\"" + bucketName + "\") |> range(start: 0)");
    runner.setProperty(GetInfluxDatabaseRecord_2.LOG_LEVEL, "BODY");
    InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
    runner.addControllerService("influxdb-service", influxDatabaseService);
    runner.setProperty(influxDatabaseService, INFLUX_DB_URL, INFLUX_DB_2);
    runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
    runner.enableControllerService(influxDatabaseService);
    recordWriter = new AvroRecordSetWriter();
    runner.addControllerService("writer", recordWriter);
    runner.setProperty(recordWriter, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.INHERIT_RECORD_SCHEMA);
    runner.setProperty(GetInfluxDatabaseRecord_2.WRITER_FACTORY, "writer");
    runner.enableControllerService(recordWriter);
    runner.assertValid();
}
Also used : InfluxDatabaseService_2(org.influxdata.nifi.services.InfluxDatabaseService_2) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) AvroRecordSetWriter(org.apache.nifi.avro.AvroRecordSetWriter) Before(org.junit.Before)

Example 4 with InfluxDatabaseService_2

use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.

the class ITGetInfluxDatabase_2 method setUp.

@Before
public void setUp() throws Exception {
    init();
    GetInfluxDatabase_2 putInfluxDatabase_2 = new GetInfluxDatabase_2();
    runner = TestRunners.newTestRunner(putInfluxDatabase_2);
    runner.setValidateExpressionUsage(false);
    runner.setProperty(GetInfluxDatabase_2.INFLUX_DB_SERVICE, "influxdb-service");
    runner.setProperty(GetInfluxDatabase_2.ORG, organization.getId());
    runner.setProperty(GetInfluxDatabase_2.QUERY, "from(bucket:\"" + bucketName + "\") |> range(start: 0)");
    InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
    runner.addControllerService("influxdb-service", influxDatabaseService);
    runner.setProperty(influxDatabaseService, INFLUX_DB_URL, INFLUX_DB_2);
    runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
    runner.enableControllerService(influxDatabaseService);
}
Also used : InfluxDatabaseService_2(org.influxdata.nifi.services.InfluxDatabaseService_2) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) Before(org.junit.Before)

Example 5 with InfluxDatabaseService_2

use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.

the class TestPutInfluxDatabase_2 method setUp.

@Before
public void setUp() throws InitializationException, IOException, GeneralSecurityException {
    mockWriteApi = Mockito.mock(WriteApiBlocking.class);
    mockInfluxDBClient = Mockito.mock(InfluxDBClient.class);
    Mockito.doAnswer(invocation -> mockWriteApi).when(mockInfluxDBClient).getWriteApiBlocking();
    PutInfluxDatabase_2 putInfluxDatabase_2 = new PutInfluxDatabase_2();
    runner = TestRunners.newTestRunner(putInfluxDatabase_2);
    runner.setProperty(PutInfluxDatabase_2.INFLUX_DB_SERVICE, "influxdb-service");
    runner.setProperty(PutInfluxDatabase_2.BUCKET, "my-bucket");
    runner.setProperty(PutInfluxDatabase_2.ORG, "my-org");
    InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
    Mockito.doAnswer(invocation -> mockInfluxDBClient).when(influxDatabaseService).create();
    runner.addControllerService("influxdb-service", influxDatabaseService);
    runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
    runner.enableControllerService(influxDatabaseService);
}
Also used : InfluxDBClient(com.influxdb.client.InfluxDBClient) InfluxDatabaseService_2(org.influxdata.nifi.services.InfluxDatabaseService_2) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) WriteApiBlocking(com.influxdb.client.WriteApiBlocking) StandardInfluxDatabaseService_2(org.influxdata.nifi.services.StandardInfluxDatabaseService_2) Before(org.junit.Before)

Aggregations

InfluxDatabaseService_2 (org.influxdata.nifi.services.InfluxDatabaseService_2)9 StandardInfluxDatabaseService_2 (org.influxdata.nifi.services.StandardInfluxDatabaseService_2)9 Before (org.junit.Before)8 InfluxDBClient (com.influxdb.client.InfluxDBClient)4 MockProcessContext (org.apache.nifi.util.MockProcessContext)4 MockProcessorInitializationContext (org.apache.nifi.util.MockProcessorInitializationContext)4 Cancellable (com.influxdb.Cancellable)2 QueryApi (com.influxdb.client.QueryApi)2 WriteApiBlocking (com.influxdb.client.WriteApiBlocking)2 Query (com.influxdb.client.domain.Query)2 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 InitializationException (org.apache.nifi.reporting.InitializationException)2 MockRecordParser (org.apache.nifi.serialization.record.MockRecordParser)2 FluxRecord (com.influxdb.query.FluxRecord)1 AvroRecordSetWriter (org.apache.nifi.avro.AvroRecordSetWriter)1 ProcessContext (org.apache.nifi.processor.ProcessContext)1 ArrayListRecordWriter (org.apache.nifi.serialization.record.ArrayListRecordWriter)1 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)1 MockFlowFile (org.apache.nifi.util.MockFlowFile)1