chore: Add the missing EmptySource case to TraversalBuilder (#1743)

This commit is contained in:
He-Pin(kerr) 2025-01-25 06:42:25 +08:00 committed by GitHub
parent 864777ef62
commit ba639f68a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -17,7 +17,7 @@ import org.apache.pekko
import pekko.NotUsed import pekko.NotUsed
import pekko.stream._ import pekko.stream._
import pekko.stream.impl.TraversalTestUtils._ import pekko.stream.impl.TraversalTestUtils._
import pekko.stream.scaladsl.Keep import pekko.stream.scaladsl.{ Keep, Source }
import pekko.testkit.PekkoSpec import pekko.testkit.PekkoSpec
class TraversalBuilderSpec extends PekkoSpec { class TraversalBuilderSpec extends PekkoSpec {
@ -447,4 +447,20 @@ class TraversalBuilderSpec extends PekkoSpec {
} }
} }
"find Source.empty via TraversalBuilder with isEmptySource" in {
val emptySource = EmptySource
TraversalBuilder.isEmptySource(emptySource) should be(true)
}
"find javadsl Source.empty via TraversalBuilder with isEmptySource" in {
import pekko.stream.javadsl.Source
val emptySource = Source.empty()
TraversalBuilder.isEmptySource(emptySource) should be(true)
}
"find scaldsl Source.empty via TraversalBuilder with isEmptySource" in {
val emptySource = Source.empty
TraversalBuilder.isEmptySource(emptySource) should be(true)
}
} }

View file

@ -386,6 +386,7 @@ import pekko.util.unused
def isEmptySource(graph: Graph[SourceShape[_], _]): Boolean = graph match { def isEmptySource(graph: Graph[SourceShape[_], _]): Boolean = graph match {
case source: scaladsl.Source[_, _] if source eq scaladsl.Source.empty => true case source: scaladsl.Source[_, _] if source eq scaladsl.Source.empty => true
case source: javadsl.Source[_, _] if source eq javadsl.Source.empty() => true case source: javadsl.Source[_, _] if source eq javadsl.Source.empty() => true
case EmptySource => true
case _ => false case _ => false
} }