From babf3b17bbee86137661ffbce576166354828e71 Mon Sep 17 00:00:00 2001 From: "He-Pin(kerr)" Date: Sat, 25 Jan 2025 23:33:38 +0800 Subject: [PATCH] chore: Add the missing EmptySource case to TraversalBuilder (#1743) (#1747) (cherry picked from commit ba639f68a2eebb521e01879f584d2f682a7934eb) --- .../stream/impl/TraversalBuilderSpec.scala | 18 +++++++++++++++++- .../pekko/stream/impl/TraversalBuilder.scala | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/stream-tests/src/test/scala/org/apache/pekko/stream/impl/TraversalBuilderSpec.scala b/stream-tests/src/test/scala/org/apache/pekko/stream/impl/TraversalBuilderSpec.scala index 484ac0ed477..063b9ec335c 100644 --- a/stream-tests/src/test/scala/org/apache/pekko/stream/impl/TraversalBuilderSpec.scala +++ b/stream-tests/src/test/scala/org/apache/pekko/stream/impl/TraversalBuilderSpec.scala @@ -17,7 +17,7 @@ import org.apache.pekko import pekko.NotUsed import pekko.stream._ import pekko.stream.impl.TraversalTestUtils._ -import pekko.stream.scaladsl.Keep +import pekko.stream.scaladsl.{ Keep, Source } import pekko.testkit.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) + } + } diff --git a/stream/src/main/scala/org/apache/pekko/stream/impl/TraversalBuilder.scala b/stream/src/main/scala/org/apache/pekko/stream/impl/TraversalBuilder.scala index 7ff61a2b3a8..22c006601bb 100644 --- a/stream/src/main/scala/org/apache/pekko/stream/impl/TraversalBuilder.scala +++ b/stream/src/main/scala/org/apache/pekko/stream/impl/TraversalBuilder.scala @@ -386,6 +386,7 @@ import pekko.util.unused def isEmptySource(graph: Graph[SourceShape[_], _]): Boolean = graph match { case source: scaladsl.Source[_, _] if source eq scaladsl.Source.empty => true case source: javadsl.Source[_, _] if source eq javadsl.Source.empty() => true + case EmptySource => true case _ => false }