@Test public void testPrioritizer() throws InstantiationException, IllegalAccessException { final Processor processor = new SimpleProcessor(); final AtomicLong idGenerator = new AtomicLong(0L); final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, idGenerator), Mockito.mock(Processor.class)); final MockFlowFile ffNoPriority = session.create(); final MockFlowFile ffPri1 = session.create(); ffPri1.putAttributes(attrsPri1); final MockFlowFile ffPri2 = session.create(); ffPri2.putAttributes(attrsPri2); final MockFlowFile ffPrin1 = session.create(); ffPrin1.putAttributes(attrsPrin1); final MockFlowFile ffPriA = session.create(); ffPriA.putAttributes(attrsPriA); final MockFlowFile ffPriB = session.create(); ffPriB.putAttributes(attrsPriB); final MockFlowFile ffPriLP = session.create(); ffPriLP.putAttributes(attrsPriLP); final MockFlowFile ffPriLN = session.create(); ffPriLN.putAttributes(attrsPriLN); final PriorityAttributePrioritizer prioritizer = new PriorityAttributePrioritizer(); assertEquals(0, prioritizer.compare(null, null)); assertEquals(-1, prioritizer.compare(ffNoPriority, null)); assertEquals(1, prioritizer.compare(null, ffNoPriority)); assertEquals(-1, prioritizer.compare(ffNoPriority, ffNoPriority)); assertEquals(-1, prioritizer.compare(ffPri1, ffNoPriority)); assertEquals(1, prioritizer.compare(ffNoPriority, ffPri1)); assertEquals(0, prioritizer.compare(ffPri1, ffPri1)); assertEquals(-1, prioritizer.compare(ffPri1, ffPri2)); assertEquals(1, prioritizer.compare(ffPri2, ffPri1)); assertEquals(-1, prioritizer.compare(ffPrin1, ffPri1)); assertEquals(1, prioritizer.compare(ffPri1, ffPrin1)); assertEquals(-1, prioritizer.compare(ffPri1, ffPriA)); assertEquals(1, prioritizer.compare(ffPriA, ffPri1)); assertEquals(0, prioritizer.compare(ffPriA, ffPriA)); assertEquals(-1, prioritizer.compare(ffPriA, ffPriB)); assertEquals(1, prioritizer.compare(ffPriB, ffPriA)); assertEquals(1, prioritizer.compare(ffPriLP, ffPri1)); assertEquals(-1, prioritizer.compare(ffPri1, ffPriLP)); assertEquals(-1, prioritizer.compare(ffPriLN, ffPri1)); assertEquals(1, prioritizer.compare(ffPri1, ffPriLN)); }
@Override public int compare(FlowFile o1, FlowFile o2) { if (o1 == null && o2 == null) { return 0; } else if (o2 == null) { return -1; } else if (o1 == null) { return 1; } String o1Priority = o1.getAttribute(CoreAttributes.PRIORITY.key()); String o2Priority = o2.getAttribute(CoreAttributes.PRIORITY.key()); if (o1Priority == null && o2Priority == null) { return -1; } else if (o2Priority == null) { return -1; } else if (o1Priority == null) { return 1; } if (intPattern.matcher(o1Priority.trim()).matches()) { if (intPattern.matcher(o2Priority.trim()).matches()) { try { long o1num = Long.parseLong(o1Priority.trim()); long o2num = Long.parseLong(o2Priority.trim()); return o1num < o2num ? -1 : (o1num > o2num ? 1 : 0); } catch (NumberFormatException e) { return 0; } } else { return -1; } } else { if (intPattern.matcher(o2Priority.trim()).matches()) { return 1; } else { return o1Priority.compareTo(o2Priority); } } }
PriorityAttributePrioritizer implements FlowFilePrioritizer { @Override public int compare(FlowFile o1, FlowFile o2) { if (o1 == null && o2 == null) { return 0; } else if (o2 == null) { return -1; } else if (o1 == null) { return 1; } String o1Priority = o1.getAttribute(CoreAttributes.PRIORITY.key()); String o2Priority = o2.getAttribute(CoreAttributes.PRIORITY.key()); if (o1Priority == null && o2Priority == null) { return -1; } else if (o2Priority == null) { return -1; } else if (o1Priority == null) { return 1; } if (intPattern.matcher(o1Priority.trim()).matches()) { if (intPattern.matcher(o2Priority.trim()).matches()) { try { long o1num = Long.parseLong(o1Priority.trim()); long o2num = Long.parseLong(o2Priority.trim()); return o1num < o2num ? -1 : (o1num > o2num ? 1 : 0); } catch (NumberFormatException e) { return 0; } } else { return -1; } } else { if (intPattern.matcher(o2Priority.trim()).matches()) { return 1; } else { return o1Priority.compareTo(o2Priority); } } } }
PriorityAttributePrioritizer implements FlowFilePrioritizer { @Override public int compare(FlowFile o1, FlowFile o2) { if (o1 == null && o2 == null) { return 0; } else if (o2 == null) { return -1; } else if (o1 == null) { return 1; } String o1Priority = o1.getAttribute(CoreAttributes.PRIORITY.key()); String o2Priority = o2.getAttribute(CoreAttributes.PRIORITY.key()); if (o1Priority == null && o2Priority == null) { return -1; } else if (o2Priority == null) { return -1; } else if (o1Priority == null) { return 1; } if (intPattern.matcher(o1Priority.trim()).matches()) { if (intPattern.matcher(o2Priority.trim()).matches()) { try { long o1num = Long.parseLong(o1Priority.trim()); long o2num = Long.parseLong(o2Priority.trim()); return o1num < o2num ? -1 : (o1num > o2num ? 1 : 0); } catch (NumberFormatException e) { return 0; } } else { return -1; } } else { if (intPattern.matcher(o2Priority.trim()).matches()) { return 1; } else { return o1Priority.compareTo(o2Priority); } } }  }
PriorityAttributePrioritizer implements FlowFilePrioritizer { @Override public int compare(FlowFile o1, FlowFile o2) { if (o1 == null && o2 == null) { return 0; } else if (o2 == null) { return -1; } else if (o1 == null) { return 1; } String o1Priority = o1.getAttribute(CoreAttributes.PRIORITY.key()); String o2Priority = o2.getAttribute(CoreAttributes.PRIORITY.key()); if (o1Priority == null && o2Priority == null) { return -1; } else if (o2Priority == null) { return -1; } else if (o1Priority == null) { return 1; } if (intPattern.matcher(o1Priority.trim()).matches()) { if (intPattern.matcher(o2Priority.trim()).matches()) { try { long o1num = Long.parseLong(o1Priority.trim()); long o2num = Long.parseLong(o2Priority.trim()); return o1num < o2num ? -1 : (o1num > o2num ? 1 : 0); } catch (NumberFormatException e) { return 0; } } else { return -1; } } else { if (intPattern.matcher(o2Priority.trim()).matches()) { return 1; } else { return o1Priority.compareTo(o2Priority); } } }  @Override int compare(FlowFile o1, FlowFile o2); }
PriorityAttributePrioritizer implements FlowFilePrioritizer { @Override public int compare(FlowFile o1, FlowFile o2) { if (o1 == null && o2 == null) { return 0; } else if (o2 == null) { return -1; } else if (o1 == null) { return 1; } String o1Priority = o1.getAttribute(CoreAttributes.PRIORITY.key()); String o2Priority = o2.getAttribute(CoreAttributes.PRIORITY.key()); if (o1Priority == null && o2Priority == null) { return -1; } else if (o2Priority == null) { return -1; } else if (o1Priority == null) { return 1; } if (intPattern.matcher(o1Priority.trim()).matches()) { if (intPattern.matcher(o2Priority.trim()).matches()) { try { long o1num = Long.parseLong(o1Priority.trim()); long o2num = Long.parseLong(o2Priority.trim()); return o1num < o2num ? -1 : (o1num > o2num ? 1 : 0); } catch (NumberFormatException e) { return 0; } } else { return -1; } } else { if (intPattern.matcher(o2Priority.trim()).matches()) { return 1; } else { return o1Priority.compareTo(o2Priority); } } }  @Override int compare(FlowFile o1, FlowFile o2);  }