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:
Norman Maurer 2017-02-13 08:35:45 +01:00
parent 2d558b3c2b
commit 73af7c9215
2 changed files with 11 additions and 2 deletions

View File

@ -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;

View File

@ -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);