Search in sources :

Example 6 with FirstInFirstOutPrioritizer

use of org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer in project nifi by apache.

the class TestEnforceOrder method testSort.

@Test
public void testSort() {
    final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
    runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
    runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
    runner.assertValid();
    Ordered.enqueue(runner, "b", 0);
    Ordered.enqueue(runner, "a", 1);
    Ordered.enqueue(runner, "a", 0);
    runner.run();
    runner.assertAllFlowFilesTransferred(EnforceOrder.REL_SUCCESS, 3);
    final List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(EnforceOrder.REL_SUCCESS);
    succeeded.sort(new FirstInFirstOutPrioritizer());
    succeeded.get(0).assertContentEquals("a.0");
    succeeded.get(1).assertContentEquals("a.1");
    succeeded.get(2).assertContentEquals("b.0");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) FirstInFirstOutPrioritizer(org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 7 with FirstInFirstOutPrioritizer

use of org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer in project nifi by apache.

the class TestEnforceOrder method testInitialOrderValue.

@Test
public void testInitialOrderValue() {
    final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
    runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
    runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
    runner.setProperty(EnforceOrder.INITIAL_ORDER, "${index.start}");
    runner.setProperty(EnforceOrder.MAX_ORDER, "${index.max}");
    runner.assertValid();
    runner.enqueue("b.0", Ordered.i("b", 0).put("index.start", "0").put("index.max", "99").map());
    runner.enqueue("a.100", Ordered.i("a", 100).put("index.start", "100").put("index.max", "103").map());
    runner.enqueue("a.101", Ordered.i("a", 101).put("index.start", "100").put("index.max", "103").map());
    runner.enqueue("illegal initial order", Ordered.i("c", 1).put("index.start", "non-integer").map());
    runner.enqueue("without initial order", Ordered.i("d", 1).map());
    // Even if this flow file doesn't have initial order attribute, this will be routed to success.
    // Because target order for group b is already computed from b.0.
    Ordered.enqueue(runner, "b", 1);
    runner.run();
    List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(EnforceOrder.REL_SUCCESS);
    assertEquals(4, succeeded.size());
    succeeded.sort(new FirstInFirstOutPrioritizer());
    succeeded.get(0).assertContentEquals("a.100");
    succeeded.get(1).assertContentEquals("a.101");
    succeeded.get(2).assertContentEquals("b.0");
    succeeded.get(3).assertContentEquals("b.1");
    final List<MockFlowFile> failed = runner.getFlowFilesForRelationship(EnforceOrder.REL_FAILURE);
    assertEquals(2, failed.size());
    failed.get(0).assertAttributeExists(EnforceOrder.ATTR_DETAIL);
    failed.get(0).assertContentEquals("illegal initial order");
    failed.get(1).assertAttributeExists(EnforceOrder.ATTR_DETAIL);
    failed.get(1).assertContentEquals("without initial order");
    final MockStateManager stateManager = runner.getStateManager();
    stateManager.assertStateEquals("a.target", "102", Scope.LOCAL);
    stateManager.assertStateEquals("a.max", "103", Scope.LOCAL);
    stateManager.assertStateEquals("b.target", "2", Scope.LOCAL);
    stateManager.assertStateEquals("b.max", "99", Scope.LOCAL);
    runner.clearTransferState();
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) FirstInFirstOutPrioritizer(org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer) MockStateManager(org.apache.nifi.state.MockStateManager) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Aggregations

FirstInFirstOutPrioritizer (org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer)7 MockFlowFile (org.apache.nifi.util.MockFlowFile)7 TestRunner (org.apache.nifi.util.TestRunner)7 Test (org.junit.Test)7 MockStateManager (org.apache.nifi.state.MockStateManager)3