Restore derived buffer index/mark updates
Motivation: As part of the revert process in https://github.com/netty/netty/pull/4138 some index and mark updates were lost. Modifications: - Restore the index / mark updates made in https://github.com/netty/netty/pull/3788 Result: Slice and Duplicate buffers index / marks are correctly initialized.
This commit is contained in:
parent
1525edfde7
commit
09dff41343
@ -43,6 +43,8 @@ public class DuplicatedByteBuf extends AbstractDerivedByteBuf {
|
||||
}
|
||||
|
||||
setIndex(buffer.readerIndex(), buffer.writerIndex());
|
||||
markReaderIndex();
|
||||
markWriterIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,7 @@ package io.netty.buffer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests duplicated channel buffers
|
||||
@ -28,8 +28,10 @@ public class DuplicateByteBufTest extends AbstractByteBufTest {
|
||||
|
||||
@Override
|
||||
protected ByteBuf newBuffer(int length) {
|
||||
buffer = new DuplicatedByteBuf(Unpooled.buffer(length));
|
||||
assertEquals(0, buffer.writerIndex());
|
||||
ByteBuf wrapped = Unpooled.buffer(length);
|
||||
buffer = new DuplicatedByteBuf(wrapped);
|
||||
assertEquals(wrapped.writerIndex(), buffer.writerIndex());
|
||||
assertEquals(wrapped.readerIndex(), buffer.readerIndex());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -54,4 +56,26 @@ public class DuplicateByteBufTest extends AbstractByteBufTest {
|
||||
|
||||
assertEquals((byte) 0, buffer.readByte());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarksInitialized() {
|
||||
ByteBuf wrapped = Unpooled.buffer(8);
|
||||
try {
|
||||
wrapped.writerIndex(6);
|
||||
wrapped.readerIndex(1);
|
||||
ByteBuf duplicate = new DuplicatedByteBuf(wrapped);
|
||||
|
||||
// Test writer mark
|
||||
duplicate.writerIndex(duplicate.writerIndex() + 1);
|
||||
duplicate.resetWriterIndex();
|
||||
assertEquals(wrapped.writerIndex(), duplicate.writerIndex());
|
||||
|
||||
// Test reader mark
|
||||
duplicate.readerIndex(duplicate.readerIndex() + 1);
|
||||
duplicate.resetReaderIndex();
|
||||
assertEquals(wrapped.readerIndex(), duplicate.readerIndex());
|
||||
} finally {
|
||||
wrapped.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,12 @@
|
||||
*/
|
||||
package io.netty.buffer;
|
||||
|
||||
import io.netty.util.IllegalReferenceCountException;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests sliced channel buffers
|
||||
@ -114,4 +113,28 @@ public class SlicedByteBufTest extends AbstractByteBufTest {
|
||||
public void testLittleEndianWithExpand() {
|
||||
// ignore for SlicedByteBuf
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReaderIndexAndMarks() {
|
||||
ByteBuf wrapped = Unpooled.buffer(16);
|
||||
try {
|
||||
wrapped.writerIndex(14);
|
||||
wrapped.readerIndex(2);
|
||||
wrapped.markWriterIndex();
|
||||
wrapped.markReaderIndex();
|
||||
ByteBuf slice = new SlicedByteBuf(wrapped, 4, 4);
|
||||
assertEquals(0, slice.readerIndex());
|
||||
assertEquals(4, slice.writerIndex());
|
||||
|
||||
slice.readerIndex(slice.readerIndex() + 1);
|
||||
slice.resetReaderIndex();
|
||||
assertEquals(0, slice.readerIndex());
|
||||
|
||||
slice.writerIndex(slice.writerIndex() - 1);
|
||||
slice.resetWriterIndex();
|
||||
assertEquals(0, slice.writerIndex());
|
||||
} finally {
|
||||
wrapped.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user