File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed
akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,6 @@ import akka.event._
44import akka .http .scaladsl .server .RoutingSpec
55import akka .testkit .EventFilter
66
7- import scala .collection .mutable .ListBuffer
8-
97class MdcLoggingDirectivesSpec extends RoutingSpec {
108
119 " The `withMarkerLoggingAdapter` directive" should {
@@ -55,13 +53,17 @@ class MdcLoggingDirectivesSpec extends RoutingSpec {
5553 }
5654 }
5755 " include the entries in the LoggingEvents" in {
58- val buf = ListBuffer .empty[Logging .Info2 ]
59- val filter = EventFilter .custom {
60- case e : Logging .Info2 =>
61- buf.append(e)
62- true
63- case _ => false
56+ class EF (n : Int ) extends EventFilter (n) {
57+ @ volatile
58+ var buf = Vector .empty[Logging .Info2 ]
59+ override protected def matches (event : Logging .LogEvent ): Boolean = event match {
60+ case e : Logging .Info2 =>
61+ buf :+= e
62+ true
63+ case _ => false
64+ }
6465 }
66+ val filter = new EF (3 )
6567 filter.intercept {
6668 Get () ~> withMdcEntries(" user_id" -> " 1234" , " request_id" -> " abcd" ) {
6769 extractLog { log1 =>
@@ -76,10 +78,10 @@ class MdcLoggingDirectivesSpec extends RoutingSpec {
7678 }
7779 } ~> check {
7880 response shouldEqual Ok
79- buf.size shouldBe 3
80- val l1 = buf(0 )
81- val l2 = buf(1 )
82- val l3 = buf(2 )
81+ filter. buf.size shouldBe 3
82+ val l1 = filter. buf(0 )
83+ val l2 = filter. buf(1 )
84+ val l3 = filter. buf(2 )
8385 l1.message shouldBe " test 1"
8486 l1.mdc shouldBe Map (" user_id" -> " 1234" , " request_id" -> " abcd" )
8587 l2.message shouldBe " test 2"
You can’t perform that action at this time.
0 commit comments