本文整理汇总了Java中org.apache.nifi.util.TestRunner.getFlowFilesForRelationship方法的典型用法代码示例。如果您正苦于以下问题:Java TestRunner.getFlowFilesForRelationship方法的具体用法?Java TestRunner.getFlowFilesForRelationship怎么用?Java TestRunner.getFlowFilesForRelationship使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.TestRunner
的用法示例。
在下文中一共展示了TestRunner.getFlowFilesForRelationship方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: singleAttributeTest
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void singleAttributeTest() {
TestRunner runner = TestRunners.newTestRunner(Md5HashAttributes.class);
runner.setProperty("hash", "${attribute1}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "attribute1", "pbs.twimg.com/media/ClvFsHiUgAE4fT6.jpg");
runner.enqueue(ff);
runner.run();
// All results were processed with out failure
runner.assertQueueEmpty();
runner.assertTransferCount(Md5HashAttributes.REL_SUCCESS, 1);
// If you need to read or do additional tests on results you can access the content
List<MockFlowFile> results = runner.getFlowFilesForRelationship(Md5HashAttributes.REL_SUCCESS);
assertTrue("1 match", results.size() == 1);
MockFlowFile result = results.get(0);
result.assertAttributeEquals("hash", "e2c26a2479f497562a615a42ecb1ef7e");
}
示例2: onTrigger
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void onTrigger() throws Exception {
TestRunner runner = TestRunners.newTestRunner(new ProtobufEncoder());
HashMap<String, String> adressBookProperties = new HashMap<>();
adressBookProperties.put("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
adressBookProperties.put("protobuf.messageType", "AddressBook");
// AddressBook test
for (String filename: validTestFiles) {
InputStream jsonFile = ProtobufEncoderTest.class.getResourceAsStream("/data/" + filename + ".json");
adressBookProperties.put("testfile", filename);
runner.enqueue(jsonFile, adressBookProperties);
}
// Ensure the configuration is valid as-is
runner.assertValid();
// Run the enqueued content, it also takes an int = number of contents queued
runner.run(validTestFiles.length);
runner.assertQueueEmpty();
// Check if the data was processed without failure
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS);
Assert.assertEquals("All flowfiles should be returned to success", validTestFiles.length, results.size());
// Check if the content of the flowfile is as expected
for (MockFlowFile result: results) {
result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/" + result.getAttribute("testfile") + ".data"));
}
}
示例3: onTrigger
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void onTrigger() throws Exception {
TestRunner runner = TestRunners.newTestRunner(new ProtobufDecoder());
// AddressBook test
HashMap<String, String> addressBookProperties = new HashMap<>();
addressBookProperties.put("protobuf.schemaPath", ProtobufDecoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
addressBookProperties.put("protobuf.messageType", "AddressBook");
// AddressBook test
for (String filename: validTestFiles) {
InputStream jsonFile = ProtobufDecoderTest.class.getResourceAsStream("/data/" + filename + ".data");
addressBookProperties.put("testfile", filename);
runner.enqueue(jsonFile, addressBookProperties);
}
// Ensure the configuration is valid as-is
runner.assertValid();
// Run the enqueued content, it also takes an int = number of contents queued
runner.run(validTestFiles.length);
runner.assertQueueEmpty();
// Check if the data was processed without failure
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS);
Assert.assertEquals("All flowfiles should be returned to success", validTestFiles.length, results.size());
// Check if the content of the flowfile is as expected
ObjectMapper mapper = new ObjectMapper();
for (MockFlowFile result: results) {
JsonNode expected = mapper.readTree(this.getClass().getResourceAsStream("/data/" + result.getAttribute("testfile") + ".json"));
JsonNode given = mapper.readTree(runner.getContentAsByteArray(result));
Assert.assertEquals("The parsing result of " + result.getAttribute("testfile") + ".data is not as expected", expected, given);
}
}
示例4: multipleAttributeTest
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void multipleAttributeTest() {
TestRunner runner = TestRunners.newTestRunner(Md5HashAttributes.class);
runner.setProperty("hash", "${attribute1}");
runner.setProperty("hash2", "${attribute2}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "attribute1", "pbs.twimg.com/media/ClvFsHiUgAE4fT6.jpg");
ff = session.putAttribute(ff, "attribute2", "");
runner.enqueue(ff);
runner.run();
// All results were processed with out failure
runner.assertQueueEmpty();
runner.assertTransferCount(Md5HashAttributes.REL_SUCCESS, 1);
// If you need to read or do additional tests on results you can access the content
List<MockFlowFile> results = runner.getFlowFilesForRelationship(Md5HashAttributes.REL_SUCCESS);
assertTrue("1 match", results.size() == 1);
MockFlowFile result = results.get(0);
result.assertAttributeEquals("hash", "e2c26a2479f497562a615a42ecb1ef7e");
result.assertAttributeEquals("hash2", "d41d8cd98f00b204e9800998ecf8427e");
}
示例5: testDuplicateKeyFailureOrderedTrue
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testDuplicateKeyFailureOrderedTrue() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.BATCH_SIZE, "10");
runner.setProperty(MongoProps.ORDERED, "true");
ObjectId objectId = ObjectId.get();
String success = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
String successTwo = "{\"a\":\"a\"}";
String payloadOne = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"first value\"}";
String payloadTwo = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"second value\"}";
runner.enqueue(payloadOne.getBytes());
runner.enqueue(success.getBytes());
runner.enqueue(payloadTwo.getBytes());
runner.enqueue(successTwo.getBytes()); // add another successful message
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 2);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 2);
List<MockFlowFile> failures = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE);
FlowFile failure1 = failures.get(0);
String errorCode1 = failure1.getAttribute("mongo.errorcode");
assertEquals("11000", errorCode1); // duplicate key error code
String errorMessage1 = failure1.getAttribute("mongo.errormessage");
assertTrue(StringUtils.isNotBlank(errorMessage1));
FlowFile failure2 = failures.get(1);
String errorMessage2 = failure2.getAttribute("storeinmongo.error");
assertTrue(StringUtils.isNotBlank(errorMessage2));
String mongoErrorCode2 = failure2.getAttribute("mongo.errorcode");
assertTrue(StringUtils.isBlank(mongoErrorCode2));
// Test contents of mongo
MongoCollection<Document> collection = mongo.getMongoClient().getDatabase(MONGO_DATABASE_NAME).getCollection("insert_test");
assertEquals(2L, collection.count());
}