本文整理汇总了Java中org.apache.nifi.processor.ProcessSession.create方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessSession.create方法的具体用法?Java ProcessSession.create怎么用?Java ProcessSession.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.processor.ProcessSession
的用法示例。
在下文中一共展示了ProcessSession.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTrigger
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
FlowFile original = session.get();
FlowFile flowFile;
if (original == null) {
flowFile = session.create();
session.getProvenanceReporter().create(flowFile);
} else {
flowFile = session.clone(original);
session.transfer(original, REL_ORIGINAL);
}
final String updatedContent = StringFormatter.format(context.getProperty(CONTENT_FIELD).getValue(), flowFile.getAttributes());
this.getLogger().debug("Created content: {}", new Object[]{updatedContent});
flowFile = session.write(flowFile, outputStream -> outputStream.write(updatedContent.getBytes(StandardCharsets.UTF_8)));
session.getProvenanceReporter().modifyContent(flowFile);
session.transfer(flowFile, REL_SUCCESS);
}
示例2: payloadWithSpanishCharacters
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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);
}
示例3: singleAttributeTest
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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");
}
示例4: payloadWithBadIntSubstitution
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Test
public void payloadWithBadIntSubstitution() {
String payload = "{\"time\": \"{{time:int}}\"}";
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("time", "2015-06-22T13:45:23.000Z");
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("$.time", actualFlowFile.getAttribute("json.error.key"));
assertEquals("2015-06-22T13:45:23.000Z", actualFlowFile.getAttribute("json.error.value"));
}
示例5: payloadWithSpecialCharacters
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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);
}
示例6: sendStatsIfPresent
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
/**
* Send a flowfile with the stats as attributes: IF the report time is exceeded AND there are
* stats to send
*/
private void sendStatsIfPresent(ProcessSession session, long currentTimestamp) {
if (currentTimestamp < lastReportTime + reportingIntervalMillis) {
return;
}
for (Map.Entry<String, Optional<Map<String, String>>> statsMap : latestStats.entrySet()) {
String statsMapKey = statsMap.getKey();
Optional<Map<String, String>> result = buildStatAttributes(currentTimestamp, momentsMap.get(statsMapKey));
if (result.isPresent()) {
Map<String, String> attrs = new HashMap<>(result.get());
attrs.put("AbstractStatsProcessor.correlationKey", statsMapKey);
String uuid = UUID.randomUUID().toString();
attrs.put(CoreAttributes.UUID.key(), uuid);
attrs.put(CoreAttributes.FILENAME.key(), statsMapKey + "_" + System.currentTimeMillis() + "_" + uuid);
FlowFile statsFlowFile = session.create();
statsFlowFile = session.putAllAttributes(statsFlowFile, attrs);
session.getProvenanceReporter().create(statsFlowFile);
session.transfer(statsFlowFile, REL_STATS);
}
}
lastReportTime = currentTimestamp;
momentsMap.values().forEach(MomentAggregator::reset);
}
示例7: testQuery
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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"));
}
示例8: payloadWithMissingAttributes
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Test
public void payloadWithMissingAttributes() {
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");
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\": null}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例9: payloadWithTokenAttributes
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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);
}
示例10: payloadWithTokenAttributes
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Test
public void payloadWithTokenAttributes() {
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 {{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);
}
示例11: payloadWithDoubleQuotes
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Test
public void payloadWithDoubleQuotes() {
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);
}
示例12: testNoResults
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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);
}
示例13: payloadWithSpanishCharacters
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Test
public void payloadWithSpanishCharacters() {
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", "\"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(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\": \"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(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例14: payloadWithBadFloatSubstitution
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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"));
}
示例15: payloadWithSubstitutions
import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Test
public void payloadWithSubstitutions() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"boolean\": \"{{boolean:bool}}\", \"long\": \"{{long:int}}\"}";
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("long", "12345678901234");
props.put("boolean", "true");
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,\"boolean\":true,\"long\":12345678901234}";
final MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
assertEquals(expected, new String(out.toByteArray()));
}