mirror of https://github.com/apache/nifi.git
NIFI-398: Fixed ArrayIndexOutOfBoundsException and added unit test to verify
This commit is contained in:
parent
608f8007ed
commit
342ca1791a
|
@ -185,7 +185,7 @@ public class RingBuffer<T> {
|
|||
public T getNewestElement() {
|
||||
readLock.lock();
|
||||
try {
|
||||
int index = (insertionPointer == 0) ? buffer.length : insertionPointer - 1;
|
||||
int index = (insertionPointer == 0) ? buffer.length - 1 : insertionPointer - 1;
|
||||
return getElementData(index);
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
|
|
|
@ -33,6 +33,16 @@ import org.junit.Test;
|
|||
*/
|
||||
public class TestRingBuffer {
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsList() {
|
||||
final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10);
|
||||
|
|
Loading…
Reference in New Issue