本文整理汇总了Java中org.apache.nifi.util.TestRunner.assertQueueEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java TestRunner.assertQueueEmpty方法的具体用法?Java TestRunner.assertQueueEmpty怎么用?Java TestRunner.assertQueueEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.TestRunner
的用法示例。
在下文中一共展示了TestRunner.assertQueueEmpty方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testBulkSingle
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testBulkSingle() {
final TestRunner runner = TestRunners.newTestRunner(new AutoTerminator());
runner.setProperty(AutoTerminator.BULK, "1");
runner.enqueue("sample1".getBytes());
runner.enqueue("sample2".getBytes());
runner.enqueue("sample3".getBytes());
runner.run();
runner.assertQueueNotEmpty();
runner.run();
runner.assertQueueNotEmpty();
runner.run();
runner.assertQueueEmpty();
}
示例6: testBulk
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testBulk() {
final TestRunner runner = TestRunners.newTestRunner(new AutoTerminator());
runner.setProperty(AutoTerminator.BULK, "10");
runner.enqueue("sample1".getBytes());
runner.enqueue("sample2".getBytes());
runner.enqueue("sample3".getBytes());
runner.run();
runner.assertQueueEmpty();
}
示例7: 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);
}
示例8: 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"));
}