如何解决使用嵌套依赖项测试Nifi类
如何在Apache Nifi中为org.apache.nifi.processors.standard.ValidateRecord处理器编写junit? 这是我的代码
@Test
public void valiateRecordtest() throws IOException {
ValidateRecord validateRecord = new ValidateRecord();
TestRunner runner = TestRunners.newTestRunner(validateRecord);
String inputJson = IoUtils.toString(this.getClass().getResourceAsstream("validateRecordInput.json"));
String inputSchema = IoUtils.toString(this.getClass().getResourceAsstream("validateRecordInputSchema.json"));
String expectedResult = IoUtils.toString(this.getClass().getResourceAsstream("validateRecordOutput.json"));
//runner.setProperty(ValidateRecord.SCHEMA_REGISTRY,inputSchema);
MockRecordParser reader = new MockRecordParser();
runner.addControllerService("reader",reader);
runner.setProperty("Record Reader","JsonTreeReader");
runner.setProperty("Record Writer","JsonRecordSetWriter");
runner.setProperty("service","reader");
runner.setProperty(reader,"Schema Registry","AvroSchemaRegistry"); //for JsonTreeReader
runner.setProperty(reader,"Schema Text",inputSchema); //for JsonRecordSetWriter
runner.enableControllerService(reader);
runner.enqueue(inputJson);
runner.run(1);
runner.assertQueueEmpty();
List<MockFlowFile> resultList = runner.getFlowFilesForRelationship("valid");
........
}
JsonTreeReader还具有其他参数,例如Avro模式。如何设置? (因为我没有在这里传递JsonTreeReader的实例)。我收到以下错误消息
'Record Reader' is invalid because Record Reader is required
'Record Writer' is invalid because Record Writer is required
'Record Reader' validated against 'JsonTreeReader' is invalid because 'Record Reader' is not a supported property or has no Validator associated with it
'Record Writer' validated against 'JsonRecordSetWriter' is invalid because 'Record Writer' is not a supported property or has no Validator associated with it
解决方法
TestRunner上具有添加和启用控制器服务的方法。像这样:
plot(obj1,fsize=c(0.05,0.05),link.type="curved",lwd=c(0.2,0.2))
您可以设置以下属性:
def reader = new MockRecordParser()
runner.addControllerService("reader",reader)
runner.setProperty(SomeDescriptor,"reader")
runner.enableControllerService(reader)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。