Suppress OSGI printing to stderr unless a test fails. See #2339.
This commit is contained in:
parent
4d114eb2c6
commit
1e632e5a5c
3 changed files with 64 additions and 30 deletions
|
|
@ -38,17 +38,21 @@ class SimpleNamespaceHandlerTest extends WordSpec with MustMatchers with PojoSRT
|
||||||
|
|
||||||
"simple.xml" must {
|
"simple.xml" must {
|
||||||
"set up ActorSystem when bundle starts" in {
|
"set up ActorSystem when bundle starts" in {
|
||||||
serviceForType[ActorSystem] must not be (null)
|
filterErrors() {
|
||||||
|
serviceForType[ActorSystem] must not be (null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"stop the ActorSystem when bundle stops" in {
|
"stop the ActorSystem when bundle stops" in {
|
||||||
val system = serviceForType[ActorSystem]
|
filterErrors() {
|
||||||
system.isTerminated must be(false)
|
val system = serviceForType[ActorSystem]
|
||||||
|
system.isTerminated must be(false)
|
||||||
|
|
||||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||||
|
|
||||||
system.awaitTermination()
|
system.awaitTermination()
|
||||||
system.isTerminated must be(true)
|
system.isTerminated must be(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,19 +68,23 @@ class ConfigNamespaceHandlerTest extends WordSpec with MustMatchers with PojoSRT
|
||||||
|
|
||||||
"config.xml" must {
|
"config.xml" must {
|
||||||
"set up ActorSystem when bundle starts" in {
|
"set up ActorSystem when bundle starts" in {
|
||||||
val system = serviceForType[ActorSystem]
|
filterErrors() {
|
||||||
system must not be (null)
|
val system = serviceForType[ActorSystem]
|
||||||
system.settings.config.getString("some.config.key") must be("value")
|
system must not be (null)
|
||||||
|
system.settings.config.getString("some.config.key") must be("value")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"stop the ActorSystem when bundle stops" in {
|
"stop the ActorSystem when bundle stops" in {
|
||||||
val system = serviceForType[ActorSystem]
|
filterErrors() {
|
||||||
system.isTerminated must be(false)
|
val system = serviceForType[ActorSystem]
|
||||||
|
system.isTerminated must be(false)
|
||||||
|
|
||||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||||
|
|
||||||
system.awaitTermination()
|
system.awaitTermination()
|
||||||
system.isTerminated must be(true)
|
system.isTerminated must be(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,9 +101,11 @@ class DependencyInjectionNamespaceHandlerTest extends WordSpec with MustMatchers
|
||||||
"injection.xml" must {
|
"injection.xml" must {
|
||||||
|
|
||||||
"set up bean containing ActorSystem" in {
|
"set up bean containing ActorSystem" in {
|
||||||
val bean = serviceForType[ActorSystemAwareBean]
|
filterErrors() {
|
||||||
bean must not be (null)
|
val bean = serviceForType[ActorSystemAwareBean]
|
||||||
bean.system must not be (null)
|
bean must not be (null)
|
||||||
|
bean.system must not be (null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,21 +38,24 @@ class PingPongActorSystemActivatorTest extends WordSpec with MustMatchers with P
|
||||||
"PingPongActorSystemActivator" must {
|
"PingPongActorSystemActivator" must {
|
||||||
|
|
||||||
"start and register the ActorSystem when bundle starts" in {
|
"start and register the ActorSystem when bundle starts" in {
|
||||||
val system = serviceForType[ActorSystem]
|
filterErrors() {
|
||||||
val actor = system.actorFor("/user/pong")
|
val system = serviceForType[ActorSystem]
|
||||||
|
val actor = system.actorFor("/user/pong")
|
||||||
|
|
||||||
implicit val timeout = Timeout(5 seconds)
|
implicit val timeout = Timeout(5 seconds)
|
||||||
Await.result(actor ? Ping, timeout.duration) must be(Pong)
|
Await.result(actor ? Ping, timeout.duration) must be(Pong)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"stop the ActorSystem when bundle stops" in {
|
"stop the ActorSystem when bundle stops" in {
|
||||||
val system = serviceForType[ActorSystem]
|
filterErrors() {
|
||||||
system.isTerminated must be(false)
|
val system = serviceForType[ActorSystem]
|
||||||
|
system.isTerminated must be(false)
|
||||||
|
|
||||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||||
|
system.awaitTermination()
|
||||||
system.awaitTermination()
|
system.isTerminated must be(true)
|
||||||
system.isTerminated must be(true)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,7 +70,9 @@ class RuntimeNameActorSystemActivatorTest extends WordSpec with MustMatchers wit
|
||||||
"RuntimeNameActorSystemActivator" must {
|
"RuntimeNameActorSystemActivator" must {
|
||||||
|
|
||||||
"register an ActorSystem and add the bundle id to the system name" in {
|
"register an ActorSystem and add the bundle id to the system name" in {
|
||||||
serviceForType[ActorSystem].name must equal(TestActivators.ACTOR_SYSTEM_NAME_PATTERN.format(bundleForName(TEST_BUNDLE_NAME).getBundleId))
|
filterErrors() {
|
||||||
|
serviceForType[ActorSystem].name must equal(TestActivators.ACTOR_SYSTEM_NAME_PATTERN.format(bundleForName(TEST_BUNDLE_NAME).getBundleId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,11 @@ import org.osgi.framework._
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
import java.io.{ FileInputStream, FileOutputStream, File }
|
import java.io._
|
||||||
import org.scalatest.{ BeforeAndAfterAll, Suite }
|
import org.scalatest.{ BeforeAndAfterAll, Suite }
|
||||||
import java.util.{ UUID, Date, ServiceLoader, HashMap }
|
import java.util.{ UUID, Date, ServiceLoader, HashMap }
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
|
import scala.Some
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait that provides support for building akka-osgi tests using PojoSR
|
* Trait that provides support for building akka-osgi tests using PojoSR
|
||||||
|
|
@ -32,6 +33,8 @@ trait PojoSRTestSupport extends Suite with BeforeAndAfterAll {
|
||||||
*/
|
*/
|
||||||
def testBundles: Seq[BundleDescriptor]
|
def testBundles: Seq[BundleDescriptor]
|
||||||
|
|
||||||
|
val bufferedLoadingErrors = new ByteArrayOutputStream()
|
||||||
|
|
||||||
lazy val context: BundleContext = {
|
lazy val context: BundleContext = {
|
||||||
val config = new HashMap[String, AnyRef]()
|
val config = new HashMap[String, AnyRef]()
|
||||||
System.setProperty("org.osgi.framework.storage", "target/akka-osgi/" + UUID.randomUUID().toString)
|
System.setProperty("org.osgi.framework.storage", "target/akka-osgi/" + UUID.randomUUID().toString)
|
||||||
|
|
@ -40,7 +43,15 @@ trait PojoSRTestSupport extends Suite with BeforeAndAfterAll {
|
||||||
bundles.addAll(testBundles)
|
bundles.addAll(testBundles)
|
||||||
config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles)
|
config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles)
|
||||||
|
|
||||||
ServiceLoader.load(classOf[PojoServiceRegistryFactory]).iterator.next.newPojoServiceRegistry(config).getBundleContext
|
val oldErr = System.err
|
||||||
|
System.setErr(new PrintStream(bufferedLoadingErrors))
|
||||||
|
try {
|
||||||
|
ServiceLoader.load(classOf[PojoServiceRegistryFactory]).iterator.next.newPojoServiceRegistry(config).getBundleContext
|
||||||
|
} catch {
|
||||||
|
case e: Throwable ⇒ oldErr.write(bufferedLoadingErrors.toByteArray); throw e
|
||||||
|
} finally {
|
||||||
|
System.setErr(oldErr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure bundles get stopped at the end of the test to release resources and stop threads
|
// Ensure bundles get stopped at the end of the test to release resources and stop threads
|
||||||
|
|
@ -72,6 +83,14 @@ trait PojoSRTestSupport extends Suite with BeforeAndAfterAll {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def buildTestBundles(builders: Seq[BundleDescriptorBuilder]): Seq[BundleDescriptor] = builders map (_.build)
|
protected def buildTestBundles(builders: Seq[BundleDescriptorBuilder]): Seq[BundleDescriptor] = builders map (_.build)
|
||||||
|
|
||||||
|
def filterErrors()(block: ⇒ Unit): Unit = {
|
||||||
|
try {
|
||||||
|
block
|
||||||
|
} catch {
|
||||||
|
case e: Throwable ⇒ System.err.write(bufferedLoadingErrors.toByteArray); throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object PojoSRTestSupport {
|
object PojoSRTestSupport {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue