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


Java TestRunner.assertAllFlowFilesTransferred方法代码示例

本文整理汇总了Java中org.apache.nifi.util.TestRunner.assertAllFlowFilesTransferred方法的典型用法代码示例。如果您正苦于以下问题:Java TestRunner.assertAllFlowFilesTransferred方法的具体用法?Java TestRunner.assertAllFlowFilesTransferred怎么用?Java TestRunner.assertAllFlowFilesTransferred使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.nifi.util.TestRunner的用法示例。


在下文中一共展示了TestRunner.assertAllFlowFilesTransferred方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSuccess

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testSuccess() throws InterruptedException {
    TestRunner runner = TestRunners.newTestRunner(DelayProcessor.class);
    runner.setValidateExpressionUsage(false);
    runner.setProperty(DelayProcessor.TIME_PERIOD, "1 sec");

    runner.enqueue(new byte[0], ImmutableMap.of(CoreAttributes.FILENAME.key(), "file1"));

    runner.run();
    // nothing transferred, 1 file still on queue and cached
    runner.assertTransferCount(DelayProcessor.REL_SUCCESS, 0);
    assertEquals(1, runner.getQueueSize().getObjectCount());
    assertEquals(1, ((DelayProcessor) runner.getProcessor()).delayMap.size());

    // wait until delay has passed
    Thread.sleep(1010);

    runner.run();
    // file transferred, nothing on queue, cache empty
    runner.assertAllFlowFilesTransferred(DelayProcessor.REL_SUCCESS, 1);
    assertEquals(0, ((DelayProcessor) runner.getProcessor()).delayMap.size());
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:23,代码来源:DelayProcessorTest.java

示例2: testExpireMultipleFilesSimultaneously

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testExpireMultipleFilesSimultaneously() throws InterruptedException {
    TestRunner runner = TestRunners.newTestRunner(DelayProcessor.class);
    runner.setValidateExpressionUsage(false);
    runner.setProperty(DelayProcessor.TIME_PERIOD, "1 sec");

    runner.enqueue(new byte[0], ImmutableMap.of(CoreAttributes.FILENAME.key(), "file1"));
    runner.enqueue(new byte[0], ImmutableMap.of(CoreAttributes.FILENAME.key(), "file2"));

    runner.run();
    // nothing transferred, 2 files still on queue and cached
    runner.assertTransferCount(DelayProcessor.REL_SUCCESS, 0);
    assertEquals(2, runner.getQueueSize().getObjectCount());
    assertEquals(2, ((DelayProcessor) runner.getProcessor()).delayMap.size());

    runner.enqueue(new byte[0], ImmutableMap.of(CoreAttributes.FILENAME.key(), "file3"));

    // wait until delay has passed
    Thread.sleep(1010);

    runner.run();
    // 1st 2 files transferred, 3rd still on queue and cached
    runner.assertAllFlowFilesTransferred(DelayProcessor.REL_SUCCESS, 2);
    assertEquals(1, ((DelayProcessor) runner.getProcessor()).delayMap.size());

    runner.clearTransferState();

    // wait until delay has passed
    Thread.sleep(1010);
    runner.run();

    // 3rd file now transferred, cache empty
    runner.assertAllFlowFilesTransferred(DelayProcessor.REL_SUCCESS, 1);
    assertEquals(0, ((DelayProcessor) runner.getProcessor()).delayMap.size());
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:36,代码来源:DelayProcessorTest.java

示例3: onPropertyModified

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void onPropertyModified() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(new ProtobufDecoder());

    HashMap<String, String> addressBookProperties = new HashMap<>();
    addressBookProperties.put("protobuf.messageType", "AddressBook");


    /*
        First try to decode using a schema set in a processor property
     */

    runner.setProperty("protobuf.schemaPath", ProtobufDecoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
    runner.assertValid();

    runner.enqueue(ProtobufDecoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS);

    // Finally check the content
    MockFlowFile result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode expected = mapper.readTree(this.getClass().getResourceAsStream("/data/AddressBook_basic.json"));
    JsonNode given = mapper.readTree(runner.getContentAsByteArray(result));
    Assert.assertEquals("The parsing result of AddressBook_basic.data is not as expected", expected, given);


    /*
        Then try to remove the schema from the processor property and see if it still parse
     */

    runner.clearTransferState();
    runner.removeProperty(runner.getProcessor().getPropertyDescriptor("protobuf.schemaPath"));
    Assert.assertFalse("The schema property should now be null", runner.getProcessContext().getProperty("protobuf.schemaPath").isSet());
    runner.assertValid();

    runner.enqueue(ProtobufDecoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.INVALID_SCHEMA);


    /*
        Finally add the property again to see if it works again
     */

    runner.clearTransferState();
    runner.setProperty("protobuf.schemaPath", ProtobufDecoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
    runner.assertValid();

    runner.enqueue(ProtobufDecoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS);

    // Finally check the content
    result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0);
    expected = mapper.readTree(this.getClass().getResourceAsStream("/data/AddressBook_basic.json"));
    given = mapper.readTree(runner.getContentAsByteArray(result));
    Assert.assertEquals("The parsing result of AddressBook_basic.data is not as expected", expected, given);

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

示例4: onPropertyModified

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void onPropertyModified() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(new ProtobufEncoder());

    HashMap<String, String> addressBookProperties = new HashMap<>();
    addressBookProperties.put("protobuf.messageType", "AddressBook");


    /*
        First try to decode using a schema set in a processor property
     */

    runner.setProperty("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
    runner.assertValid();

    runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS);

    // Finally check the content
    MockFlowFile result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0);
    result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"));


    /*
        Then try to remove the schema from the processor property and see if it still parse
     */

    runner.clearTransferState();
    runner.removeProperty(runner.getProcessor().getPropertyDescriptor("protobuf.schemaPath"));
    Assert.assertFalse("The schema property should now be null", runner.getProcessContext().getProperty("protobuf.schemaPath").isSet());
    runner.assertValid();

    runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.INVALID_SCHEMA);


    /*
        Finally add the property again to see if it works again
     */

    runner.clearTransferState();
    runner.setProperty("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath());
    runner.assertValid();

    runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties);

    runner.run(1);

    // Check if the flowfile has been successfully processed
    runner.assertQueueEmpty();
    runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS);

    // Finally check the content
    result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0);
    result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"));

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


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