当前位置: 首页>>代码示例>>Java>>正文


Java TestRunner.getFlowFilesForRelationship方法代码示例

本文整理汇总了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");
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:25,代码来源:Md5HashAttributesTest.java

示例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"));
    }

}
 
开发者ID:whiver,项目名称:nifi-protobuf-processor,代码行数:33,代码来源:ProtobufEncoderTest.java

示例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);
    }
}
 
开发者ID:whiver,项目名称:nifi-protobuf-processor,代码行数:37,代码来源:ProtobufDecoderTest.java

示例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");

}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:30,代码来源:Md5HashAttributesTest.java

示例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());
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:44,代码来源:StoreInMongoIT.java


注:本文中的org.apache.nifi.util.TestRunner.getFlowFilesForRelationship方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。