Skip to content

Commit

Permalink
Change tests to use new Source.queue api, #29801 (#30070)
Browse files Browse the repository at this point in the history
  • Loading branch information
azotcsit committed May 27, 2021
1 parent 48e4f11 commit 3ae85e8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SendQueueBenchmark {
val N = 100000
val burstSize = 1000

val source = Source.queue[Int](1024, OverflowStrategy.dropBuffer)
val source = Source.queue[Int](1024)

val (queue, killSwitch) = source
.viaMat(KillSwitches.single)(Keep.both)
Expand Down
4 changes: 2 additions & 2 deletions akka-docs/src/test/java/jdocs/stream/IntegrationDocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ public void illustrateSourceQueue() throws Exception {
int bufferSize = 10;
int elementsToProcess = 5;

SourceQueueWithComplete<Integer> sourceQueue =
Source.<Integer>queue(bufferSize, OverflowStrategy.backpressure())
BoundedSourceQueue<Integer> sourceQueue =
Source.<Integer>queue(bufferSize)
.throttle(elementsToProcess, Duration.ofSeconds(3))
.map(x -> x * x)
.to(Sink.foreach(x -> System.out.println("got: " + x)))
Expand Down
5 changes: 3 additions & 2 deletions akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import scala.concurrent.ExecutionContext
import java.util.concurrent.atomic.AtomicInteger

import akka.stream.scaladsl.Flow
import org.scalacheck.Gen.const

object IntegrationDocSpec {
import TwitterStreamQuickstartDocSpec._
Expand Down Expand Up @@ -469,7 +470,7 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
val elementsToProcess = 5

val queue = Source
.queue[Int](bufferSize, OverflowStrategy.backpressure)
.queue[Int](bufferSize)
.throttle(elementsToProcess, 3.second)
.map(x => x * x)
.toMat(Sink.foreach(x => println(s"completed $x")))(Keep.left)
Expand All @@ -479,7 +480,7 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {

implicit val ec = system.dispatcher
source
.mapAsync(1)(x => {
.map(x => {
queue.offer(x).map {
case QueueOfferResult.Enqueued => println(s"enqueued $x")
case QueueOfferResult.Dropped => println(s"dropped $x")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,9 @@ public void mustRepeatForDocs() throws Exception {

@Test
public void mustBeAbleToUseQueue() throws Exception {
final Pair<SourceQueueWithComplete<String>, CompletionStage<List<String>>> x =
Flow.of(String.class).runWith(Source.queue(2, OverflowStrategy.fail()), Sink.seq(), system);
final SourceQueueWithComplete<String> source = x.first();
final Pair<BoundedSourceQueue<String>, CompletionStage<List<String>>> x =
Flow.of(String.class).runWith(Source.queue(2), Sink.seq(), system);
final BoundedSourceQueue<String> source = x.first();
final CompletionStage<List<String>> result = x.second();
source.offer("hello");
source.offer("world");
Expand Down Expand Up @@ -833,20 +833,19 @@ public void mustBeAbleToCombine() throws Exception {
@Test
public void mustBeAbleToCombineMat() throws Exception {
final TestKit probe = new TestKit(system);
final Source<Integer, SourceQueueWithComplete<Integer>> source1 =
Source.queue(1, OverflowStrategy.dropNew());
final Source<Integer, BoundedSourceQueue<Integer>> source1 = Source.queue(2);
final Source<Integer, NotUsed> source2 = Source.from(Arrays.asList(2, 3));

// compiler to check the correct materialized value of type = SourceQueueWithComplete<Integer>
// compiler to check the correct materialized value of type = BoundedSourceQueue<Integer>
// available
final Source<Integer, SourceQueueWithComplete<Integer>> combined =
final Source<Integer, BoundedSourceQueue<Integer>> combined =
Source.combineMat(
source1,
source2,
width -> Concat.create(width),
Keep.left()); // Keep.left() (i.e. preserve queueSource's materialized value)

SourceQueueWithComplete<Integer> queue =
BoundedSourceQueue<Integer> queue =
combined
.toMat(
Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), Keep.left())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ class FlowGroupBySpec extends StreamSpec("""
"not block all substreams when one is blocked but has a buffer in front" in assertAllStagesStopped {
case class Elem(id: Int, substream: Int, f: () => Any)
val queue = Source
.queue[Elem](3, OverflowStrategy.backpressure)
.queue[Elem](3)
.groupBy(2, _.substream)
.buffer(2, OverflowStrategy.backpressure)
.map { _.f() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ class SourceSpec extends StreamSpec with DefaultTimeout {
}

"combine from two inputs with combinedMat and take a materialized value" in {
val queueSource = Source.queue[Int](1, OverflowStrategy.dropBuffer)
val queueSource = Source.queue[Int](3)
val intSeqSource = Source(1 to 3)

// compiler to check the correct materialized value of type = SourceQueueWithComplete[Int] available
val combined1: Source[Int, SourceQueueWithComplete[Int]] =
val combined1: Source[Int, BoundedSourceQueue[Int]] =
Source.combineMat(queueSource, intSeqSource)(Concat(_))(Keep.left) //Keep.left (i.e. preserve queueSource's materialized value)

val (queue1, sinkProbe1) = combined1.toMat(TestSink.probe[Int])(Keep.both).run()
Expand All @@ -192,7 +192,7 @@ class SourceSpec extends StreamSpec with DefaultTimeout {
sinkProbe1.expectNext(3)

// compiler to check the correct materialized value of type = SourceQueueWithComplete[Int] available
val combined2: Source[Int, SourceQueueWithComplete[Int]] =
val combined2: Source[Int, BoundedSourceQueue[Int]] =
//queueSource to be the second of combined source
Source.combineMat(intSeqSource, queueSource)(Concat(_))(Keep.right) //Keep.right (i.e. preserve queueSource's materialized value)

Expand Down Expand Up @@ -390,33 +390,33 @@ class SourceSpec extends StreamSpec with DefaultTimeout {
}

"allow for multiple downstream materialized sources" in {
val matValPoweredSource = Source.queue[String](Int.MaxValue, OverflowStrategy.fail)
val matValPoweredSource = Source.queue[String](Int.MaxValue)
val (mat, src) = matValPoweredSource.preMaterialize()

val probe1 = src.runWith(TestSink.probe[String])
val probe2 = src.runWith(TestSink.probe[String])

probe1.request(1)
probe2.request(1)
mat.offer("One").futureValue
mat.offer("One")
probe1.expectNext("One")
probe2.expectNext("One")
}

"survive cancellations of downstream materialized sources" in {
val matValPoweredSource = Source.queue[String](Int.MaxValue, OverflowStrategy.fail)
val matValPoweredSource = Source.queue[String](Int.MaxValue)
val (mat, src) = matValPoweredSource.preMaterialize()

val probe1 = src.runWith(TestSink.probe[String])
src.runWith(Sink.cancelled)

probe1.request(1)
mat.offer("One").futureValue
mat.offer("One")
probe1.expectNext("One")
}

"propagate failures to downstream materialized sources" in {
val matValPoweredSource = Source.queue[String](Int.MaxValue, OverflowStrategy.fail)
val matValPoweredSource = Source.queue[String](Int.MaxValue)
val (mat, src) = matValPoweredSource.preMaterialize()

val probe1 = src.runWith(TestSink.probe[String])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class Failure implements Protocol {
{
final ActorRef<String> ref = null;

Source.<String>queue(10, OverflowStrategy.dropBuffer())
Source.<String>queue(10)
.map(s -> s + "!")
.to(ActorSink.actorRef(ref, "DONE", ex -> "FAILED: " + ex.getMessage()));
}

{
final ActorRef<Protocol> ref = null;

Source.<String>queue(10, OverflowStrategy.dropBuffer())
Source.<String>queue(10)
.to(
ActorSink.actorRefWithBackpressure(
ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ActorSourceSinkSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike

val in =
Source
.queue[String](10, OverflowStrategy.dropBuffer)
.queue[String](10)
.map(_ + "!")
.to(ActorSink.actorRef(p.ref, "DONE", ex => "FAILED: " + ex.getMessage))
.run()
Expand Down Expand Up @@ -65,7 +65,7 @@ class ActorSourceSinkSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike

val in =
Source
.queue[String](10, OverflowStrategy.dropBuffer)
.queue[String](10)
.to(ActorSink.actorRefWithBackpressure(pilotRef, Msg.apply, Init.apply, "ACK", Complete, _ => Failed))
.run()

Expand Down Expand Up @@ -102,7 +102,7 @@ class ActorSourceSinkSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike

val in =
Source
.queue[String](10, OverflowStrategy.dropBuffer)
.queue[String](10)
.to(ActorSink.actorRefWithBackpressure(pilotRef, Msg.apply, Init.apply, Complete, _ => Failed))
.run()

Expand Down

0 comments on commit 3ae85e8

Please sign in to comment.