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 {
|
||||
"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 {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system.isTerminated must be(false)
|
||||
filterErrors() {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system.isTerminated must be(false)
|
||||
|
||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||
|
||||
system.awaitTermination()
|
||||
system.isTerminated must be(true)
|
||||
system.awaitTermination()
|
||||
system.isTerminated must be(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,19 +68,23 @@ class ConfigNamespaceHandlerTest extends WordSpec with MustMatchers with PojoSRT
|
|||
|
||||
"config.xml" must {
|
||||
"set up ActorSystem when bundle starts" in {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system must not be (null)
|
||||
system.settings.config.getString("some.config.key") must be("value")
|
||||
filterErrors() {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system must not be (null)
|
||||
system.settings.config.getString("some.config.key") must be("value")
|
||||
}
|
||||
}
|
||||
|
||||
"stop the ActorSystem when bundle stops" in {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system.isTerminated must be(false)
|
||||
filterErrors() {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system.isTerminated must be(false)
|
||||
|
||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||
|
||||
system.awaitTermination()
|
||||
system.isTerminated must be(true)
|
||||
system.awaitTermination()
|
||||
system.isTerminated must be(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,9 +101,11 @@ class DependencyInjectionNamespaceHandlerTest extends WordSpec with MustMatchers
|
|||
"injection.xml" must {
|
||||
|
||||
"set up bean containing ActorSystem" in {
|
||||
val bean = serviceForType[ActorSystemAwareBean]
|
||||
bean must not be (null)
|
||||
bean.system must not be (null)
|
||||
filterErrors() {
|
||||
val bean = serviceForType[ActorSystemAwareBean]
|
||||
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 {
|
||||
|
||||
"start and register the ActorSystem when bundle starts" in {
|
||||
val system = serviceForType[ActorSystem]
|
||||
val actor = system.actorFor("/user/pong")
|
||||
filterErrors() {
|
||||
val system = serviceForType[ActorSystem]
|
||||
val actor = system.actorFor("/user/pong")
|
||||
|
||||
implicit val timeout = Timeout(5 seconds)
|
||||
Await.result(actor ? Ping, timeout.duration) must be(Pong)
|
||||
implicit val timeout = Timeout(5 seconds)
|
||||
Await.result(actor ? Ping, timeout.duration) must be(Pong)
|
||||
}
|
||||
}
|
||||
|
||||
"stop the ActorSystem when bundle stops" in {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system.isTerminated must be(false)
|
||||
filterErrors() {
|
||||
val system = serviceForType[ActorSystem]
|
||||
system.isTerminated must be(false)
|
||||
|
||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||
|
||||
system.awaitTermination()
|
||||
system.isTerminated must be(true)
|
||||
bundleForName(TEST_BUNDLE_NAME).stop()
|
||||
system.awaitTermination()
|
||||
system.isTerminated must be(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +70,9 @@ class RuntimeNameActorSystemActivatorTest extends WordSpec with MustMatchers wit
|
|||
"RuntimeNameActorSystemActivator" must {
|
||||
|
||||
"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.util.jar.JarInputStream
|
||||
import java.io.{ FileInputStream, FileOutputStream, File }
|
||||
import java.io._
|
||||
import org.scalatest.{ BeforeAndAfterAll, Suite }
|
||||
import java.util.{ UUID, Date, ServiceLoader, HashMap }
|
||||
import scala.reflect.ClassTag
|
||||
import scala.Some
|
||||
|
||||
/**
|
||||
* 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]
|
||||
|
||||
val bufferedLoadingErrors = new ByteArrayOutputStream()
|
||||
|
||||
lazy val context: BundleContext = {
|
||||
val config = new HashMap[String, AnyRef]()
|
||||
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)
|
||||
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
|
||||
|
|
@ -72,6 +83,14 @@ trait PojoSRTestSupport extends Suite with BeforeAndAfterAll {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue