Search in sources :

Example 81 with TestRunner

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

the class ITPutCloudWatchMetric method testPublishWithCredentialsProviderService.

@Test
public void testPublishWithCredentialsProviderService() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(new PutCloudWatchMetric());
    runner.setValidateExpressionUsage(false);
    final AWSCredentialsProviderControllerService serviceImpl = new AWSCredentialsProviderControllerService();
    runner.addControllerService("awsCredentialsProvider", serviceImpl);
    runner.setProperty(serviceImpl, AbstractAWSCredentialsProviderProcessor.CREDENTIALS_FILE, System.getProperty("user.home") + "/aws-credentials.properties");
    runner.enableControllerService(serviceImpl);
    runner.assertValid(serviceImpl);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "Test");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "Test");
    runner.setProperty(PutCloudWatchMetric.VALUE, "1.0");
    runner.setProperty(PutSNS.AWS_CREDENTIALS_PROVIDER_SERVICE, "awsCredentialsProvider");
    runner.enqueue(new byte[] {});
    runner.run();
    runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1);
}
Also used : AWSCredentialsProviderControllerService(org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 82 with TestRunner

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

the class TestPutCloudWatchMetric method testMetricExpressionInvalidRoutesToFailure.

@Test
public void testMetricExpressionInvalidRoutesToFailure() throws Exception {
    MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
    final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
    runner.setProperty(PutCloudWatchMetric.VALUE, "${metric.value}");
    runner.assertValid();
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("metric.value", "nan");
    runner.enqueue(new byte[] {}, attributes);
    runner.run();
    Assert.assertEquals(0, mockPutCloudWatchMetric.putMetricDataCallCount);
    runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_FAILURE, 1);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 83 with TestRunner

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

the class TestPutCloudWatchMetric method testMaximumDimensions.

@Test
public void testMaximumDimensions() throws Exception {
    MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
    final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
    runner.setProperty(PutCloudWatchMetric.VALUE, "1.0");
    runner.setProperty(PutCloudWatchMetric.UNIT, "Count");
    runner.setProperty(PutCloudWatchMetric.TIMESTAMP, "1476296132575");
    for (int i = 0; i < 10; i++) {
        runner.setProperty(new PropertyDescriptor.Builder().dynamic(true).name("dim" + i).build(), "0");
    }
    runner.assertValid();
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 84 with TestRunner

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

the class TestPutCloudWatchMetric method testMetricExpressionValid.

@Test
public void testMetricExpressionValid() throws Exception {
    MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
    final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
    runner.setProperty(PutCloudWatchMetric.VALUE, "${metric.value}");
    runner.assertValid();
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("metric.value", "1.23");
    runner.enqueue(new byte[] {}, attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1);
    Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount);
    Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace);
    MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0);
    Assert.assertEquals("TestMetric", datum.getMetricName());
    Assert.assertEquals(1.23d, datum.getValue(), 0.0001d);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) Test(org.junit.Test)

Example 85 with TestRunner

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

the class TestPutCloudWatchMetric method testStatisticSet.

@Test
public void testStatisticSet() throws Exception {
    MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
    final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
    runner.setProperty(PutCloudWatchMetric.MINIMUM, "${metric.min}");
    runner.setProperty(PutCloudWatchMetric.MAXIMUM, "${metric.max}");
    runner.setProperty(PutCloudWatchMetric.SUM, "${metric.sum}");
    runner.setProperty(PutCloudWatchMetric.SAMPLECOUNT, "${metric.count}");
    runner.assertValid();
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("metric.min", "1");
    attributes.put("metric.max", "2");
    attributes.put("metric.sum", "3");
    attributes.put("metric.count", "2");
    runner.enqueue(new byte[] {}, attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1);
    Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount);
    Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace);
    MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0);
    Assert.assertEquals("TestMetric", datum.getMetricName());
    Assert.assertEquals(1.0d, datum.getStatisticValues().getMinimum(), 0.0001d);
    Assert.assertEquals(2.0d, datum.getStatisticValues().getMaximum(), 0.0001d);
    Assert.assertEquals(3.0d, datum.getStatisticValues().getSum(), 0.0001d);
    Assert.assertEquals(2.0d, datum.getStatisticValues().getSampleCount(), 0.0001d);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) Test(org.junit.Test)

Aggregations

TestRunner (org.apache.nifi.util.TestRunner)1337 Test (org.junit.Test)1315 MockFlowFile (org.apache.nifi.util.MockFlowFile)741 HashMap (java.util.HashMap)297 File (java.io.File)137 ProcessContext (org.apache.nifi.processor.ProcessContext)56 Connection (java.sql.Connection)44 Statement (java.sql.Statement)37 UpdateAttribute (org.apache.nifi.processors.attributes.UpdateAttribute)32 ProcessSession (org.apache.nifi.processor.ProcessSession)31 ResultSet (java.sql.ResultSet)30 Schema (org.apache.avro.Schema)28 Relationship (org.apache.nifi.processor.Relationship)27 ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)27 ByteArrayInputStream (java.io.ByteArrayInputStream)26 MockProcessContext (org.apache.nifi.util.MockProcessContext)25 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)24 Ignore (org.junit.Ignore)24 InputStream (java.io.InputStream)22 PutFlowFile (org.apache.nifi.hbase.put.PutFlowFile)22