exceptionfactory commented on code in PR #9620:
URL: https://github.com/apache/nifi/pull/9620#discussion_r1909749877
##########
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:
Instead of building the unit test against the complexities around the random
function, it would be better to use a simple deterministic expression, avoiding
the need for multiple runs.
##########
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:
The `DATA_SIZE_VALIDATOR` includes support for expression language, so is
this change necessary?
##########
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:
The import static should be used for `assertTrue`.
--
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]