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


Java ProcessSession.create方法代码示例

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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