Ensure tests pass when sun.misc.Unsafe is not present
Motivation: We need to ensure we pass all tests when sun.misc.Unsafe is not present. Modifications: - Make *ByteBufAllocatorTest work whenever sun.misc.Unsafe is present or not Result: Tests pass even without sun.misc.Unsafe.
This commit is contained in:
parent
2d558b3c2b
commit
73af7c9215
@ -15,11 +15,18 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
|
||||||
public abstract class AbstractByteBufAllocatorTest extends ByteBufAllocatorTest {
|
public abstract class AbstractByteBufAllocatorTest extends ByteBufAllocatorTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected abstract AbstractByteBufAllocator newAllocator(boolean preferDirect);
|
protected abstract AbstractByteBufAllocator newAllocator(boolean preferDirect);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isDirectExpected(boolean preferDirect) {
|
||||||
|
return preferDirect && PlatformDependent.hasUnsafe();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final int defaultMaxCapacity() {
|
protected final int defaultMaxCapacity() {
|
||||||
return AbstractByteBufAllocator.DEFAULT_MAX_CAPACITY;
|
return AbstractByteBufAllocator.DEFAULT_MAX_CAPACITY;
|
||||||
|
@ -37,7 +37,7 @@ public abstract class ByteBufAllocatorTest {
|
|||||||
ByteBufAllocator allocator = newAllocator(preferDirect);
|
ByteBufAllocator allocator = newAllocator(preferDirect);
|
||||||
ByteBuf buffer = allocator.buffer(1);
|
ByteBuf buffer = allocator.buffer(1);
|
||||||
try {
|
try {
|
||||||
assertBuffer(buffer, preferDirect, 1, defaultMaxCapacity());
|
assertBuffer(buffer, isDirectExpected(preferDirect), 1, defaultMaxCapacity());
|
||||||
} finally {
|
} finally {
|
||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
@ -53,12 +53,14 @@ public abstract class ByteBufAllocatorTest {
|
|||||||
ByteBufAllocator allocator = newAllocator(preferDirect);
|
ByteBufAllocator allocator = newAllocator(preferDirect);
|
||||||
ByteBuf buffer = allocator.buffer(1, maxCapacity);
|
ByteBuf buffer = allocator.buffer(1, maxCapacity);
|
||||||
try {
|
try {
|
||||||
assertBuffer(buffer, preferDirect, 1, maxCapacity);
|
assertBuffer(buffer, isDirectExpected(preferDirect), 1, maxCapacity);
|
||||||
} finally {
|
} finally {
|
||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract boolean isDirectExpected(boolean preferDirect);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeapBuffer() {
|
public void testHeapBuffer() {
|
||||||
testHeapBuffer(true);
|
testHeapBuffer(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user