markobean commented on code in PR #9620:
URL: https://github.com/apache/nifi/pull/9620#discussion_r1909807885


##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateFlowFile.java:
##########
@@ -76,7 +76,8 @@ public class GenerateFlowFile extends AbstractProcessor {
             .description("The size of the file that will be used")
             .required(true)
             .defaultValue("0B")
-            .addValidator(StandardValidators.DATA_SIZE_VALIDATOR)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)

Review Comment:
   Without that validator within the property, the processor was invalid 
indicating:
   "'File Size' validated against '${random():mod(101)}B' is invalid because 
'File Size' is not a supported property or has no Validator associated with it"
   As the property is in fact required, this is a reasonable validator to add. 



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java:
##########
@@ -73,4 +78,30 @@ public void testDynamicPropertiesToAttributes() {
         generatedFlowFile.assertAttributeEquals("mime.type", 
"application/text");
     }
 
+    @Test
+    public void testExpressionLanguageSupport() {
+        TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
+        runner.setProperty(GenerateFlowFile.FILE_SIZE, 
"${random():mod(10):plus(1)}B");  // represents a range of 1-10 bytes, inclusive

Review Comment:
   Modified to use `nextInt()` function. But still made 2 batch executions to 
confirm file size uniqueness (or not) based on `UNIQUE_FLOWFILES` setting. This 
is slightly out of scope, but the batch processing does not have any other unit 
test. 2 birds.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java:
##########
@@ -73,4 +78,30 @@ public void testDynamicPropertiesToAttributes() {
         generatedFlowFile.assertAttributeEquals("mime.type", 
"application/text");
     }
 
+    @Test
+    public void testExpressionLanguageSupport() {
+        TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
+        runner.setProperty(GenerateFlowFile.FILE_SIZE, 
"${random():mod(10):plus(1)}B");  // represents a range of 1-10 bytes, inclusive
+        runner.setProperty(GenerateFlowFile.UNIQUE_FLOWFILES, "true");
+        runner.assertValid();
+
+        // Execute multiple times to ensure adequate distribution of file sizes
+        runner.run(1000);
+
+        runner.assertTransferCount(GenerateFlowFile.SUCCESS, 1000);
+        List<MockFlowFile> flowFiles = 
runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS);
+        Map<Long, Integer> fileSizeDistribution = new HashMap<>();
+        flowFiles.forEach(ff -> {
+            long fileSize = ff.getSize();
+            fileSizeDistribution.put(fileSize, 
fileSizeDistribution.getOrDefault(fileSize, 0) + 1);
+        });
+        long minSize = 
fileSizeDistribution.keySet().stream().min(Long::compareTo).orElse(-1L);
+        long maxSize = 
fileSizeDistribution.keySet().stream().max(Long::compareTo).orElse(-1L);
+
+        // Assert all file sizes fall within the range and that there exists 
more than one unique file size value
+        Assertions.assertTrue(minSize > 0 && minSize < maxSize);
+        Assertions.assertTrue(maxSize <= 10);

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to