Provide a test for #6548 using the OSGi test suite

Motiviation:

The OSGi Test suite runs without access to sun.misc.Unsafe, and so is a good place to put a test to avoid regressing #6548.

Modification:

Added a test-case that failed before https://github.com/netty/netty/pull/7432.

Result:

Test for fix included.
This commit is contained in:
Tim Ward 2017-11-27 14:20:17 +00:00 committed by Norman Maurer
parent 65cacc9b15
commit 460d125121

View File

@ -17,17 +17,19 @@
package io.netty.osgitests; package io.netty.osgitests;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
import static org.ops4j.pax.exam.CoreOptions.junitBundles; import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty; import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle; import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import static org.osgi.framework.Constants.FRAMEWORK_BOOTDELEGATION;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -38,6 +40,7 @@ import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.junit.PaxExam;
import io.netty.util.internal.PlatformDependent;
@RunWith(PaxExam.class) @RunWith(PaxExam.class)
public class OsgiBundleTest { public class OsgiBundleTest {
@ -86,6 +89,8 @@ public class OsgiBundleTest {
public final Option[] config() { public final Option[] config() {
final Collection<Option> options = new ArrayList<Option>(); final Collection<Option> options = new ArrayList<Option>();
// Avoid boot delegating sun.misc which would fail testCanLoadPlatformDependent()
options.add(frameworkProperty(FRAMEWORK_BOOTDELEGATION).value("com.sun.*"));
options.add(systemProperty("pax.exam.osgi.unresolved.fail").value("true")); options.add(systemProperty("pax.exam.osgi.unresolved.fail").value("true"));
options.addAll(Arrays.asList(junitBundles())); options.addAll(Arrays.asList(junitBundles()));
@ -104,4 +109,9 @@ public class OsgiBundleTest {
// No-op, as we just want the bundles to be resolved. Just check if we tested something // No-op, as we just want the bundles to be resolved. Just check if we tested something
assertFalse("At least one bundle needs to be tested", BUNDLES.isEmpty()); assertFalse("At least one bundle needs to be tested", BUNDLES.isEmpty());
} }
@Test
public void testCanLoadPlatformDependent() {
assertFalse(PlatformDependent.hasUnsafe());
}
} }