From c7bd6870bddce0d75ce4dc192f833b232f31d39b Mon Sep 17 00:00:00 2001 From: Martin Thompson Date: Mon, 28 Oct 2019 07:01:39 +0000 Subject: [PATCH] Revert "Fix bug in ExpandableRingBuffer" --- .../java/org/agrona/ExpandableRingBuffer.java | 20 ++++++++----------- .../org/agrona/ExpandableRingBufferTest.java | 19 ------------------ 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/agrona/src/main/java/org/agrona/ExpandableRingBuffer.java b/agrona/src/main/java/org/agrona/ExpandableRingBuffer.java index 1af2d854a..957593c38 100644 --- a/agrona/src/main/java/org/agrona/ExpandableRingBuffer.java +++ b/agrona/src/main/java/org/agrona/ExpandableRingBuffer.java @@ -386,19 +386,15 @@ public boolean append(final DirectBuffer srcBuffer, final int srcOffset, final i else if (tailOffset >= headOffset) { final int toEndRemaining = capacity - tailOffset; - - if (alignedLength > toEndRemaining) + if (alignedLength > toEndRemaining && alignedLength <= (totalRemaining - toEndRemaining)) { - if (alignedLength <= (totalRemaining - toEndRemaining)) - { - buffer.putInt(tailOffset + MESSAGE_LENGTH_OFFSET, toEndRemaining); - buffer.putInt(tailOffset + MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_PADDING); - tail += toEndRemaining; - } - else - { - resize(alignedLength); - } + buffer.putInt(tailOffset + MESSAGE_LENGTH_OFFSET, toEndRemaining); + buffer.putInt(tailOffset + MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_PADDING); + tail += toEndRemaining; + } + else + { + resize(alignedLength); } } diff --git a/agrona/src/test/java/org/agrona/ExpandableRingBufferTest.java b/agrona/src/test/java/org/agrona/ExpandableRingBufferTest.java index d8fe77057..4f6c55330 100644 --- a/agrona/src/test/java/org/agrona/ExpandableRingBufferTest.java +++ b/agrona/src/test/java/org/agrona/ExpandableRingBufferTest.java @@ -181,25 +181,6 @@ public void shouldAppendThenIterateMessagesInOrder() inOrder.verify(mockConsumer).onMessage(any(MutableDirectBuffer.class), anyInt(), eq(MSG_LENGTH_TWO), anyInt()); } - @Test - public void shouldAppendMessagesWithinCapacityWithoutExpanding() - { - final int initialCapacity = 1024; - final int maxCapacity = 2048; - - final ExpandableRingBuffer ringBuffer = new ExpandableRingBuffer(initialCapacity, maxCapacity, false); - - final ExpandableRingBuffer.MessageConsumer mockConsumer = mock(ExpandableRingBuffer.MessageConsumer.class); - when(mockConsumer.onMessage(any(), anyInt(), anyInt(), anyInt())).thenReturn(Boolean.TRUE); - - assertThat(ringBuffer.capacity(), is(initialCapacity)); - - final int messageLength = 32; - ringBuffer.append(TEST_MSG, 0, messageLength); - - assertThat(ringBuffer.capacity(), is(initialCapacity)); - } - @Test public void shouldAppendMessagesWithPaddingWithoutExpanding() {