Java Code Examples for org.apache.nifi.util.RingBuffer#add()
The following examples show how to use
org.apache.nifi.util.RingBuffer#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRingBuffer.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testIterateForwards() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } final AtomicInteger countHolder = new AtomicInteger(0); ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { final int expected = values[counter++]; countHolder.incrementAndGet(); assertEquals(expected, value.intValue()); return true; } }, IterationDirection.FORWARD); assertEquals(4, countHolder.get()); }
Example 2
Source File: TestRingBuffer.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testIterateForwards() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } final AtomicInteger countHolder = new AtomicInteger(0); ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { final int expected = values[counter++]; countHolder.incrementAndGet(); assertEquals(expected, value.intValue()); return true; } }, IterationDirection.FORWARD); assertEquals(4, countHolder.get()); }
Example 3
Source File: TestRingBuffer.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testGetNewestElement() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); for (int i = 0; i < 11; i++) { ringBuffer.add(i); assertEquals(i, ringBuffer.getNewestElement().intValue()); } }
Example 4
Source File: TestRingBuffer.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testAsList() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); final List<Integer> emptyList = ringBuffer.asList(); assertTrue(emptyList.isEmpty()); for (int i = 0; i < 3; i++) { ringBuffer.add(i); } List<Integer> list = ringBuffer.asList(); assertEquals(3, list.size()); for (int i = 0; i < 3; i++) { assertEquals(Integer.valueOf(i), list.get(i)); } for (int i = 3; i < 10; i++) { ringBuffer.add(i); } list = ringBuffer.asList(); assertEquals(10, list.size()); for (int i = 0; i < 10; i++) { assertEquals(Integer.valueOf(i), list.get(i)); } }
Example 5
Source File: TestRingBuffer.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testIterateForwardsAfterFull() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); for (int i = 0; i < 12; i++) { ringBuffer.add(i); } final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { if (counter < 6) { assertEquals(counter + 6, value.intValue()); } else { final int expected = values[counter - 6]; assertEquals(expected, value.intValue()); } counter++; return true; } }, IterationDirection.FORWARD); }
Example 6
Source File: TestRingBuffer.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testIterateBackwards() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } final AtomicInteger countHolder = new AtomicInteger(0); ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { final int index = values.length - 1 - counter; final int expected = values[index]; countHolder.incrementAndGet(); assertEquals(expected, value.intValue()); counter++; return true; } }, IterationDirection.BACKWARD); assertEquals(4, countHolder.get()); }
Example 7
Source File: TestRingBuffer.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testIterateBackwardsAfterFull() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); for (int i = 0; i < 12; i++) { ringBuffer.add(i); } final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { if (counter < values.length) { final int index = values.length - 1 - counter; final int expected = values[index]; assertEquals(expected, value.intValue()); counter++; } return true; } }, IterationDirection.BACKWARD); }
Example 8
Source File: TestRingBuffer.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testGetNewestElement() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); for (int i = 0; i < 11; i++) { ringBuffer.add(i); assertEquals(i, ringBuffer.getNewestElement().intValue()); } }
Example 9
Source File: TestRingBuffer.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testAsList() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); final List<Integer> emptyList = ringBuffer.asList(); assertTrue(emptyList.isEmpty()); for (int i = 0; i < 3; i++) { ringBuffer.add(i); } List<Integer> list = ringBuffer.asList(); assertEquals(3, list.size()); for (int i = 0; i < 3; i++) { assertEquals(Integer.valueOf(i), list.get(i)); } for (int i = 3; i < 10; i++) { ringBuffer.add(i); } list = ringBuffer.asList(); assertEquals(10, list.size()); for (int i = 0; i < 10; i++) { assertEquals(Integer.valueOf(i), list.get(i)); } }
Example 10
Source File: TestRingBuffer.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testIterateForwardsAfterFull() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); for (int i = 0; i < 12; i++) { ringBuffer.add(i); } final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { if (counter < 6) { assertEquals(counter + 6, value.intValue()); } else { final int expected = values[counter - 6]; assertEquals(expected, value.intValue()); } counter++; return true; } }, IterationDirection.FORWARD); }
Example 11
Source File: TestRingBuffer.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testIterateBackwards() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } final AtomicInteger countHolder = new AtomicInteger(0); ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { final int index = values.length - 1 - counter; final int expected = values[index]; countHolder.incrementAndGet(); assertEquals(expected, value.intValue()); counter++; return true; } }, IterationDirection.BACKWARD); assertEquals(4, countHolder.get()); }
Example 12
Source File: TestRingBuffer.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testIterateBackwardsAfterFull() { final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10); for (int i = 0; i < 12; i++) { ringBuffer.add(i); } final int[] values = new int[]{3, 5, 20, 7}; for (final int v : values) { ringBuffer.add(v); } ringBuffer.forEach(new ForEachEvaluator<Integer>() { int counter = 0; @Override public boolean evaluate(final Integer value) { if (counter < values.length) { final int index = values.length - 1 - counter; final int expected = values[index]; assertEquals(expected, value.intValue()); counter++; } return true; } }, IterationDirection.BACKWARD); }
Example 13
Source File: LatestEventsPerProcessorQuery.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void update(final ProvenanceEventRecord event, final StorageSummary storageSummary) { final String componentId = event.getComponentId(); final RingBuffer<Long> ringBuffer = latestRecords.computeIfAbsent(componentId, id -> new RingBuffer<>(1000)); ringBuffer.add(storageSummary.getEventId()); }
Example 14
Source File: VolatileBulletinRepository.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void update(final Bulletin bulletin) { for (final RingBuffer<Bulletin> bulletinBuffer : getBulletinBuffers(bulletin)) { bulletinBuffer.add(bulletin); } }
Example 15
Source File: LatestEventsPerProcessorQuery.java From nifi with Apache License 2.0 | 4 votes |
@Override public void update(final ProvenanceEventRecord event, final StorageSummary storageSummary) { final String componentId = event.getComponentId(); final RingBuffer<Long> ringBuffer = latestRecords.computeIfAbsent(componentId, id -> new RingBuffer<>(1000)); ringBuffer.add(storageSummary.getEventId()); }
Example 16
Source File: VolatileBulletinRepository.java From nifi with Apache License 2.0 | 4 votes |
@Override public void update(final Bulletin bulletin) { for (final RingBuffer<Bulletin> bulletinBuffer : getBulletinBuffers(bulletin)) { bulletinBuffer.add(bulletin); } }