Java Code Examples for org.apache.nifi.util.RingBuffer#forEach()

The following examples show how to use org.apache.nifi.util.RingBuffer#forEach() . 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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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 4
Source File: TestRingBuffer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: TestRingBuffer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: TestRingBuffer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: TestRingBuffer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: TestRingBuffer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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);
}