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


Java TestRunner.enqueue方法代码示例

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


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

示例1: payloadWithSpecialCharacters

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithSpecialCharacters() {

    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 &$^()}{{}[email protected]#\"");
    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 &$^()}{{}[email protected]#\"}";
    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

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

示例3: payloadWithBadIntSubstitution

import org.apache.nifi.util.TestRunner; //导入方法依赖的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

示例4: 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

示例5: payloadWithTokenAttributes

import org.apache.nifi.util.TestRunner; //导入方法依赖的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

示例6: 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 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

示例7: payloadWithMissingAttributes

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void payloadWithMissingAttributes() {

    String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"boolean\": \"{{boolean:bool}}\"}";
    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");
    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\":null}";
    MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
    String actual = new String(out.toByteArray());
    assertEquals(expected, actual);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:26,代码来源:CreateJsonContentTest.java

示例8: testMixOfSuccessAndFailure

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testMixOfSuccessAndFailure() 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.setProperty(MongoProps.BATCH_SIZE, "50");

    String successOne = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
    runner.enqueue(successOne.getBytes());
    runner.enqueue("bad payload".getBytes());
    runner.enqueue("{\"a\":\"a\"}".getBytes());

    runner.run();

    runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
    runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 2);

    FlowFile failure = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE).get(0);
    String parseException = failure.getAttribute("mongo.exception");
    assertTrue(StringUtils.isNotBlank(parseException));

}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:24,代码来源:StoreInMongoIT.java

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

示例10: payloadWithMissingAttributes

import org.apache.nifi.util.TestRunner; //导入方法依赖的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

示例11: 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

示例12: 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");

}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:30,代码来源:Md5HashAttributesTest.java

示例13: testDuplicateKeyFailureOrderedFalse

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testDuplicateKeyFailureOrderedFalse() 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.setProperty(MongoProps.BATCH_SIZE, "10");
    runner.setProperty(MongoProps.ORDERED, "false");

    ObjectId objectId = ObjectId.get();

    String success = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
    String successTwo = "{\"a\":\"a\"}";
    String payloadOne = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"first value\"}";
    String payloadTwo = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"second value\"}";

    runner.enqueue(payloadOne.getBytes());
    runner.enqueue(success.getBytes());
    runner.enqueue(payloadTwo.getBytes());
    runner.enqueue(successTwo.getBytes()); // add another successful message

    runner.run();

    runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
    runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 3);

    FlowFile failure = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE).get(0);
    String errorCode = failure.getAttribute("mongo.errorcode");
    assertEquals("11000", errorCode); // duplicate key error code
    String errorMessage = failure.getAttribute("mongo.errormessage");
    assertTrue(StringUtils.isNotBlank(errorMessage));

    // Test contents of mongo
    MongoCollection<Document> collection = mongo.getMongoClient().getDatabase(MONGO_DATABASE_NAME).getCollection("insert_test");
    assertEquals(3L, collection.count());
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:37,代码来源:StoreInMongoIT.java

示例14: testUpsertFalse

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void testUpsertFalse() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateMongo());
    addMongoService(runner);
    runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
    runner.setProperty(MongoProps.COLLECTION, "upsert_test");
    runner.setProperty(MongoProps.UPDATE_QUERY_KEYS, "d.id");
    runner.setProperty(MongoProps.UPDATE_KEYS, "d.g");
    runner.setProperty(MongoProps.UPDATE_OPERATOR, "$unset");
    runner.setProperty(MongoProps.UPSERT, "false");

    String contents = FileUtils.readFileToString(Paths.get("src/test/resources/update_payload.json").toFile());

    runner.enqueue(contents.getBytes());
    runner.run();

    runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
    runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 1);

    // Verify that document wasn't inserted
    MongoClient client = mongo.getMongoClient();
    MongoDatabase db = client.getDatabase(MONGO_DATABASE_NAME);
    if (db != null) {
        MongoCollection<Document> collection = db.getCollection("upsert_test");
        assertEquals(0, collection.count());
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:28,代码来源:UpdateMongoIT.java

示例15: validateSuccessfulPublishAndTransferToSuccess

import org.apache.nifi.util.TestRunner; //导入方法依赖的package包/类
@Test
public void validateSuccessfulPublishAndTransferToSuccess() throws Exception {
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");

    final String destinationName = "fooQueue";
    PublishJMS pubProc = new PublishJMS();
    TestRunner runner = TestRunners.newTestRunner(pubProc);
    JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
    when(cs.getIdentifier()).thenReturn("cfProvider");
    when(cs.getConnectionFactory()).thenReturn(cf);

    runner.addControllerService("cfProvider", cs);
    runner.enableControllerService(cs);

    runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
    runner.setProperty(PublishJMS.DESTINATION, destinationName);

    Map<String, String> attributes = new HashMap<>();
    attributes.put("foo", "foo");
    attributes.put(JmsHeaders.REPLY_TO, "cooQueue");
    runner.enqueue("Hey dude!".getBytes(), attributes);
    runner.run(1, false);

    final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
    assertNotNull(successFF);

    JmsTemplate jmst = new JmsTemplate(cf);
    BytesMessage message = (BytesMessage) jmst.receive(destinationName);

    byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message);
    assertEquals("Hey dude!", new String(messageBytes));
    assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName());
    assertEquals("foo", message.getStringProperty("foo"));
}
 
开发者ID:SolaceLabs,项目名称:solace-integration-guides,代码行数:35,代码来源:PublishJMSTest.java


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