Materializer settings as attributes (#27499)
* Replace MaterializerSettings with Attributes #25559 * Field access to settings deprecated to make stages use attributes instead * Internal stages updated to use attributes * Docs on ActorMaterializerSettings updated to recommend away from using it * Verify all stages stopped after each testcase in FlowGroupBySpec * Subscription timeout attributes merged into one
This commit is contained in:
parent
b9a879d722
commit
aca63ea198
132 changed files with 1596 additions and 1116 deletions
|
|
@ -5,12 +5,9 @@
|
|||
package docs.stream
|
||||
|
||||
import scala.concurrent.Await
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream.ActorMaterializerSettings
|
||||
import akka.stream.Supervision
|
||||
import akka.stream.scaladsl._
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.stream.Attributes
|
||||
import akka.stream.ActorAttributes
|
||||
import scala.concurrent.duration._
|
||||
|
||||
|
|
@ -35,9 +32,13 @@ class FlowErrorDocSpec extends AkkaSpec {
|
|||
case _: ArithmeticException => Supervision.Resume
|
||||
case _ => Supervision.Stop
|
||||
}
|
||||
implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withSupervisionStrategy(decider))
|
||||
val source = Source(0 to 5).map(100 / _)
|
||||
val result = source.runWith(Sink.fold(0)(_ + _))
|
||||
val runnableGraph =
|
||||
source.toMat(Sink.fold(0)(_ + _))(Keep.right)
|
||||
|
||||
val withCustomSupervision = runnableGraph.withAttributes(ActorAttributes.supervisionStrategy(decider))
|
||||
|
||||
val result = withCustomSupervision.run()
|
||||
// the element causing division by zero will be dropped
|
||||
// result here will be a Future completed with Success(228)
|
||||
//#resume
|
||||
|
|
|
|||
|
|
@ -409,13 +409,12 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
|
|||
implicit val blockingExecutionContext = system.dispatchers.lookup("blocking-dispatcher")
|
||||
val service = new SometimesSlowService
|
||||
|
||||
implicit val materializer =
|
||||
ActorMaterializer(ActorMaterializerSettings(system).withInputBuffer(initialSize = 4, maxSize = 4))
|
||||
|
||||
Source(List("a", "B", "C", "D", "e", "F", "g", "H", "i", "J"))
|
||||
.map(elem => { println(s"before: $elem"); elem })
|
||||
.mapAsync(4)(service.convert)
|
||||
.runForeach(elem => println(s"after: $elem"))
|
||||
.to(Sink.foreach(elem => println(s"after: $elem")))
|
||||
.withAttributes(Attributes.inputBuffer(initial = 4, max = 4))
|
||||
.run()
|
||||
//#sometimes-slow-mapAsync
|
||||
|
||||
probe.expectMsg("after: A")
|
||||
|
|
@ -441,13 +440,12 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
|
|||
implicit val blockingExecutionContext = system.dispatchers.lookup("blocking-dispatcher")
|
||||
val service = new SometimesSlowService
|
||||
|
||||
implicit val materializer =
|
||||
ActorMaterializer(ActorMaterializerSettings(system).withInputBuffer(initialSize = 4, maxSize = 4))
|
||||
|
||||
Source(List("a", "B", "C", "D", "e", "F", "g", "H", "i", "J"))
|
||||
.map(elem => { println(s"before: $elem"); elem })
|
||||
.mapAsyncUnordered(4)(service.convert)
|
||||
.runForeach(elem => println(s"after: $elem"))
|
||||
.to(Sink.foreach(elem => println(s"after: $elem")))
|
||||
.withAttributes(Attributes.inputBuffer(initial = 4, max = 4))
|
||||
.run()
|
||||
//#sometimes-slow-mapAsyncUnordered
|
||||
|
||||
probe.receiveN(10).toSet should be(
|
||||
|
|
|
|||
|
|
@ -32,14 +32,13 @@ class StreamBuffersRateSpec extends AkkaSpec {
|
|||
}
|
||||
|
||||
"Demonstrate buffer sizes" in {
|
||||
//#materializer-buffer
|
||||
val materializer =
|
||||
ActorMaterializer(ActorMaterializerSettings(system).withInputBuffer(initialSize = 64, maxSize = 64))
|
||||
//#materializer-buffer
|
||||
|
||||
//#section-buffer
|
||||
val section = Flow[Int].map(_ * 2).async.addAttributes(Attributes.inputBuffer(initial = 1, max = 1)) // the buffer size of this map is 1
|
||||
val flow = section.via(Flow[Int].map(_ / 2)).async // the buffer size of this map is the default
|
||||
val runnableGraph =
|
||||
Source(1 to 10).via(flow).to(Sink.foreach(elem => println(elem)))
|
||||
|
||||
val withOverriddenDefaults = runnableGraph.withAttributes(Attributes.inputBuffer(initial = 64, max = 64))
|
||||
//#section-buffer
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,7 @@
|
|||
|
||||
package docs.stream.cookbook
|
||||
|
||||
import akka.stream.{ ActorMaterializer, ActorMaterializerSettings }
|
||||
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.Await
|
||||
|
||||
class RecipeCollectingMetrics extends RecipeSpec {
|
||||
implicit val m2 = ActorMaterializer(ActorMaterializerSettings(system).withInputBuffer(1, 1))
|
||||
|
||||
"Recipe for periodically collecting metrics" must {
|
||||
|
||||
|
|
@ -39,7 +33,7 @@ class RecipeCollectingMetrics extends RecipeSpec {
|
|||
// }
|
||||
// //#periodic-metrics-collection
|
||||
//
|
||||
// val reports = graph.run().get(futureSink)
|
||||
// val reports = graph.withAttributes(Attributes.inputBuffer(1, 1).run().get(futureSink)
|
||||
// val manualLoad = new StreamTestKit.AutoPublisher(loadPub)
|
||||
// val manualTick = new StreamTestKit.AutoPublisher(tickPub)
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue