Allow to build netty when sun.misc.Unsafe is not avaible or -Dio.netty.noUnsafe=true is used.

Motivation:

We support using Netty without sun.misc.Unsafe, so we should also support building it without it. This way we can also run all tests without sun.misc.Unsafe and so see if it works as expected.

Modifications:

Correctly skip tests that depend on sun.misc.Unsafe if its not present or -Dio.netty.noUnsafe=true is used.

Result:

Be able to build netty without sun.misc.Unsafe
This commit is contained in:
Norman Maurer 2016-11-29 14:35:06 +01:00 committed by Norman Maurer
parent feae0435b5
commit 5bc447c539
7 changed files with 30 additions and 5 deletions

View File

@ -23,8 +23,10 @@ import org.junit.Before;
public class BigEndianUnsafeDirectByteBufTest extends BigEndianDirectByteBufTest {
@Before
public void checkHasUnsafe() {
@Override
public void init() {
Assume.assumeTrue("sun.misc.Unsafe not found, skip tests", PlatformDependent.hasUnsafe());
super.init();
}
@Override

View File

@ -23,9 +23,11 @@ import org.junit.Before;
public class BigEndianUnsafeNoCleanerDirectByteBufTest extends BigEndianDirectByteBufTest {
@Before
public void checkHasUnsafe() {
@Override
public void init() {
Assume.assumeTrue("java.nio.DirectByteBuffer.<init>(long, int) not found, skip tests",
PlatformDependent.useDirectBufferNoCleaner());
super.init();
}
@Override

View File

@ -22,8 +22,10 @@ import org.junit.Before;
public class LittleEndianUnsafeDirectByteBufTest extends LittleEndianDirectByteBufTest {
@Before
public void checkHasUnsafe() {
@Override
public void init() {
Assume.assumeTrue("sun.misc.Unsafe not found, skip tests", PlatformDependent.hasUnsafe());
super.init();
}
@Override

View File

@ -22,9 +22,11 @@ import org.junit.Before;
public class LittleEndianUnsafeNoCleanerDirectByteBufTest extends LittleEndianDirectByteBufTest {
@Before
public void checkHasUnsafe() {
@Override
public void init() {
Assume.assumeTrue("java.nio.DirectByteBuffer.<init>(long, int) not found, skip tests",
PlatformDependent.useDirectBufferNoCleaner());
super.init();
}
@Override

View File

@ -16,6 +16,7 @@
package io.netty.buffer;
import io.netty.util.internal.PlatformDependent;
import org.junit.Assume;
import org.junit.BeforeClass;
import java.nio.ByteBuffer;
@ -29,7 +30,7 @@ public class ReadOnlyUnsafeDirectByteBufferBufTest extends ReadOnlyDirectByteBuf
*/
@BeforeClass
public static void assumeConditions() {
assumeTrue(PlatformDependent.hasUnsafe());
assumeTrue("sun.misc.Unsafe not found, skip tests", PlatformDependent.hasUnsafe());
}
@Override

View File

@ -15,6 +15,9 @@
*/
package io.netty.buffer;
import io.netty.util.internal.PlatformDependent;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import java.nio.ByteBuffer;
@ -25,6 +28,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class UnsafeByteBufUtilTest {
@Before
public void checkHasUnsafe() {
Assume.assumeTrue("sun.misc.Unsafe not found, skip tests", PlatformDependent.hasUnsafe());
}
@Test
public void testSetBytesOnReadOnlyByteBuffer() throws Exception {

View File

@ -16,12 +16,21 @@
package io.netty.buffer;
import io.netty.util.internal.PlatformDependent;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
public class WrappedUnpooledUnsafeByteBufTest extends BigEndianUnsafeDirectByteBufTest {
@Before
@Override
public void init() {
Assume.assumeTrue("sun.misc.Unsafe not found, skip tests", PlatformDependent.hasUnsafe());
super.init();
}
@Override
protected ByteBuf newBuffer(int length) {
return new WrappedUnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT,