本文整理汇总了Java中org.apache.nifi.util.TestRunner.assertTransferCount方法的典型用法代码示例。如果您正苦于以下问题:Java TestRunner.assertTransferCount方法的具体用法?Java TestRunner.assertTransferCount怎么用?Java TestRunner.assertTransferCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.TestRunner
的用法示例。
在下文中一共展示了TestRunner.assertTransferCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: payloadWithBadFloatSubstitution
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithBadFloatSubstitution() {
String payload = "{\"pi\": \"{{pi:float}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("pi", "This is not a float!");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 1);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 0);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
FlowFile actualFlowFile = runner.getFlowFilesForRelationship(CreateJsonContent.REL_FAILURE).get(0);
assertEquals("$.pi", actualFlowFile.getAttribute("json.error.key"));
assertEquals("This is not a float!", actualFlowFile.getAttribute("json.error.value"));
}
示例2: testNoResults
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testNoResults() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new QueryMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.QUERY, "{\"criteria\": \"${test_attribute}\"}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "test_attribute", "98765");
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 0);
}
示例3: payloadWithoutSubstitutions
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithoutSubstitutions() {
String payload = "{\"a\": \"a\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
runner.enqueue(payload.getBytes());
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
assertEquals(payload, new String(out.toByteArray()));
}
示例4: payloadWithSubstitutions
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithSubstitutions() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"boolean\": {{boolean}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("boolean", "true");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"boolean\": true}";
final MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
assertEquals(expected, new String(out.toByteArray()));
}
示例5: payloadWithTokenAttributes
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithTokenAttributes() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("text", "\"here is some {{text}}\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some {{text}}\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例6: insert_refined_payload_test
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void insert_refined_payload_test() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
String contents = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
runner.enqueue(contents.getBytes());
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 1);
// Verify Wrapped Payload
MockFlowFile out = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_SUCCESS).get(0);
BasicDBObject actual = (BasicDBObject) JSON.parse(new String(out.toByteArray(), StandardCharsets.UTF_8));
assertNotNull(actual.getString("d"));
}
示例7: testBackPressured
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testBackPressured() {
final TestRunner runner = TestRunners.newTestRunner(RouteOnBackPressure.class);
runner.assertValid();
for (int i = 0; i < 100; ++i) {
runner.enqueue(new byte[0]);
}
runner.run(100);
runner.assertTransferCount(RouteOnBackPressure.PASS_THROUGH, 100);
runner.assertTransferCount(RouteOnBackPressure.BACK_PRESSURED, 0);
runner.setRelationshipUnavailable(RouteOnBackPressure.PASS_THROUGH);
for (int i = 0; i < 100; ++i) {
runner.enqueue(new byte[0]);
}
runner.run(100);
runner.assertTransferCount(RouteOnBackPressure.PASS_THROUGH, 100);
runner.assertTransferCount(RouteOnBackPressure.BACK_PRESSURED, 100);
}
示例8: testMalformedJsonUpdate
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testMalformedJsonUpdate() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new UpdateMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.UPDATE_QUERY_KEYS, "d.id");
runner.setProperty(MongoProps.UPDATE_KEYS, "d.media");
runner.setProperty(MongoProps.UPDATE_OPERATOR, "$push");
runner.enqueue("bad payload".getBytes());
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 0);
}
示例9: testQuery
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testQuery() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new QueryMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.QUERY, "{\"criteria\": \"${test_attribute}\"}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "test_attribute", "12345");
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 1);
MockFlowFile out = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_SUCCESS).get(0);
BasicDBObject actual = (BasicDBObject) JSON.parse(new String(out.toByteArray(), StandardCharsets.UTF_8));
assertEquals("[ \"12345\" , \"23456\" , \"34567\"]", actual.getString("criteria"));
}
示例10: 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");
}
示例11: payloadWithSpecialCharacters
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithSpecialCharacters() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", "\"here is some &$^()}{{}[email protected]#\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"text\":\"\\\"here is some &$^()}{{}[email protected]#\\\"\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例12: insert_test
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void insert_test() 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.enqueue("{\"a\":\"a\"}".getBytes());
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 1);
// Verify Wrapped Payload
MockFlowFile out = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_SUCCESS).get(0);
BasicDBObject actual = (BasicDBObject) JSON.parse(new String(out.toByteArray(), StandardCharsets.UTF_8));
assertEquals("a", actual.getString("a"));
}
示例13: payloadWithSpacesWithinDelimiters
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithSpacesWithinDelimiters() {
String payload = "{\"a\": \"{{ from}}\", \"pi\": \"{{pi }}\", \"text\": \" {{ text }} \"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", "here is some text");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":\"3.14\",\"text\":\"here is some text\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例14: payloadWithSpanishCharacters
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithSpanishCharacters() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14"); // This should be a string representation of the number 3.14
props.put("text", "Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":\"3.14\",\"text\":\"Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例15: testTrueHeaderCreation
import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testTrueHeaderCreation() {
TestRunner runner = TestRunners.newTestRunner(new GenerateTimeSeriesFlowFile());
runner.setProperty(GenerateTimeSeriesFlowFile.PRINT_HEADER, "true");
runner.setProperty(GenerateTimeSeriesFlowFile.SIMULATOR_CONFIG, getClass().getResource("/configs/unitTestConfig.json").getPath());
runner.setProperty(GenerateTimeSeriesFlowFile.DATA_FORMAT, "CSV");
runner.run();
runner.assertTransferCount(GenerateTimeSeriesFlowFile.SUCCESS, 1);
runner.getFlowFilesForRelationship(GenerateTimeSeriesFlowFile.SUCCESS).get(0).assertContentEquals("name, ts, value" + System.lineSeparator() + "test,2016-01-01T00:00:00.000,17.5");
}