diff --git a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/ActorSystemStub.scala b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/ActorSystemStub.scala index 680aff5890..8ba66d30dd 100644 --- a/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/ActorSystemStub.scala +++ b/akka-actor-testkit-typed/src/main/scala/akka/actor/testkit/typed/internal/ActorSystemStub.scala @@ -55,6 +55,11 @@ import com.github.ghik.silencer.silent // impl InternalRecipientRef, ask not supported override def provider: ActorRefProvider = throw new UnsupportedOperationException("no provider") + + // stream materialization etc. using stub not supported + override private[akka] def classicSystem = + throw new UnsupportedOperationException("no untyped actor system available") + // impl InternalRecipientRef def isTerminated: Boolean = whenTerminated.isCompleted diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/ActorSystem.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/ActorSystem.scala index 2255a5f6a2..686a8cb36a 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/ActorSystem.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/ActorSystem.scala @@ -6,6 +6,7 @@ package akka.actor.typed import java.util.concurrent.{ CompletionStage, ThreadFactory } +import akka.actor.ClassicActorSystemProvider import akka.actor.BootstrapSetup import akka.actor.setup.ActorSystemSetup import akka.actor.typed.eventstream.EventStream @@ -17,6 +18,7 @@ import akka.util.Helpers.Requiring import akka.util.Timeout import akka.{ Done, actor => untyped } import com.typesafe.config.{ Config, ConfigFactory } + import scala.concurrent.{ ExecutionContextExecutor, Future } /** @@ -29,7 +31,8 @@ import scala.concurrent.{ ExecutionContextExecutor, Future } * Not for user extension. */ @DoNotInherit -abstract class ActorSystem[-T] extends ActorRef[T] with Extensions { this: InternalRecipientRef[T] => +abstract class ActorSystem[-T] extends ActorRef[T] with Extensions with ClassicActorSystemProvider { + this: InternalRecipientRef[T] => /** * The name of this actor system, used to distinguish multiple ones within diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorSystemAdapter.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorSystemAdapter.scala index 9fe4db8808..9f4fd9e59f 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorSystemAdapter.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/adapter/ActorSystemAdapter.scala @@ -55,6 +55,8 @@ import akka.{ actor => untyped } import ActorRefAdapter.sendSystemMessage + override private[akka] def classicSystem: untyped.ActorSystem = untypedSystem + // Members declared in akka.actor.typed.ActorRef override def tell(msg: T): Unit = { if (msg == null) throw InvalidMessageException("[null] is not an allowed message") diff --git a/akka-actor/src/main/mima-filters/2.5.x.backwards.excludes b/akka-actor/src/main/mima-filters/2.5.x.backwards.excludes index 39e4889e20..2f431524a2 100644 --- a/akka-actor/src/main/mima-filters/2.5.x.backwards.excludes +++ b/akka-actor/src/main/mima-filters/2.5.x.backwards.excludes @@ -81,4 +81,8 @@ ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.pattern.CircuitBreaker ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.pattern.CircuitBreaker.onHalfOpen") # streamref serialization #27304 -ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.actor.DynamicAccess.classIsOnClasspath") \ No newline at end of file +ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.actor.DynamicAccess.classIsOnClasspath") + +# system wide materializer #25559 +ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("akka.actor.ExtendedActorSystem.classicSystem") +ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("akka.actor.ActorSystem.classicSystem") \ No newline at end of file diff --git a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala index be3db443d3..573c06cc33 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorSystem.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorSystem.scala @@ -13,12 +13,14 @@ import akka.actor.dungeon.ChildrenContainer import akka.actor.setup.{ ActorSystemSetup, Setup } import akka.annotation.InternalApi import akka.ConfigurationException +import akka.annotation.DoNotInherit import akka.dispatch._ import akka.event._ import akka.japi.Util.immutableSeq import akka.util.Helpers.toRootLowerCase import akka.util._ import com.typesafe.config.{ Config, ConfigFactory } + import scala.annotation.tailrec import scala.collection.immutable import scala.compat.java8.FutureConverters @@ -470,7 +472,7 @@ object ActorSystem { * extending [[akka.actor.ExtendedActorSystem]] instead, but beware that you * are completely on your own in that case! */ -abstract class ActorSystem extends ActorRefFactory { +abstract class ActorSystem extends ActorRefFactory with ClassicActorSystemProvider { import ActorSystem._ /** @@ -674,6 +676,7 @@ abstract class ActorSystem extends ActorRefFactory { * actually roll your own Akka, beware that you are completely on your own in * that case! */ +@DoNotInherit abstract class ExtendedActorSystem extends ActorSystem { /** @@ -916,6 +919,8 @@ private[akka] class ActorSystemImpl( def /(actorName: String): ActorPath = guardian.path / actorName def /(path: Iterable[String]): ActorPath = guardian.path / path + override private[akka] def classicSystem: ActorSystem = this + // Used for ManifestInfo.checkSameVersion private def allModules: List[String] = List( diff --git a/akka-actor/src/main/scala/akka/actor/ClassicActorSystemProvider.scala b/akka-actor/src/main/scala/akka/actor/ClassicActorSystemProvider.scala new file mode 100644 index 0000000000..0c4dfaea13 --- /dev/null +++ b/akka-actor/src/main/scala/akka/actor/ClassicActorSystemProvider.scala @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2009-2019 Lightbend Inc. + */ + +package akka.actor + +import akka.annotation.DoNotInherit +import akka.annotation.InternalApi + +/** + * Glue API introduced to allow minimal user effort integration between classic and typed for example for streams. + * + * Not for user extension. + */ +@DoNotInherit +trait ClassicActorSystemProvider { + + /** INTERNAL API */ + @InternalApi + private[akka] def classicSystem: ActorSystem +} diff --git a/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md b/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md index 173bba81c1..9c6ae02a4b 100644 --- a/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md +++ b/akka-docs/src/main/paradox/project/migration-guide-2.5.x-2.6.x.md @@ -502,3 +502,16 @@ made before finalizing the APIs. Compared to Akka 2.5.x the source incompatible * `ActorSource.actorRef` relying on `PartialFunction` has been replaced in the Java API with a variant more suitable to be called by Java. + +## Additional changes + +### System global Materializer provided + +A default materializer is now provided out of the box. For the Java API just pass `system` when running streams, +for Scala an implicit materializer is provided if there is an implicit `ActorSystem` available. This avoids leaking +materializers and simplifies most stream use cases somewhat. + +Having a default materializer available means that most, if not all, usages of Java `ActorMaterializer.create()` +and Scala `implicit val materializer = ActorMaterializer()` should be removed. + +Details about the stream materializer can be found in [Actor Materializer Lifecycle](../stream/stream-flows-and-basics.md#actor-materializer-lifecycle) diff --git a/akka-docs/src/main/paradox/stream/stream-flows-and-basics.md b/akka-docs/src/main/paradox/stream/stream-flows-and-basics.md index c30736c45f..122eea6218 100644 --- a/akka-docs/src/main/paradox/stream/stream-flows-and-basics.md +++ b/akka-docs/src/main/paradox/stream/stream-flows-and-basics.md @@ -266,7 +266,7 @@ and `runWith()` methods defined on `Source` and `Flow` elements as well as a sma well-known sinks, such as @scala[`runForeach(el => ...)`]@java[`runForeach(el -> ...)`] (being an alias to @scala[`runWith(Sink.foreach(el => ...))`]@java[`runWith(Sink.foreach(el -> ...))`]). -Materialization is currently performed synchronously on the materializing thread. +Materialization is performed synchronously on the materializing thread by an `ActorSystem` global `Materializer`. The actual stream processing is handled by actors started up during the streams materialization, which will be running on the thread pools they have been configured to run on - which defaults to the dispatcher set in `MaterializationSettings` while constructing the `ActorMaterializer`. @@ -376,20 +376,25 @@ merge is performed. ## Actor Materializer Lifecycle +The `Materializer` is a component that is responsible for turning the stream blueprint into a running stream +and emitting the "materialized value". An `ActorSystem` wide `Materializer` is provided by the Akka `Extension` +`SystemMaterializer` by @scala[having an implicit `ActorSystem` in scope]@java[passing the `ActorSystem` to the +various `run` methods] this way there is no need to worry about the `Materializer` unless there are special requirements. + +The use cases that may require a custom instance of `Materializer` are: + + * When wanting to change some specific default settings for a set of streams (FIXME we should phase this out) + * When all streams materialized in an actor should be tied to the Actor lifecycle and stop if the Actor stops or crashes + +Currently the `Materializer` has one concrete implementation, the `ActorMaterializer`. + An important aspect of working with streams and actors is understanding an `ActorMaterializer`'s life-cycle. The materializer is bound to the lifecycle of the `ActorRefFactory` it is created from, which in practice will -be either an `ActorSystem` or `ActorContext` (when the materializer is created within an `Actor`). +be either an `ActorSystem` or `ActorContext` (when the materializer is created within an `Actor`). -The usual way of creating an `ActorMaterializer` is to create it next to your `ActorSystem`, -which likely is in a "main" class of your application: +Tying it to the `ActorSystem` should be replaced with using the system materializer from Akka 2.6 and on. -Scala -: @@snip [FlowDocSpec.scala](/akka-docs/src/test/scala/docs/stream/FlowDocSpec.scala) { #materializer-from-system } - -Java -: @@snip [FlowDocTest.java](/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java) { #materializer-from-system } - -In this case the streams run by the materializer will run until it is shut down. When the materializer is shut down +When run by the system materializer the streams will run until the `ActorSystem` is shut down. When the materializer is shut down *before* the streams have run to completion, they will be terminated abruptly. This is a little different than the usual way to terminate streams, which is by cancelling/completing them. The stream lifecycles are bound to the materializer like this to prevent leaks, and in normal operations you should not rely on the mechanism and rather use `KillSwitch` or diff --git a/akka-docs/src/main/paradox/stream/stream-quickstart.md b/akka-docs/src/main/paradox/stream/stream-quickstart.md index cf00293df3..928ee33bb6 100644 --- a/akka-docs/src/main/paradox/stream/stream-quickstart.md +++ b/akka-docs/src/main/paradox/stream/stream-quickstart.md @@ -35,7 +35,8 @@ Scala Java : @@snip [QuickStartDocTest.java](/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java) { #other-imports } -And @scala[an object]@java[a class] to hold your code, for example: +And @scala[an object]@java[a class] to start an Akka `ActorSystem` and hold your code @scala[. Making the `ActorSystem` +implicit makes it available to the streams without manually passing it when running them]: Scala : @@snip [QuickStartDocSpec.scala](/akka-docs/src/test/scala/docs/stream/QuickStartDocSpec.scala) { #main-app } @@ -52,11 +53,12 @@ Java : @@snip [QuickStartDocTest.java](/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java) { #create-source } The `Source` type is parameterized with two types: the first one is the -type of element that this source emits and the second one may signal that -running the source produces some auxiliary value (e.g. a network source may +type of element that this source emits and the second one, the "materialized value", allows +running the source to produce some auxiliary value (e.g. a network source may provide information about the bound port or the peer’s address). Where no -auxiliary information is produced, the type `akka.NotUsed` is used—and a -simple range of integers surely falls into this category. +auxiliary information is produced, the type `akka.NotUsed` is used. A +simple range of integers falls into this category - running our stream produces +a `NotUsed`. Having created this source means that we have a description of how to emit the first 100 natural numbers, but this source is not yet active. In order to get @@ -84,24 +86,6 @@ Scala Java : @@snip [QuickStartDocTest.java](/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java) { #run-source-and-terminate } -You may wonder where the Actor gets created that runs the stream, and you are -probably also asking yourself what this `materializer` means. In order to get -this value we first need to create an Actor system: - -Scala -: @@snip [QuickStartDocSpec.scala](/akka-docs/src/test/scala/docs/stream/QuickStartDocSpec.scala) { #create-materializer } - -Java -: @@snip [QuickStartDocTest.java](/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java) { #create-materializer } - -There are other ways to create a materializer, e.g. from an -`ActorContext` when using streams from within Actors. The -`Materializer` is a factory for stream execution engines, it is the -thing that makes streams run—you don’t need to worry about any of the details -right now apart from that you need one for calling any of the `run` methods on -a `Source`. @scala[The materializer is picked up implicitly if it is omitted -from the `run` method call arguments, which we will do in the following.] - The nice thing about Akka Streams is that the `Source` is a description of what you want to run, and like an architect’s blueprint it can be reused, incorporated into a larger design. We may choose to transform the @@ -129,6 +113,8 @@ whether the stream terminated normally or exceptionally. ### Browser-embedded example +FIXME: fiddle won't work until Akka 2.6 is released and fiddle updated with that [#27510](https://github.com/akka/akka/issues/27510) + Here is another example that you can edit and run in the browser: @@ -243,14 +229,13 @@ sections of the docs, and then come back to this quickstart to see it all pieced The example application we will be looking at is a simple Twitter feed stream from which we'll want to extract certain information, like for example finding all twitter handles of users who tweet about `#akka`. -In order to prepare our environment by creating an `ActorSystem` and `ActorMaterializer`, -which will be responsible for materializing and running the streams we are about to create: +In order to prepare our environment by creating an `ActorSystem` which will be responsible for running the streams we are about to create: Scala -: @@snip [TwitterStreamQuickstartDocSpec.scala](/akka-docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala) { #materializer-setup } +: @@snip [TwitterStreamQuickstartDocSpec.scala](/akka-docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala) { #system-setup } Java -: @@snip [TwitterStreamQuickstartDocTest.java](/akka-docs/src/test/java/jdocs/stream/TwitterStreamQuickstartDocTest.java) { #materializer-setup } +: @@snip [TwitterStreamQuickstartDocTest.java](/akka-docs/src/test/java/jdocs/stream/TwitterStreamQuickstartDocTest.java) { #system-setup } The `ActorMaterializer` can optionally take `ActorMaterializerSettings` which can be used to define materialization properties, such as default buffer sizes (see also @ref:[Buffers for asynchronous operators](stream-rate.md#async-stream-buffers)), the dispatcher to diff --git a/akka-docs/src/test/java/jdocs/persistence/PersistenceQueryDocTest.java b/akka-docs/src/test/java/jdocs/persistence/PersistenceQueryDocTest.java index 6a5089edf3..70cdc7a6bc 100644 --- a/akka-docs/src/test/java/jdocs/persistence/PersistenceQueryDocTest.java +++ b/akka-docs/src/test/java/jdocs/persistence/PersistenceQueryDocTest.java @@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit; public class PersistenceQueryDocTest { final ActorSystem system = ActorSystem.create(); - final ActorMaterializer mat = ActorMaterializer.create(system); public // #advanced-journal-query-types @@ -217,8 +216,7 @@ public class PersistenceQueryDocTest { readJournal.eventsByPersistenceId("user-1337", 0, Long.MAX_VALUE); // materialize stream, consuming events - ActorMaterializer mat = ActorMaterializer.create(system); - source.runForeach(event -> System.out.println("Event: " + event), mat); + source.runForeach(event -> System.out.println("Event: " + event), system); // #basic-usage } @@ -261,7 +259,6 @@ public class PersistenceQueryDocTest { void demonstrateEventsByTag() { final ActorSystem system = ActorSystem.create(); - final ActorMaterializer mat = ActorMaterializer.create(system); final MyJavadslReadJournal readJournal = PersistenceQuery.get(system) @@ -284,7 +281,7 @@ public class PersistenceQueryDocTest { acc.add(e); return acc; }, - mat); + system); // start another query, from the known offset Source blue = readJournal.eventsByTag("blue", new Sequence(10)); @@ -293,7 +290,6 @@ public class PersistenceQueryDocTest { void demonstrateMaterializedQueryValues() { final ActorSystem system = ActorSystem.create(); - final ActorMaterializer mat = ActorMaterializer.create(system); final MyJavadslReadJournal readJournal = PersistenceQuery.get(system) @@ -326,7 +322,7 @@ public class PersistenceQueryDocTest { System.out.println("Event payload: " + event.payload); return event.payload; }) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #advanced-journal-query-usage } @@ -339,7 +335,6 @@ public class PersistenceQueryDocTest { void demonstrateWritingIntoDifferentStore() { final ActorSystem system = ActorSystem.create(); - final ActorMaterializer mat = ActorMaterializer.create(system); final MyJavadslReadJournal readJournal = PersistenceQuery.get(system) @@ -355,7 +350,7 @@ public class PersistenceQueryDocTest { .eventsByPersistenceId("user-1337", 0L, Long.MAX_VALUE) .map(envelope -> envelope.event()) .grouped(20) // batch inserts into groups of 20 - .runWith(Sink.fromSubscriber(dbBatchWriter), mat); // write batches to read-side database + .runWith(Sink.fromSubscriber(dbBatchWriter), system); // write batches to read-side database // #projection-into-different-store-rs } @@ -372,7 +367,6 @@ public class PersistenceQueryDocTest { void demonstrateWritingIntoDifferentStoreWithMapAsync() { final ActorSystem system = ActorSystem.create(); - final ActorMaterializer mat = ActorMaterializer.create(system); final MyJavadslReadJournal readJournal = PersistenceQuery.get(system) @@ -385,7 +379,7 @@ public class PersistenceQueryDocTest { readJournal .eventsByTag("bid", new Sequence(0L)) .mapAsync(1, store::save) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #projection-into-different-store-simple } @@ -415,7 +409,6 @@ public class PersistenceQueryDocTest { void demonstrateWritingIntoDifferentStoreWithResumableProjections() throws Exception { final ActorSystem system = ActorSystem.create(); - final ActorMaterializer mat = ActorMaterializer.create(system); final MyJavadslReadJournal readJournal = PersistenceQuery.get(system) @@ -442,7 +435,7 @@ public class PersistenceQueryDocTest { return f.thenApplyAsync(in -> envelope.offset(), system.dispatcher()); }) .mapAsync(1, offset -> bidProjection.saveProgress(offset)) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); } // #projection-into-different-store-actor-run diff --git a/akka-docs/src/test/java/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java b/akka-docs/src/test/java/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java index 0d035a8b88..5ae9b20808 100644 --- a/akka-docs/src/test/java/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java +++ b/akka-docs/src/test/java/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java @@ -15,7 +15,6 @@ import akka.persistence.query.EventEnvelope; import akka.persistence.query.Sequence; import akka.persistence.query.PersistenceQuery; import akka.persistence.query.journal.leveldb.javadsl.LeveldbReadJournal; -import akka.stream.ActorMaterializer; import akka.stream.javadsl.Source; public class LeveldbPersistenceQueryDocTest { @@ -24,8 +23,6 @@ public class LeveldbPersistenceQueryDocTest { public void demonstrateReadJournal() { // #get-read-journal - final ActorMaterializer mat = ActorMaterializer.create(system); - LeveldbReadJournal queries = PersistenceQuery.get(system) .getReadJournalFor(LeveldbReadJournal.class, LeveldbReadJournal.Identifier()); diff --git a/akka-docs/src/test/java/jdocs/stream/BidiFlowDocTest.java b/akka-docs/src/test/java/jdocs/stream/BidiFlowDocTest.java index e5ac52c837..9bad4d652a 100644 --- a/akka-docs/src/test/java/jdocs/stream/BidiFlowDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/BidiFlowDocTest.java @@ -32,19 +32,16 @@ import static org.junit.Assert.assertArrayEquals; public class BidiFlowDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("FlowDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } // #codec @@ -261,7 +258,7 @@ public class BidiFlowDocTest extends AbstractJavaTest { .map(id -> new Ping(id)) .via(flow) .grouped(10) - .runWith(Sink.>head(), mat); + .runWith(Sink.>head(), system); assertArrayEquals( new Message[] {new Pong(0), new Pong(1), new Pong(2)}, result.toCompletableFuture().get(1, TimeUnit.SECONDS).toArray(new Message[0])); diff --git a/akka-docs/src/test/java/jdocs/stream/CompositionDocTest.java b/akka-docs/src/test/java/jdocs/stream/CompositionDocTest.java index 09e819dd1f..11c0d33a94 100644 --- a/akka-docs/src/test/java/jdocs/stream/CompositionDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/CompositionDocTest.java @@ -27,19 +27,16 @@ import akka.util.ByteString; public class CompositionDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("CompositionDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test diff --git a/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java b/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java index 92ef653a9d..49a63de169 100644 --- a/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/FlowDocTest.java @@ -33,19 +33,16 @@ import static org.junit.Assert.assertEquals; public class FlowDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("FlowDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -54,16 +51,16 @@ public class FlowDocTest extends AbstractJavaTest { final Source source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); source.map(x -> 0); // has no effect on source, since it's immutable - source.runWith(Sink.fold(0, (agg, next) -> agg + next), mat); // 55 + source.runWith(Sink.fold(0, (agg, next) -> agg + next), system); // 55 // returns new Source, with `map()` appended final Source zeroes = source.map(x -> 0); final Sink> fold = Sink.fold(0, (agg, next) -> agg + next); - zeroes.runWith(fold, mat); // 0 + zeroes.runWith(fold, system); // 0 // #source-immutable - int result = zeroes.runWith(fold, mat).toCompletableFuture().get(3, TimeUnit.SECONDS); + int result = zeroes.runWith(fold, system).toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(0, result); } @@ -80,7 +77,7 @@ public class FlowDocTest extends AbstractJavaTest { final RunnableGraph> runnable = source.toMat(sink, Keep.right()); // materialize the flow - final CompletionStage sum = runnable.run(mat); + final CompletionStage sum = runnable.run(system); // #materialization-in-steps int result = sum.toCompletableFuture().get(3, TimeUnit.SECONDS); @@ -96,7 +93,7 @@ public class FlowDocTest extends AbstractJavaTest { Sink.fold(0, (aggr, next) -> aggr + next); // materialize the flow, getting the Sinks materialized value - final CompletionStage sum = source.runWith(sink, mat); + final CompletionStage sum = source.runWith(sink, system); // #materialization-runWith int result = sum.toCompletableFuture().get(3, TimeUnit.SECONDS); @@ -113,8 +110,8 @@ public class FlowDocTest extends AbstractJavaTest { Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)).toMat(sink, Keep.right()); // get the materialized value of the FoldSink - final CompletionStage sum1 = runnable.run(mat); - final CompletionStage sum2 = runnable.run(mat); + final CompletionStage sum1 = runnable.run(system); + final CompletionStage sum2 = runnable.run(system); // sum1 and sum2 are different Futures! // #stream-reuse @@ -135,7 +132,7 @@ public class FlowDocTest extends AbstractJavaTest { // akka.actor.Cancellable final Source timer = Source.tick(oneSecond, oneSecond, tick); - Sink.ignore().runWith(timer, mat); + Sink.ignore().runWith(timer, system); final Source timerMap = timer.map(t -> "tick"); // WRONG: returned type is not the timers Cancellable! @@ -144,7 +141,7 @@ public class FlowDocTest extends AbstractJavaTest { // #compound-source-is-not-keyed-run // retain the materialized map, in order to retrieve the timer's Cancellable - final Cancellable timerCancellable = timer.to(Sink.ignore()).run(mat); + final Cancellable timerCancellable = timer.to(Sink.ignore()).run(system); timerCancellable.cancel(); // #compound-source-is-not-keyed-run } @@ -239,10 +236,10 @@ public class FlowDocTest extends AbstractJavaTest { // Using runWith will always give the materialized values of the stages added // by runWith() itself - CompletionStage r4 = source.via(flow).runWith(sink, mat); - CompletableFuture> r5 = flow.to(sink).runWith(source, mat); + CompletionStage r4 = source.via(flow).runWith(sink, system); + CompletableFuture> r5 = flow.to(sink).runWith(source, system); Pair>, CompletionStage> r6 = - flow.runWith(source, sink, mat); + flow.runWith(source, sink, system); // Using more complex combinations RunnableGraph>, Cancellable>> r7 = @@ -280,12 +277,12 @@ public class FlowDocTest extends AbstractJavaTest { Source matValuePoweredSource = Source.actorRef(100, OverflowStrategy.fail()); Pair> actorRefSourcePair = - matValuePoweredSource.preMaterialize(mat); + matValuePoweredSource.preMaterialize(system); actorRefSourcePair.first().tell("Hello!", ActorRef.noSender()); // pass source around for materialization - actorRefSourcePair.second().runWith(Sink.foreach(System.out::println), mat); + actorRefSourcePair.second().runWith(Sink.foreach(System.out::println), system); // #source-prematerialization } @@ -295,15 +292,6 @@ public class FlowDocTest extends AbstractJavaTest { // #flow-async } - static { - // #materializer-from-system - ActorSystem system = ActorSystem.create("ExampleSystem"); - - // created from `system`: - ActorMaterializer mat = ActorMaterializer.create(system); - // #materializer-from-system - } - // #materializer-from-actor-context final class RunWithMyself extends AbstractActor { @@ -336,10 +324,11 @@ public class FlowDocTest extends AbstractJavaTest { // #materializer-from-system-in-actor final class RunForever extends AbstractActor { - final ActorMaterializer mat; - RunForever(ActorMaterializer mat) { - this.mat = mat; + private final Materializer materializer; + + public RunForever(Materializer materializer) { + this.materializer = materializer; } @Override @@ -350,7 +339,7 @@ public class FlowDocTest extends AbstractJavaTest { tryDone -> { System.out.println("Terminated stream: " + tryDone); }), - mat); + materializer); } @Override diff --git a/akka-docs/src/test/java/jdocs/stream/FlowErrorDocTest.java b/akka-docs/src/test/java/jdocs/stream/FlowErrorDocTest.java index d7d63d1fca..1ee2654602 100644 --- a/akka-docs/src/test/java/jdocs/stream/FlowErrorDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/FlowErrorDocTest.java @@ -20,8 +20,6 @@ import org.junit.BeforeClass; import org.junit.Test; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.ActorMaterializerSettings; import akka.stream.Materializer; import akka.stream.Supervision; import akka.stream.javadsl.Flow; @@ -48,14 +46,13 @@ public class FlowErrorDocTest extends AbstractJavaTest { @Test(expected = ExecutionException.class) public void demonstrateFailStream() throws Exception { // #stop - final Materializer mat = ActorMaterializer.create(system); final Source source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5)).map(elem -> 100 / elem); final Sink> fold = Sink.fold(0, (acc, elem) -> acc + elem); - final CompletionStage result = source.runWith(fold, mat); + final CompletionStage result = source.runWith(fold, system); // division by zero will fail the stream and the - // result here will be a Future completed with Failure(ArithmeticException) + // result here will be a CompletionStage failed with ArithmeticException // #stop result.toCompletableFuture().get(3, TimeUnit.SECONDS); @@ -69,15 +66,14 @@ public class FlowErrorDocTest extends AbstractJavaTest { if (exc instanceof ArithmeticException) return Supervision.resume(); else return Supervision.stop(); }; - final Materializer mat = - ActorMaterializer.create( - ActorMaterializerSettings.create(system).withSupervisionStrategy(decider), system); final Source source = - Source.from(Arrays.asList(0, 1, 2, 3, 4, 5)).map(elem -> 100 / elem); + Source.from(Arrays.asList(0, 1, 2, 3, 4, 5)) + .map(elem -> 100 / elem) + .withAttributes(ActorAttributes.withSupervisionStrategy(decider)); final Sink> fold = Sink.fold(0, (acc, elem) -> acc + elem); - final CompletionStage result = source.runWith(fold, mat); + final CompletionStage result = source.runWith(fold, system); // the element causing division by zero will be dropped - // result here will be a Future completed with Success(228) + // result here will be a CompletionStage completed with 228 // #resume assertEquals(Integer.valueOf(228), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); @@ -86,7 +82,6 @@ public class FlowErrorDocTest extends AbstractJavaTest { @Test public void demonstrateResumeSectionStream() throws Exception { // #resume-section - final Materializer mat = ActorMaterializer.create(system); final Function decider = exc -> { if (exc instanceof ArithmeticException) return Supervision.resume(); @@ -100,9 +95,9 @@ public class FlowErrorDocTest extends AbstractJavaTest { final Source source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5)).via(flow); final Sink> fold = Sink.fold(0, (acc, elem) -> acc + elem); - final CompletionStage result = source.runWith(fold, mat); + final CompletionStage result = source.runWith(fold, system); // the elements causing division by zero will be dropped - // result here will be a Future completed with Success(150) + // result here will be a Future completed with 150 // #resume-section assertEquals(Integer.valueOf(150), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); @@ -111,7 +106,6 @@ public class FlowErrorDocTest extends AbstractJavaTest { @Test public void demonstrateRestartSectionStream() throws Exception { // #restart-section - final Materializer mat = ActorMaterializer.create(system); final Function decider = exc -> { if (exc instanceof IllegalArgumentException) return Supervision.restart(); @@ -128,10 +122,10 @@ public class FlowErrorDocTest extends AbstractJavaTest { .withAttributes(ActorAttributes.withSupervisionStrategy(decider)); final Source source = Source.from(Arrays.asList(1, 3, -1, 5, 7)).via(flow); final CompletionStage> result = - source.grouped(1000).runWith(Sink.>head(), mat); + source.grouped(1000).runWith(Sink.>head(), system); // the negative element cause the scan stage to be restarted, // i.e. start from 0 again - // result here will be a Future completed with Success(List(0, 1, 4, 0, 5, 12)) + // result here will be a Future completed with List(0, 1, 4, 0, 5, 12) // #restart-section assertEquals( @@ -141,7 +135,6 @@ public class FlowErrorDocTest extends AbstractJavaTest { @Test public void demonstrateRecover() { // #recover - final Materializer mat = ActorMaterializer.create(system); Source.from(Arrays.asList(0, 1, 2, 3, 4, 5, 6)) .map( n -> { @@ -149,7 +142,7 @@ public class FlowErrorDocTest extends AbstractJavaTest { else throw new RuntimeException("Boom!"); }) .recover(new PFBuilder().match(RuntimeException.class, ex -> "stream truncated").build()) - .runForeach(System.out::println, mat); + .runForeach(System.out::println, system); // #recover /* @@ -168,7 +161,6 @@ public class FlowErrorDocTest extends AbstractJavaTest { @Test public void demonstrateRecoverWithRetries() { // #recoverWithRetries - final Materializer mat = ActorMaterializer.create(system); Source planB = Source.from(Arrays.asList("five", "six", "seven", "eight")); Source.from(Arrays.asList(0, 1, 2, 3, 4, 5, 6)) @@ -180,7 +172,7 @@ public class FlowErrorDocTest extends AbstractJavaTest { .recoverWithRetries( 1, // max attempts new PFBuilder().match(RuntimeException.class, ex -> planB).build()) - .runForeach(System.out::println, mat); + .runForeach(System.out::println, system); // #recoverWithRetries /* diff --git a/akka-docs/src/test/java/jdocs/stream/FlowParallelismDocTest.java b/akka-docs/src/test/java/jdocs/stream/FlowParallelismDocTest.java index d009f60912..76efff231c 100644 --- a/akka-docs/src/test/java/jdocs/stream/FlowParallelismDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/FlowParallelismDocTest.java @@ -19,19 +19,16 @@ import akka.stream.javadsl.*; public class FlowParallelismDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("FlowParallellismDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } static class ScoopOfBatter {} diff --git a/akka-docs/src/test/java/jdocs/stream/GraphCyclesDocTest.java b/akka-docs/src/test/java/jdocs/stream/GraphCyclesDocTest.java index 8c93c15fca..d517b58209 100644 --- a/akka-docs/src/test/java/jdocs/stream/GraphCyclesDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/GraphCyclesDocTest.java @@ -21,19 +21,16 @@ import akka.stream.scaladsl.MergePreferred.MergePreferredShape; public class GraphCyclesDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("GraphCyclesDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } static final SilenceSystemOut.System System = SilenceSystemOut.get(); diff --git a/akka-docs/src/test/java/jdocs/stream/GraphStageDocTest.java b/akka-docs/src/test/java/jdocs/stream/GraphStageDocTest.java index 51515dde70..05caa84b1e 100644 --- a/akka-docs/src/test/java/jdocs/stream/GraphStageDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/GraphStageDocTest.java @@ -36,19 +36,16 @@ import static org.junit.Assert.assertEquals; public class GraphStageDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("GraphStageDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } // #simple-source @@ -139,11 +136,12 @@ public class GraphStageDocTest extends AbstractJavaTest { Source mySource = Source.fromGraph(sourceGraph); // Returns 55 - CompletionStage result1 = mySource.take(10).runFold(0, (sum, next) -> sum + next, mat); + CompletionStage result1 = + mySource.take(10).runFold(0, (sum, next) -> sum + next, system); // The source is reusable. This returns 5050 CompletionStage result2 = - mySource.take(100).runFold(0, (sum, next) -> sum + next, mat); + mySource.take(100).runFold(0, (sum, next) -> sum + next, system); // #simple-source-usage assertEquals(result1.toCompletableFuture().get(3, TimeUnit.SECONDS), (Integer) 55); @@ -156,7 +154,7 @@ public class GraphStageDocTest extends AbstractJavaTest { Sink mySink = Sink.fromGraph(sinkGraph); - Source.from(Arrays.asList(1, 2, 3)).runWith(mySink, mat); + Source.from(Arrays.asList(1, 2, 3)).runWith(mySink, system); } // #one-to-one @@ -221,7 +219,7 @@ public class GraphStageDocTest extends AbstractJavaTest { CompletionStage result = Source.from(Arrays.asList("one", "two", "three")) .via(stringLength) - .runFold(0, (sum, n) -> sum + n, mat); + .runFold(0, (sum, n) -> sum + n, system); assertEquals(new Integer(11), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -286,7 +284,7 @@ public class GraphStageDocTest extends AbstractJavaTest { CompletionStage result = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6)) .via(evenFilter) - .runFold(0, (elem, sum) -> sum + elem, mat); + .runFold(0, (elem, sum) -> sum + elem, system); assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -356,7 +354,7 @@ public class GraphStageDocTest extends AbstractJavaTest { Flow.fromGraph(new Duplicator()); CompletionStage result = - Source.from(Arrays.asList(1, 2, 3)).via(duplicator).runFold(0, (n, sum) -> n + sum, mat); + Source.from(Arrays.asList(1, 2, 3)).via(duplicator).runFold(0, (n, sum) -> n + sum, system); assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -412,7 +410,7 @@ public class GraphStageDocTest extends AbstractJavaTest { Flow.fromGraph(new Duplicator2()); CompletionStage result = - Source.from(Arrays.asList(1, 2, 3)).via(duplicator).runFold(0, (n, sum) -> n + sum, mat); + Source.from(Arrays.asList(1, 2, 3)).via(duplicator).runFold(0, (n, sum) -> n + sum, system); assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -428,7 +426,7 @@ public class GraphStageDocTest extends AbstractJavaTest { .via(new Filter((n) -> n % 2 == 0)) .via(new Duplicator()) .via(new Map((n) -> n / 2)) - .runWith(sink, mat); + .runWith(sink, system); // #graph-operator-chain @@ -509,7 +507,7 @@ public class GraphStageDocTest extends AbstractJavaTest { Graph, NotUsed> killSwitch = Flow.fromGraph(new KillSwitch<>(switchF)); - Source.fromPublisher(in).via(killSwitch).to(Sink.fromSubscriber(out)).run(mat); + Source.fromPublisher(in).via(killSwitch).to(Sink.fromSubscriber(out)).run(system); out.request(1); in.sendNext(1); @@ -588,7 +586,7 @@ public class GraphStageDocTest extends AbstractJavaTest { Source.from(Arrays.asList(1, 2, 3)) .via(new TimedGate<>(2)) .takeWithin(java.time.Duration.ofMillis(250)) - .runFold(0, (n, sum) -> n + sum, mat); + .runFold(0, (n, sum) -> n + sum, system); assertEquals(new Integer(1), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -659,7 +657,7 @@ public class GraphStageDocTest extends AbstractJavaTest { .viaMat(new FirstValue(), Keep.right()) .to(Sink.ignore()); - CompletionStage result = flow.run(mat); + CompletionStage result = flow.run(system); assertEquals(new Integer(1), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -751,7 +749,7 @@ public class GraphStageDocTest extends AbstractJavaTest { CompletionStage result1 = Source.from(Arrays.asList(1, 2, 3)) .via(new TwoBuffer<>()) - .runFold(0, (acc, n) -> acc + n, mat); + .runFold(0, (acc, n) -> acc + n, system); assertEquals(new Integer(6), result1.toCompletableFuture().get(3, TimeUnit.SECONDS)); @@ -760,7 +758,7 @@ public class GraphStageDocTest extends AbstractJavaTest { RunnableGraph flow2 = Source.fromPublisher(publisher).via(new TwoBuffer<>()).to(Sink.fromSubscriber(subscriber)); - flow2.run(mat); + flow2.run(system); Subscription sub = subscriber.expectSubscription(); // this happens even though the subscriber has not signalled any demand diff --git a/akka-docs/src/test/java/jdocs/stream/HubDocTest.java b/akka-docs/src/test/java/jdocs/stream/HubDocTest.java index 9717414f76..65638578cd 100644 --- a/akka-docs/src/test/java/jdocs/stream/HubDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/HubDocTest.java @@ -26,19 +26,16 @@ import java.util.function.ToLongBiFunction; public class HubDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer materializer; @BeforeClass public static void setup() { system = ActorSystem.create("GraphDSLDocTest"); - materializer = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - materializer = null; } @Test @@ -55,10 +52,10 @@ public class HubDocTest extends AbstractJavaTest { // now have access to feed elements into it. This Sink can be materialized // any number of times, and every element that enters the Sink will // be consumed by our consumer. - Sink toConsumer = runnableGraph.run(materializer); + Sink toConsumer = runnableGraph.run(system); - Source.single("Hello!").runWith(toConsumer, materializer); - Source.single("Hub!").runWith(toConsumer, materializer); + Source.single("Hello!").runWith(toConsumer, system); + Source.single("Hub!").runWith(toConsumer, system); // #merge-hub } @@ -99,7 +96,7 @@ public class HubDocTest extends AbstractJavaTest { Pair, Source> sinkAndSource = MergeHub.of(String.class, 16) .toMat(BroadcastHub.of(String.class, 256), Keep.both()) - .run(materializer); + .run(system); Sink sink = sinkAndSource.first(); Source source = sinkAndSource.second(); @@ -109,7 +106,7 @@ public class HubDocTest extends AbstractJavaTest { // Ensure that the Broadcast output is dropped if there are no listening parties. // If this dropping Sink is not attached, then the broadcast hub will not drop any // elements itself when there are no subscribers, backpressuring the producer instead. - source.runWith(Sink.ignore(), materializer); + source.runWith(Sink.ignore(), system); // #pub-sub-2 // #pub-sub-3 @@ -127,7 +124,7 @@ public class HubDocTest extends AbstractJavaTest { Source.repeat("Hello World!") .viaMat(busFlow, Keep.right()) .to(Sink.foreach(System.out::println)) - .run(materializer); + .run(system); // Shut down externally killSwitch.shutdown(); diff --git a/akka-docs/src/test/java/jdocs/stream/IntegrationDocTest.java b/akka-docs/src/test/java/jdocs/stream/IntegrationDocTest.java index 7ecec02317..171326afce 100644 --- a/akka-docs/src/test/java/jdocs/stream/IntegrationDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/IntegrationDocTest.java @@ -43,7 +43,6 @@ public class IntegrationDocTest extends AbstractJavaTest { private static final SilenceSystemOut.System System = SilenceSystemOut.get(); static ActorSystem system; - static Materializer mat; static ActorRef ref; @BeforeClass @@ -61,7 +60,6 @@ public class IntegrationDocTest extends AbstractJavaTest { + "akka.actor.default-mailbox.mailbox-type = akka.dispatch.UnboundedMailbox\n"); system = ActorSystem.create("ActorPublisherDocTest", config); - mat = ActorMaterializer.create(system); ref = system.actorOf(Props.create(Translator.class)); } @@ -69,7 +67,6 @@ public class IntegrationDocTest extends AbstractJavaTest { public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; ref = null; } @@ -397,7 +394,7 @@ public class IntegrationDocTest extends AbstractJavaTest { .ask(5, ref, String.class, askTimeout) // continue processing of the replies from the actor .map(elem -> elem.toLowerCase()) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #ask } @@ -418,7 +415,7 @@ public class IntegrationDocTest extends AbstractJavaTest { new StreamCompleted(), ex -> new StreamFailure(ex)); - words.map(el -> el.toLowerCase()).runWith(sink, mat); + words.map(el -> el.toLowerCase()).runWith(sink, system); probe.expectMsg("Stream initialized"); probe.expectMsg("hello"); @@ -457,7 +454,7 @@ public class IntegrationDocTest extends AbstractJavaTest { 4, address -> emailServer.send(new Email(address, "Akka", "I like your tweet"))) .to(Sink.ignore()); - sendEmails.run(mat); + sendEmails.run(system); // #send-emails probe.expectMsg("rolandkuhn@somewhere.com"); @@ -519,7 +516,7 @@ public class IntegrationDocTest extends AbstractJavaTest { 4, address -> emailServer.send(new Email(address, "Akka", "I like your tweet"))) .to(Sink.ignore()); - sendEmails.run(mat); + sendEmails.run(system); // #external-service-mapAsyncUnordered } }; @@ -555,7 +552,7 @@ public class IntegrationDocTest extends AbstractJavaTest { blockingEc)) .to(Sink.ignore()); - sendTextMessages.run(mat); + sendTextMessages.run(system); // #blocking-mapAsync final List got = receiveN(7); @@ -597,7 +594,7 @@ public class IntegrationDocTest extends AbstractJavaTest { .withAttributes(ActorAttributes.dispatcher("blocking-dispatcher")); final RunnableGraph sendTextMessages = phoneNumbers.via(send).to(Sink.ignore()); - sendTextMessages.run(mat); + sendTextMessages.run(system); // #blocking-map probe.expectMsg(String.valueOf("rolandkuhn".hashCode())); @@ -630,7 +627,7 @@ public class IntegrationDocTest extends AbstractJavaTest { .to(Sink.ignore()); // #save-tweets - saveTweets.run(mat); + saveTweets.run(system); probe.expectMsg("rolandkuhn"); probe.expectMsg("patriknw"); @@ -677,7 +674,7 @@ public class IntegrationDocTest extends AbstractJavaTest { return elem; }) .mapAsync(4, service::convert) - .runForeach(elem -> System.out.println("after: " + elem), mat); + .runForeach(elem -> System.out.println("after: " + elem), system); // #sometimes-slow-mapAsync probe.expectMsg("after: A"); @@ -716,10 +713,6 @@ public class IntegrationDocTest extends AbstractJavaTest { final Executor blockingEc = system.dispatchers().lookup("blocking-dispatcher"); final SometimesSlowService service = new SometimesSlowService(blockingEc); - final ActorMaterializer mat = - ActorMaterializer.create( - ActorMaterializerSettings.create(system).withInputBuffer(4, 4), system); - Source.from(Arrays.asList("a", "B", "C", "D", "e", "F", "g", "H", "i", "J")) .map( elem -> { @@ -727,7 +720,9 @@ public class IntegrationDocTest extends AbstractJavaTest { return elem; }) .mapAsyncUnordered(4, service::convert) - .runForeach(elem -> System.out.println("after: " + elem), mat); + .to(Sink.foreach(elem -> System.out.println("after: " + elem))) + .withAttributes(Attributes.inputBuffer(4, 4)) + .run(system); // #sometimes-slow-mapAsyncUnordered final List got = receiveN(10); @@ -760,11 +755,11 @@ public class IntegrationDocTest extends AbstractJavaTest { .throttle(elementsToProcess, Duration.ofSeconds(3)) .map(x -> x * x) .to(Sink.foreach(x -> System.out.println("got: " + x))) - .run(mat); + .run(system); Source source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - source.map(x -> sourceQueue.offer(x)).runWith(Sink.ignore(), mat); + source.map(x -> sourceQueue.offer(x)).runWith(Sink.ignore(), system); // #source-queue } @@ -782,7 +777,10 @@ public class IntegrationDocTest extends AbstractJavaTest { Source.actorRef( bufferSize, OverflowStrategy.dropHead()); // note: backpressure is not supported ActorRef actorRef = - source.map(x -> x * x).to(Sink.foreach(x -> System.out.println("got: " + x))).run(mat); + source + .map(x -> x * x) + .to(Sink.foreach(x -> System.out.println("got: " + x))) + .run(system); actorRef.tell(1, ActorRef.noSender()); actorRef.tell(2, ActorRef.noSender()); diff --git a/akka-docs/src/test/java/jdocs/stream/KillSwitchDocTest.java b/akka-docs/src/test/java/jdocs/stream/KillSwitchDocTest.java index 7eeaae0fb6..4854c506a0 100644 --- a/akka-docs/src/test/java/jdocs/stream/KillSwitchDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/KillSwitchDocTest.java @@ -29,19 +29,16 @@ import static org.junit.Assert.assertEquals; class KillSwitchDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("GraphDSLDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -58,7 +55,7 @@ class KillSwitchDocTest extends AbstractJavaTest { countingSrc .viaMat(KillSwitches.single(), Keep.right()) .toMat(lastSnk, Keep.both()) - .run(mat); + .run(system); final UniqueKillSwitch killSwitch = stream.first(); final CompletionStage completionStage = stream.second(); @@ -82,7 +79,7 @@ class KillSwitchDocTest extends AbstractJavaTest { countingSrc .viaMat(KillSwitches.single(), Keep.right()) .toMat(lastSnk, Keep.both()) - .run(mat); + .run(system); final UniqueKillSwitch killSwitch = stream.first(); final CompletionStage completionStage = stream.second(); @@ -105,13 +102,16 @@ class KillSwitchDocTest extends AbstractJavaTest { final SharedKillSwitch killSwitch = KillSwitches.shared("my-kill-switch"); final CompletionStage completionStage = - countingSrc.viaMat(killSwitch.flow(), Keep.right()).toMat(lastSnk, Keep.right()).run(mat); + countingSrc + .viaMat(killSwitch.flow(), Keep.right()) + .toMat(lastSnk, Keep.right()) + .run(system); final CompletionStage completionStageDelayed = countingSrc .delay(Duration.ofSeconds(1), DelayOverflowStrategy.backpressure()) .viaMat(killSwitch.flow(), Keep.right()) .toMat(lastSnk, Keep.right()) - .run(mat); + .run(system); doSomethingElse(); killSwitch.shutdown(); @@ -134,9 +134,15 @@ class KillSwitchDocTest extends AbstractJavaTest { final SharedKillSwitch killSwitch = KillSwitches.shared("my-kill-switch"); final CompletionStage completionStage1 = - countingSrc.viaMat(killSwitch.flow(), Keep.right()).toMat(lastSnk, Keep.right()).run(mat); + countingSrc + .viaMat(killSwitch.flow(), Keep.right()) + .toMat(lastSnk, Keep.right()) + .run(system); final CompletionStage completionStage2 = - countingSrc.viaMat(killSwitch.flow(), Keep.right()).toMat(lastSnk, Keep.right()).run(mat); + countingSrc + .viaMat(killSwitch.flow(), Keep.right()) + .toMat(lastSnk, Keep.right()) + .run(system); final Exception error = new Exception("boom!"); killSwitch.abort(error); diff --git a/akka-docs/src/test/java/jdocs/stream/Main.java b/akka-docs/src/test/java/jdocs/stream/Main.java index c11f2a2f00..08d6627aa6 100644 --- a/akka-docs/src/test/java/jdocs/stream/Main.java +++ b/akka-docs/src/test/java/jdocs/stream/Main.java @@ -4,9 +4,12 @@ package jdocs.stream; +import akka.actor.ActorSystem; + // #main-app public class Main { public static void main(String[] argv) { + final ActorSystem system = ActorSystem.create("QuickStart"); // Code here } } diff --git a/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java b/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java index b71304dbfd..8811ff5836 100644 --- a/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/QuickStartDocTest.java @@ -34,17 +34,14 @@ public class QuickStartDocTest extends AbstractJavaTest { @Test public void demonstrateSource() throws InterruptedException, ExecutionException { - // #create-materializer final ActorSystem system = ActorSystem.create("QuickStart"); - final Materializer materializer = ActorMaterializer.create(system); - // #create-materializer // #create-source final Source source = Source.range(1, 100); // #create-source // #run-source - source.runForeach(i -> System.out.println(i), materializer); + source.runForeach(i -> System.out.println(i), system); // #run-source // #transform-source @@ -54,11 +51,11 @@ public class QuickStartDocTest extends AbstractJavaTest { final CompletionStage result = factorials .map(num -> ByteString.fromString(num.toString() + "\n")) - .runWith(FileIO.toPath(Paths.get("factorials.txt")), materializer); + .runWith(FileIO.toPath(Paths.get("factorials.txt")), system); // #transform-source // #use-transformed-sink - factorials.map(BigInteger::toString).runWith(lineSink("factorial2.txt"), materializer); + factorials.map(BigInteger::toString).runWith(lineSink("factorial2.txt"), system); // #use-transformed-sink // #add-streams @@ -68,11 +65,11 @@ public class QuickStartDocTest extends AbstractJavaTest { // #add-streams .take(2) // #add-streams - .runForeach(s -> System.out.println(s), materializer); + .runForeach(s -> System.out.println(s), system); // #add-streams // #run-source-and-terminate - final CompletionStage done = source.runForeach(i -> System.out.println(i), materializer); + final CompletionStage done = source.runForeach(i -> System.out.println(i), system); done.thenRun(() -> system.terminate()); // #run-source-and-terminate diff --git a/akka-docs/src/test/java/jdocs/stream/RateTransformationDocTest.java b/akka-docs/src/test/java/jdocs/stream/RateTransformationDocTest.java index 84485201f3..c4d488d530 100644 --- a/akka-docs/src/test/java/jdocs/stream/RateTransformationDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/RateTransformationDocTest.java @@ -8,8 +8,6 @@ import akka.NotUsed; import akka.actor.ActorSystem; import akka.japi.Pair; import akka.japi.tuple.Tuple3; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Flow; import akka.stream.javadsl.Keep; import akka.stream.javadsl.Sink; @@ -42,19 +40,16 @@ import static org.junit.Assert.assertEquals; public class RateTransformationDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RateTransformationDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } final Random r = new Random(); @@ -84,7 +79,7 @@ public class RateTransformationDocTest extends AbstractJavaTest { .map(i -> r.nextGaussian()) .via(statsFlow) .grouped(10) - .runWith(Sink.head(), mat); + .runWith(Sink.head(), system); fut.toCompletableFuture().get(1, TimeUnit.SECONDS); } @@ -110,7 +105,7 @@ public class RateTransformationDocTest extends AbstractJavaTest { final CompletionStage fut = Source.from(new ArrayList(Collections.nCopies(1000, 1.0))) .via(sampleFlow) - .runWith(Sink.fold(0.0, (agg, next) -> agg + next), mat); + .runWith(Sink.fold(0.0, (agg, next) -> agg + next), system); final Double count = fut.toCompletableFuture().get(1, TimeUnit.SECONDS); } @@ -127,7 +122,7 @@ public class RateTransformationDocTest extends AbstractJavaTest { .via(lastFlow) .grouped(10) .toMat(Sink.head(), Keep.both()) - .run(mat); + .run(system); final TestPublisher.Probe probe = probeFut.first(); final CompletionStage> fut = probeFut.second(); @@ -150,7 +145,7 @@ public class RateTransformationDocTest extends AbstractJavaTest { .via(lastFlow) .grouped(10) .toMat(Sink.head(), Keep.right()) - .run(mat); + .run(system); final List extrapolated = fut.toCompletableFuture().get(1, TimeUnit.SECONDS); assertEquals(extrapolated.size(), 10); @@ -187,7 +182,7 @@ public class RateTransformationDocTest extends AbstractJavaTest { TestSource.probe(system) .via(realDriftFlow) .toMat(TestSink.>probe(system), Keep.both()) - .run(mat); + .run(system); final TestPublisher.Probe pub = pubSub.first(); final TestSubscriber.Probe> sub = pubSub.second(); @@ -225,7 +220,7 @@ public class RateTransformationDocTest extends AbstractJavaTest { TestSource.probe(system) .via(realDriftFlow) .toMat(TestSink.>probe(system), Keep.both()) - .run(mat); + .run(system); final TestPublisher.Probe pub = pubSub.first(); final TestSubscriber.Probe> sub = pubSub.second(); diff --git a/akka-docs/src/test/java/jdocs/stream/ReactiveStreamsDocTest.java b/akka-docs/src/test/java/jdocs/stream/ReactiveStreamsDocTest.java index f7c88f595d..e68e3224c3 100644 --- a/akka-docs/src/test/java/jdocs/stream/ReactiveStreamsDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/ReactiveStreamsDocTest.java @@ -8,7 +8,6 @@ import akka.NotUsed; import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.japi.function.Creator; -import akka.stream.*; import akka.stream.javadsl.*; import akka.testkit.TestProbe; import jdocs.AbstractJavaTest; @@ -34,14 +33,12 @@ import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.AKKA; public class ReactiveStreamsDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; static TestProbe storageProbe; static TestProbe alertProbe; @BeforeClass public static void setup() { system = ActorSystem.create("ReactiveStreamsDocTest"); - mat = ActorMaterializer.create(system); storageProbe = new TestProbe(system); alertProbe = new TestProbe(system); } @@ -50,7 +47,6 @@ public class ReactiveStreamsDocTest extends AbstractJavaTest { public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; storageProbe = null; alertProbe = null; } @@ -86,7 +82,7 @@ public class ReactiveStreamsDocTest extends AbstractJavaTest { @Override public Publisher tweets() { return TwitterStreamQuickstartDocTest.Model.tweets.runWith( - Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), mat); + Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), system); } /** @@ -155,7 +151,7 @@ public class ReactiveStreamsDocTest extends AbstractJavaTest { { // #flow-publisher-subscriber - final Processor processor = authors.toProcessor().run(mat); + final Processor processor = authors.toProcessor().run(system); rs.tweets().subscribe(processor); processor.subscribe(rs.storage()); @@ -176,7 +172,7 @@ public class ReactiveStreamsDocTest extends AbstractJavaTest { final Publisher authorPublisher = Source.fromPublisher(rs.tweets()) .via(authors) - .runWith(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), mat); + .runWith(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), system); authorPublisher.subscribe(rs.storage()); // #source-publisher @@ -196,7 +192,7 @@ public class ReactiveStreamsDocTest extends AbstractJavaTest { final Publisher authorPublisher = Source.fromPublisher(rs.tweets()) .via(authors) - .runWith(Sink.asPublisher(AsPublisher.WITH_FANOUT), mat); + .runWith(Sink.asPublisher(AsPublisher.WITH_FANOUT), system); authorPublisher.subscribe(rs.storage()); authorPublisher.subscribe(rs.alert()); @@ -217,7 +213,7 @@ public class ReactiveStreamsDocTest extends AbstractJavaTest { final Subscriber storage = rs.storage(); final Subscriber tweetSubscriber = - authors.to(Sink.fromSubscriber(storage)).runWith(Source.asSubscriber(), mat); + authors.to(Sink.fromSubscriber(storage)).runWith(Source.asSubscriber(), system); rs.tweets().subscribe(tweetSubscriber); // #sink-subscriber @@ -236,7 +232,7 @@ public class ReactiveStreamsDocTest extends AbstractJavaTest { final Creator> factory = new Creator>() { public Processor create() { - return Flow.of(Integer.class).toProcessor().run(mat); + return Flow.of(Integer.class).toProcessor().run(system); } }; diff --git a/akka-docs/src/test/java/jdocs/stream/SinkRecipeDocTest.java b/akka-docs/src/test/java/jdocs/stream/SinkRecipeDocTest.java index 8473828142..2d95f942c3 100644 --- a/akka-docs/src/test/java/jdocs/stream/SinkRecipeDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/SinkRecipeDocTest.java @@ -7,8 +7,6 @@ package jdocs.stream; import akka.NotUsed; import akka.actor.ActorSystem; import akka.japi.function.Function; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Source; import akka.stream.javadsl.Sink; import jdocs.AbstractJavaTest; @@ -20,12 +18,10 @@ import java.util.concurrent.CompletionStage; public class SinkRecipeDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("SinkRecipeDocTest"); - mat = ActorMaterializer.create(system); } @Test @@ -38,7 +34,7 @@ public class SinkRecipeDocTest extends AbstractJavaTest { final Source numberSource = Source.range(1, 100); - numberSource.runWith(Sink.foreachAsync(10, asyncProcessing), mat); + numberSource.runWith(Sink.foreachAsync(10, asyncProcessing), system); // #forseachAsync-processing } } diff --git a/akka-docs/src/test/java/jdocs/stream/StreamBuffersRateDocTest.java b/akka-docs/src/test/java/jdocs/stream/StreamBuffersRateDocTest.java index a4626e5e3d..ad7e33c732 100644 --- a/akka-docs/src/test/java/jdocs/stream/StreamBuffersRateDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/StreamBuffersRateDocTest.java @@ -23,19 +23,16 @@ public class StreamBuffersRateDocTest extends AbstractJavaTest { static class Job {} static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("StreamBuffersDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } final SilenceSystemOut.System System = SilenceSystemOut.get(); @@ -62,7 +59,7 @@ public class StreamBuffersRateDocTest extends AbstractJavaTest { return i; }) .async() - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #pipelining } @@ -109,7 +106,7 @@ public class StreamBuffersRateDocTest extends AbstractJavaTest { b.from(zipper.out()).to(b.add(Sink.foreach(elem -> System.out.println(elem)))); return ClosedShape.getInstance(); })) - .run(mat); + .run(system); // #buffering-abstraction-leak } diff --git a/akka-docs/src/test/java/jdocs/stream/StreamPartialGraphDSLDocTest.java b/akka-docs/src/test/java/jdocs/stream/StreamPartialGraphDSLDocTest.java index 89909c1175..84bd4f996b 100644 --- a/akka-docs/src/test/java/jdocs/stream/StreamPartialGraphDSLDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/StreamPartialGraphDSLDocTest.java @@ -28,19 +28,16 @@ import static org.junit.Assert.assertEquals; public class StreamPartialGraphDSLDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("StreamPartialGraphDSLDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -78,7 +75,7 @@ public class StreamPartialGraphDSLDocTest extends AbstractJavaTest { return ClosedShape.getInstance(); })); - final CompletionStage max = g.run(mat); + final CompletionStage max = g.run(system); // #simple-partial-graph-dsl assertEquals(Integer.valueOf(3), max.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -119,7 +116,7 @@ public class StreamPartialGraphDSLDocTest extends AbstractJavaTest { })); final CompletionStage> firstPair = - pairs.runWith(Sink.>head(), mat); + pairs.runWith(Sink.>head(), system); // #source-from-partial-graph-dsl assertEquals(new Pair<>(0, 1), firstPair.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -146,7 +143,7 @@ public class StreamPartialGraphDSLDocTest extends AbstractJavaTest { // #flow-from-partial-graph-dsl final CompletionStage> matSink = // #flow-from-partial-graph-dsl - Source.single(1).via(pairs).runWith(Sink.>head(), mat); + Source.single(1).via(pairs).runWith(Sink.>head(), system); // #flow-from-partial-graph-dsl assertEquals(new Pair<>(1, "1"), matSink.toCompletableFuture().get(3, TimeUnit.SECONDS)); @@ -163,7 +160,7 @@ public class StreamPartialGraphDSLDocTest extends AbstractJavaTest { // #source-combine final CompletionStage result = // #source-combine - sources.runWith(Sink.fold(0, (a, b) -> a + b), mat); + sources.runWith(Sink.fold(0, (a, b) -> a + b), system); // #source-combine assertEquals(Integer.valueOf(3), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); @@ -184,7 +181,7 @@ public class StreamPartialGraphDSLDocTest extends AbstractJavaTest { Sink sinks = Sink.combine(sendRemotely, localProcessing, new ArrayList<>(), a -> Broadcast.create(a)); - Source.from(Arrays.asList(new Integer[] {0, 1, 2})).runWith(sinks, mat); + Source.from(Arrays.asList(new Integer[] {0, 1, 2})).runWith(sinks, system); // #sink-combine probe.expectMsgEquals(0); probe.expectMsgEquals(1); diff --git a/akka-docs/src/test/java/jdocs/stream/StreamTestKitDocTest.java b/akka-docs/src/test/java/jdocs/stream/StreamTestKitDocTest.java index b3fa82932b..38c0083874 100644 --- a/akka-docs/src/test/java/jdocs/stream/StreamTestKitDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/StreamTestKitDocTest.java @@ -29,19 +29,16 @@ import akka.stream.testkit.javadsl.*; public class StreamTestKitDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("StreamTestKitDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -53,7 +50,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { .toMat(Sink.fold(0, (agg, next) -> agg + next), Keep.right()); final CompletionStage future = - Source.from(Arrays.asList(1, 2, 3, 4)).runWith(sinkUnderTest, mat); + Source.from(Arrays.asList(1, 2, 3, 4)).runWith(sinkUnderTest, system); final Integer result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assert (result == 20); // #strict-collection @@ -64,7 +61,8 @@ public class StreamTestKitDocTest extends AbstractJavaTest { // #grouped-infinite final Source sourceUnderTest = Source.repeat(1).map(i -> i * 2); - final CompletionStage> future = sourceUnderTest.take(10).runWith(Sink.seq(), mat); + final CompletionStage> future = + sourceUnderTest.take(10).runWith(Sink.seq(), system); final List result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(result, Collections.nCopies(10, 2)); // #grouped-infinite @@ -79,7 +77,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { final CompletionStage future = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6)) .via(flowUnderTest) - .runWith(Sink.fold(0, (agg, next) -> agg + next), mat); + .runWith(Sink.fold(0, (agg, next) -> agg + next), system); final Integer result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assert (result == 10); // #folded-stream @@ -93,7 +91,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { final TestKit probe = new TestKit(system); final CompletionStage>> future = - sourceUnderTest.grouped(2).runWith(Sink.head(), mat); + sourceUnderTest.grouped(2).runWith(Sink.head(), system); akka.pattern.Patterns.pipe(future, system.dispatcher()).to(probe.getRef()); probe.expectMsg(Duration.ofSeconds(3), Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4))); // #pipeto-testprobe @@ -112,7 +110,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { final TestKit probe = new TestKit(system); final Cancellable cancellable = - sourceUnderTest.to(Sink.actorRef(probe.getRef(), Tick.COMPLETED)).run(mat); + sourceUnderTest.to(Sink.actorRef(probe.getRef(), Tick.COMPLETED)).run(system); probe.expectMsg(Duration.ofSeconds(3), Tick.TOCK); probe.expectNoMessage(Duration.ofMillis(100)); probe.expectMsg(Duration.ofSeconds(3), Tick.TOCK); @@ -132,7 +130,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { final Pair> refAndCompletionStage = Source.actorRef(8, OverflowStrategy.fail()) .toMat(sinkUnderTest, Keep.both()) - .run(mat); + .run(system); final ActorRef ref = refAndCompletionStage.first(); final CompletionStage future = refAndCompletionStage.second(); @@ -153,7 +151,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { Source.from(Arrays.asList(1, 2, 3, 4)).filter(elem -> elem % 2 == 0).map(elem -> elem * 2); sourceUnderTest - .runWith(TestSink.probe(system), mat) + .runWith(TestSink.probe(system), system) .request(2) .expectNext(4, 8) .expectComplete(); @@ -167,7 +165,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { TestSource.probe(system) .toMat(sinkUnderTest, Keep.left()) - .run(mat) + .run(system) .expectCancellation(); // #test-source-probe } @@ -178,7 +176,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { final Sink> sinkUnderTest = Sink.head(); final Pair, CompletionStage> probeAndCompletionStage = - TestSource.probe(system).toMat(sinkUnderTest, Keep.both()).run(mat); + TestSource.probe(system).toMat(sinkUnderTest, Keep.both()).run(system); final TestPublisher.Probe probe = probeAndCompletionStage.first(); final CompletionStage future = probeAndCompletionStage.second(); probe.sendError(new Exception("boom")); @@ -211,7 +209,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest { TestSource.probe(system) .via(flowUnderTest) .toMat(TestSink.probe(system), Keep.both()) - .run(mat); + .run(system); final TestPublisher.Probe pub = pubAndSub.first(); final TestSubscriber.Probe sub = pubAndSub.second(); diff --git a/akka-docs/src/test/java/jdocs/stream/SubstreamDocTest.java b/akka-docs/src/test/java/jdocs/stream/SubstreamDocTest.java index 59af91c0ab..b2ebb8d692 100644 --- a/akka-docs/src/test/java/jdocs/stream/SubstreamDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/SubstreamDocTest.java @@ -22,19 +22,16 @@ import java.util.List; public class SubstreamDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("FlowDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -47,26 +44,26 @@ public class SubstreamDocTest extends AbstractJavaTest { Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .groupBy(3, elem -> elem % 3) .to(Sink.ignore()) - .run(mat); + .run(system); // #groupBy2 // #groupBy3 Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .groupBy(3, elem -> elem % 3) .mergeSubstreams() - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #groupBy3 // #groupBy4 Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .groupBy(3, elem -> elem % 3) .mergeSubstreamsWithParallelism(2) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // concatSubstreams is equivalent to mergeSubstreamsWithParallelism(1) Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .groupBy(3, elem -> elem % 3) .concatSubstreams() - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #groupBy4 } @@ -89,7 +86,7 @@ public class SubstreamDocTest extends AbstractJavaTest { .map(x -> 1) .reduce((x, y) -> x + y) .to(Sink.foreach(x -> System.out.println(x))) - .run(mat); + .run(system); // #wordCount Thread.sleep(1000); } @@ -99,13 +96,13 @@ public class SubstreamDocTest extends AbstractJavaTest { // #flatMapConcat Source.from(Arrays.asList(1, 2)) .flatMapConcat(i -> Source.from(Arrays.asList(i, i, i))) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #flatMapConcat // #flatMapMerge Source.from(Arrays.asList(1, 2)) .flatMapMerge(2, i -> Source.from(Arrays.asList(i, i, i))) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #flatMapMerge } } diff --git a/akka-docs/src/test/java/jdocs/stream/TwitterStreamQuickstartDocTest.java b/akka-docs/src/test/java/jdocs/stream/TwitterStreamQuickstartDocTest.java index b8cab386ca..8488b11f07 100644 --- a/akka-docs/src/test/java/jdocs/stream/TwitterStreamQuickstartDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/TwitterStreamQuickstartDocTest.java @@ -41,19 +41,15 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; - @BeforeClass public static void setup() { system = ActorSystem.create("TwitterStreamQuickstartDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } abstract static class Model { @@ -201,11 +197,10 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { abstract static class Example1 { // #first-sample - // #materializer-setup + // #system-setup final ActorSystem system = ActorSystem.create("reactive-tweets"); - final Materializer mat = ActorMaterializer.create(system); // #first-sample - // #materializer-setup + // #system-setup } static class Example2 { @@ -263,12 +258,12 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { // #first-sample // #authors-foreachsink-println - authors.runWith(Sink.foreach(a -> System.out.println(a)), mat); + authors.runWith(Sink.foreach(a -> System.out.println(a)), system); // #first-sample // #authors-foreachsink-println // #authors-foreach-println - authors.runForeach(a -> System.out.println(a), mat); + authors.runForeach(a -> System.out.println(a), system); // #authors-foreach-println } @@ -310,7 +305,7 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { b.from(bcast).via(toTags).to(hashtags); return ClosedShape.getInstance(); })) - .run(mat); + .run(system); // #graph-dsl-broadcast } @@ -329,7 +324,7 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { tweets .buffer(10, OverflowStrategy.dropHead()) .map(t -> slowComputation(t)) - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #tweets-slow-consumption-dropHead } @@ -342,7 +337,7 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { final RunnableGraph> counter = tweets.map(t -> 1).toMat(sumSink, Keep.right()); - final CompletionStage sum = counter.run(mat); + final CompletionStage sum = counter.run(system); sum.thenAcceptAsync( c -> System.out.println("Total tweets processed: " + c), system.dispatcher()); @@ -350,7 +345,7 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { new Object() { // #tweets-fold-count-oneline - final CompletionStage sum = tweets.map(t -> 1).runWith(sumSink, mat); + final CompletionStage sum = tweets.map(t -> 1).runWith(sumSink, system); // #tweets-fold-count-oneline }; } @@ -370,9 +365,9 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { .toMat(sumSink, Keep.right()); // materialize the stream once in the morning - final CompletionStage morningTweetsCount = counterRunnableGraph.run(mat); + final CompletionStage morningTweetsCount = counterRunnableGraph.run(system); // and once in the evening, reusing the blueprint - final CompletionStage eveningTweetsCount = counterRunnableGraph.run(mat); + final CompletionStage eveningTweetsCount = counterRunnableGraph.run(system); // #tweets-runnable-flow-materialized-twice } diff --git a/akka-docs/src/test/java/jdocs/stream/io/StreamFileDocTest.java b/akka-docs/src/test/java/jdocs/stream/io/StreamFileDocTest.java index e72f15a268..dca5eea22a 100644 --- a/akka-docs/src/test/java/jdocs/stream/io/StreamFileDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/io/StreamFileDocTest.java @@ -31,19 +31,15 @@ public class StreamFileDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; - @BeforeClass public static void setup() { system = ActorSystem.create("StreamFileDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } final SilenceSystemOut.System System = SilenceSystemOut.get(); @@ -70,7 +66,7 @@ public class StreamFileDocTest extends AbstractJavaTest { Sink> printlnSink = Sink.foreach(chunk -> System.out.println(chunk.utf8String())); - CompletionStage ioResult = FileIO.fromPath(file).to(printlnSink).run(mat); + CompletionStage ioResult = FileIO.fromPath(file).to(printlnSink).run(system); // #file-source } finally { Files.delete(file); @@ -102,7 +98,7 @@ public class StreamFileDocTest extends AbstractJavaTest { Source textSource = Source.single("Hello Akka Stream!"); CompletionStage ioResult = - textSource.map(ByteString::fromString).runWith(fileSink, mat); + textSource.map(ByteString::fromString).runWith(fileSink, system); // #file-sink } finally { Files.delete(file); diff --git a/akka-docs/src/test/java/jdocs/stream/io/StreamTcpDocTest.java b/akka-docs/src/test/java/jdocs/stream/io/StreamTcpDocTest.java index 09b1a1af25..5dde9431a1 100644 --- a/akka-docs/src/test/java/jdocs/stream/io/StreamTcpDocTest.java +++ b/akka-docs/src/test/java/jdocs/stream/io/StreamTcpDocTest.java @@ -20,10 +20,8 @@ import org.junit.BeforeClass; import org.junit.Test; import akka.actor.ActorSystem; -import akka.stream.*; import akka.stream.javadsl.*; import akka.stream.javadsl.Tcp.*; -import akka.stream.stage.*; import akka.testkit.SocketUtil; import akka.testkit.TestProbe; import akka.util.ByteString; @@ -31,19 +29,16 @@ import akka.util.ByteString; public class StreamTcpDocTest extends AbstractJavaTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("StreamTcpDocTest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } final SilenceSystemOut.System System = SilenceSystemOut.get(); @@ -88,9 +83,9 @@ public class StreamTcpDocTest extends AbstractJavaTest { .map(s -> s + "!!!\n") .map(ByteString::fromString); - connection.handleWith(echo, mat); + connection.handleWith(echo, system); }, - mat); + system); // #echo-server-simple-handle } } @@ -141,9 +136,9 @@ public class StreamTcpDocTest extends AbstractJavaTest { .map(s -> s + "\n") .map(ByteString::fromString); - connection.handleWith(serverLogic, mat); + connection.handleWith(serverLogic, system); })) - .run(mat); + .run(system); // #welcome-banner-chat-server // make sure server is bound before we do anything else @@ -179,7 +174,7 @@ public class StreamTcpDocTest extends AbstractJavaTest { .map(elem -> readLine("> ")) .via(replParser); - CompletionStage connectionCS = connection.join(repl).run(mat); + CompletionStage connectionCS = connection.join(repl).run(system); // #repl-client // make sure it got connected (or fails the test) diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeAdhocSourceTest.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeAdhocSourceTest.java index d9804f60a9..4fe6142939 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeAdhocSourceTest.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeAdhocSourceTest.java @@ -32,20 +32,17 @@ import static org.junit.Assert.assertEquals; public class RecipeAdhocSourceTest extends RecipeTest { static ActorSystem system; - static Materializer mat; Duration duration200mills = Duration.ofMillis(200); @BeforeClass public static void setup() { system = ActorSystem.create("RecipeAdhocSource"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } // #adhoc-source @@ -93,7 +90,7 @@ public class RecipeAdhocSourceTest extends RecipeTest { TestSubscriber.Probe probe = adhocSource(Source.repeat("a"), duration200mills, 3) .toMat(TestSink.probe(system), Keep.right()) - .run(mat); + .run(system); probe.requestNext("a"); } }; @@ -113,7 +110,7 @@ public class RecipeAdhocSourceTest extends RecipeTest { duration200mills, 3) .toMat(TestSink.probe(system), Keep.right()) - .run(mat); + .run(system); probe.requestNext("a"); Thread.sleep(300); @@ -136,7 +133,7 @@ public class RecipeAdhocSourceTest extends RecipeTest { duration200mills, 3) .toMat(TestSink.probe(system), Keep.right()) - .run(mat); + .run(system); probe.requestNext("a"); Thread.sleep(100); @@ -174,7 +171,7 @@ public class RecipeAdhocSourceTest extends RecipeTest { duration200mills, 3) .toMat(TestSink.probe(system), Keep.right()) - .run(mat); + .run(system); probe.requestNext("a"); assertEquals(1, startedCount.get()); @@ -204,7 +201,7 @@ public class RecipeAdhocSourceTest extends RecipeTest { duration200mills, 3) .toMat(TestSink.probe(system), Keep.right()) - .run(mat); + .run(system); probe.requestNext("a"); assertEquals(1, startedCount.get()); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java index 714aed7500..f5c4d3ed83 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java @@ -30,19 +30,16 @@ import static org.junit.Assert.assertTrue; public class RecipeByteStrings extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeByteStrings"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } final Source rawBytes = @@ -142,7 +139,7 @@ public class RecipeByteStrings extends RecipeTest { // #bytestring-chunker2 CompletionStage> chunksFuture = - chunksStream.limit(10).runWith(Sink.seq(), mat); + chunksStream.limit(10).runWith(Sink.seq(), system); List chunks = chunksFuture.toCompletableFuture().get(3, TimeUnit.SECONDS); @@ -242,7 +239,7 @@ public class RecipeByteStrings extends RecipeTest { bytes1 .via(limiter) .limit(10) - .runWith(Sink.seq(), mat) + .runWith(Sink.seq(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); ByteString acc = emptyByteString(); @@ -256,7 +253,7 @@ public class RecipeByteStrings extends RecipeTest { bytes2 .via(limiter) .limit(10) - .runWith(Sink.seq(), mat) + .runWith(Sink.seq(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); } catch (ExecutionException ex) { @@ -287,7 +284,7 @@ public class RecipeByteStrings extends RecipeTest { List got = compacted .limit(10) - .runWith(Sink.seq(), mat) + .runWith(Sink.seq(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDecompress.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDecompress.java index 47adfeb081..dd99e7356a 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDecompress.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDecompress.java @@ -6,8 +6,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Compression; import akka.stream.javadsl.Source; import akka.testkit.javadsl.TestKit; @@ -23,19 +21,16 @@ import java.util.concurrent.TimeUnit; public class RecipeDecompress extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeDecompress"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -52,7 +47,7 @@ public class RecipeDecompress extends RecipeTest { ByteString decompressedData = decompressedStream - .runFold(emptyByteString(), ByteString::concat, mat) + .runFold(emptyByteString(), ByteString::concat, system) .toCompletableFuture() .get(1, TimeUnit.SECONDS); String decompressedString = decompressedData.utf8String(); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDigest.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDigest.java index 524dbf0269..fd5b2d67d9 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDigest.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDigest.java @@ -24,19 +24,16 @@ import static org.junit.Assert.assertEquals; public class RecipeDigest extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeDigest"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } // #calculating-digest @@ -111,7 +108,7 @@ public class RecipeDigest extends RecipeTest { // #calculating-digest2 ByteString got = - digest.runWith(Sink.head(), mat).toCompletableFuture().get(3, TimeUnit.SECONDS); + digest.runWith(Sink.head(), system).toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals( ByteString.fromInts( diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java index 58a7dfda8a..d8e1753194 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java @@ -20,19 +20,16 @@ import java.util.concurrent.CompletionStage; public class RecipeDroppyBroadcast extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeDroppyBroadcast"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java index 73f7770e61..fb42030878 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java @@ -6,8 +6,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.testkit.javadsl.TestKit; @@ -23,19 +21,16 @@ import static org.junit.Assert.assertEquals; public class RecipeFlattenList extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeFlattenList"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -56,7 +51,7 @@ public class RecipeFlattenList extends RecipeTest { List got = flattened .limit(10) - .runWith(Sink.seq(), mat) + .runWith(Sink.seq(), system) .toCompletableFuture() .get(1, TimeUnit.SECONDS); assertEquals(got.get(0), new Message("1")); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java index d0bf71e726..4c23556a8c 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java @@ -24,19 +24,16 @@ import static junit.framework.TestCase.assertTrue; public class RecipeGlobalRateLimit extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeGlobalRateLimit"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } public @@ -229,7 +226,7 @@ public class RecipeGlobalRateLimit extends RecipeTest { builder.from(merge).to(s); return ClosedShape.getInstance(); })) - .run(mat); + .run(system); probe.expectSubscription().request(1000); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeHold.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeHold.java index dd0a4e733e..5246bfd954 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeHold.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeHold.java @@ -16,7 +16,6 @@ import akka.stream.testkit.TestSubscriber; import akka.stream.testkit.javadsl.TestSink; import akka.stream.testkit.javadsl.TestSource; import akka.testkit.javadsl.TestKit; -import akka.util.ByteString; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -26,19 +25,16 @@ import java.util.concurrent.TimeUnit; public class RecipeHold extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeHold"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } // #hold-version-1 @@ -151,7 +147,7 @@ public class RecipeHold extends RecipeTest { final Sink> sink = TestSink.probe(system); Pair, TestSubscriber.Probe> pubSub = - source.via(new HoldWithInitial<>(0)).toMat(sink, Keep.both()).run(mat); + source.via(new HoldWithInitial<>(0)).toMat(sink, Keep.both()).run(system); TestPublisher.Probe pub = pubSub.first(); TestSubscriber.Probe sub = pubSub.second(); @@ -179,7 +175,7 @@ public class RecipeHold extends RecipeTest { final Sink> sink = TestSink.probe(system); Pair, TestSubscriber.Probe> pubSub = - source.via(new HoldWithWait<>()).toMat(sink, Keep.both()).run(mat); + source.via(new HoldWithWait<>()).toMat(sink, Keep.both()).run(system); TestPublisher.Probe pub = pubSub.first(); TestSubscriber.Probe sub = pubSub.second(); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java index 29ae4754d7..c601baf8e5 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java @@ -6,8 +6,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Flow; import akka.testkit.javadsl.TestKit; import akka.util.ByteString; @@ -19,19 +17,16 @@ import java.time.Duration; public class RecipeKeepAlive extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeKeepAlive"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } class Tick {} diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java index d79be96ce2..1130ad7285 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java @@ -8,9 +8,7 @@ import akka.NotUsed; import akka.actor.ActorSystem; import akka.event.Logging; import akka.event.LoggingAdapter; -import akka.stream.ActorMaterializer; import akka.stream.Attributes; -import akka.stream.Materializer; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.testkit.DebugFilter; @@ -26,7 +24,6 @@ import java.util.Arrays; public class RecipeLoggingElements extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { @@ -35,14 +32,12 @@ public class RecipeLoggingElements extends RecipeTest { "RecipeLoggingElements", ConfigFactory.parseString( "akka.loglevel=DEBUG\nakka.loggers = [akka.testkit.TestEventListener]")); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -95,7 +90,7 @@ public class RecipeLoggingElements extends RecipeTest { .intercept( new AbstractFunction0() { public Void apply() { - mySource.log("custom", adapter).runWith(Sink.ignore(), mat); + mySource.log("custom", adapter).runWith(Sink.ignore(), system); return null; } }, @@ -112,7 +107,7 @@ public class RecipeLoggingElements extends RecipeTest { Source.from(Arrays.asList(-1, 0, 1)) .map(x -> 1 / x) // throwing ArithmeticException: / by zero .log("error logging") - .runWith(Sink.ignore(), mat); + .runWith(Sink.ignore(), system); // #log-error } }; diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java index f6377330b9..2b4cfbc60b 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java @@ -23,19 +23,16 @@ import java.util.concurrent.TimeUnit; public class RecipeManualTrigger extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeManualTrigger"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } class Trigger {} @@ -75,7 +72,7 @@ public class RecipeManualTrigger extends RecipeTest { })); // #manually-triggered-stream - Pair, TestSubscriber.Probe> pubSub = g.run(mat); + Pair, TestSubscriber.Probe> pubSub = g.run(system); TestPublisher.Probe pub = pubSub.first(); TestSubscriber.Probe sub = pubSub.second(); @@ -130,7 +127,7 @@ public class RecipeManualTrigger extends RecipeTest { })); // #manually-triggered-stream-zipwith - Pair, TestSubscriber.Probe> pubSub = g.run(mat); + Pair, TestSubscriber.Probe> pubSub = g.run(system); TestPublisher.Probe pub = pubSub.first(); TestSubscriber.Probe sub = pubSub.second(); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java index 14eeeb2477..ea805c3503 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java @@ -7,8 +7,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; import akka.japi.Pair; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Flow; import akka.stream.javadsl.Keep; import akka.stream.javadsl.Sink; @@ -28,19 +26,16 @@ import java.util.concurrent.TimeUnit; public class RecipeMissedTicks extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeMissedTicks"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -70,7 +65,7 @@ public class RecipeMissedTicks extends RecipeTest { }); Pair, TestSubscriber.Probe> pubSub = - tickStream.via(realMissedTicks).toMat(sink, Keep.both()).run(mat); + tickStream.via(realMissedTicks).toMat(sink, Keep.both()).run(system); TestPublisher.Probe pub = pubSub.first(); TestSubscriber.Probe sub = pubSub.second(); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java index ea10f75a41..7890226235 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java @@ -8,8 +8,6 @@ import akka.NotUsed; import akka.actor.ActorSystem; import akka.japi.Function; import akka.japi.Pair; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.stream.javadsl.SubSource; @@ -29,19 +27,16 @@ import static junit.framework.TestCase.assertTrue; public class RecipeMultiGroupByTest extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeMultiGroupBy"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } static class Topic { @@ -142,7 +137,7 @@ public class RecipeMultiGroupByTest extends RecipeTest { "]"); }) .grouped(10) - .runWith(Sink.head(), mat); + .runWith(Sink.head(), system); List got = result.toCompletableFuture().get(3, TimeUnit.SECONDS); assertTrue(got.contains("1[1: a, 1: b, all: c, all: d, 1: e]")); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeParseLines.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeParseLines.java index 7251fe1a86..e57e013361 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeParseLines.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeParseLines.java @@ -6,8 +6,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Framing; import akka.stream.javadsl.FramingTruncation; import akka.stream.javadsl.Sink; @@ -24,19 +22,16 @@ import java.util.concurrent.TimeUnit; public class RecipeParseLines extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeParseLines"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -56,6 +51,6 @@ public class RecipeParseLines extends RecipeTest { .via(Framing.delimiter(ByteString.fromString("\r\n"), 100, FramingTruncation.ALLOW)) .map(b -> b.utf8String()); // #parse-lines - lines.limit(10).runWith(Sink.seq(), mat).toCompletableFuture().get(1, TimeUnit.SECONDS); + lines.limit(10).runWith(Sink.seq(), system).toCompletableFuture().get(1, TimeUnit.SECONDS); } } diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java index 2f7e253347..89eda2b1b9 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java @@ -9,8 +9,6 @@ import akka.actor.ActorSystem; import akka.japi.Pair; import akka.japi.function.Function; import akka.japi.function.Function2; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Flow; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; @@ -30,19 +28,16 @@ import java.util.stream.Collectors; public class RecipeReduceByKeyTest extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeReduceByKey"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -68,7 +63,7 @@ public class RecipeReduceByKeyTest extends RecipeTest { // #word-count final CompletionStage>> f = - counts.grouped(10).runWith(Sink.head(), mat); + counts.grouped(10).runWith(Sink.head(), system); final Set> result = f.toCompletableFuture().get(3, TimeUnit.SECONDS).stream().collect(Collectors.toSet()); final Set> expected = new HashSet<>(); @@ -117,7 +112,7 @@ public class RecipeReduceByKeyTest extends RecipeTest { // #reduce-by-key-general2 final CompletionStage>> f = - counts.grouped(10).runWith(Sink.head(), mat); + counts.grouped(10).runWith(Sink.head(), system); final Set> result = f.toCompletableFuture().get(3, TimeUnit.SECONDS).stream().collect(Collectors.toSet()); final Set> expected = new HashSet<>(); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSeq.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSeq.java index a782a8109c..dda981a802 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSeq.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSeq.java @@ -6,8 +6,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.testkit.javadsl.TestKit; @@ -22,19 +20,16 @@ import java.util.concurrent.TimeUnit; public class RecipeSeq extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeLoggingElements"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -44,7 +39,7 @@ public class RecipeSeq extends RecipeTest { final Source mySource = Source.from(Arrays.asList("1", "2", "3")); // #draining-to-list-unsafe // Dangerous: might produce a collection with 2 billion elements! - final CompletionStage> strings = mySource.runWith(Sink.seq(), mat); + final CompletionStage> strings = mySource.runWith(Sink.seq(), system); // #draining-to-list-unsafe strings.toCompletableFuture().get(3, TimeUnit.SECONDS); @@ -63,7 +58,7 @@ public class RecipeSeq extends RecipeTest { // OK. Future will fail with a `StreamLimitReachedException` // if the number of incoming elements is larger than max final CompletionStage> strings = - mySource.limit(MAX_ALLOWED_SIZE).runWith(Sink.seq(), mat); + mySource.limit(MAX_ALLOWED_SIZE).runWith(Sink.seq(), system); // #draining-to-list-safe strings.toCompletableFuture().get(1, TimeUnit.SECONDS); @@ -81,7 +76,7 @@ public class RecipeSeq extends RecipeTest { // OK. Collect up until max-th elements only, then cancel upstream final CompletionStage> strings = - mySource.take(MAX_ALLOWED_SIZE).runWith(Sink.seq(), mat); + mySource.take(MAX_ALLOWED_SIZE).runWith(Sink.seq(), system); // #draining-to-list-safe strings.toCompletableFuture().get(1, TimeUnit.SECONDS); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java index 9808cdaf17..53dec7cd93 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java @@ -7,8 +7,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; import akka.japi.Pair; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Flow; import akka.stream.testkit.TestPublisher; import akka.stream.testkit.TestSubscriber; @@ -26,19 +24,16 @@ import java.util.concurrent.TimeUnit; public class RecipeSimpleDrop extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeSimpleDrop"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -63,7 +58,7 @@ public class RecipeSimpleDrop extends RecipeTest { TestSource.probe(system) .via(realDroppyStream) .toMat(TestSink.probe(system), (pub, sub) -> new Pair<>(pub, sub)) - .run(mat); + .run(system); final TestPublisher.Probe pub = pubSub.first(); final TestSubscriber.Probe sub = pubSub.second(); diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSourceFromFunction.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSourceFromFunction.java index 295e799452..8a44fa811a 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSourceFromFunction.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeSourceFromFunction.java @@ -6,8 +6,6 @@ package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.testkit.javadsl.TestKit; @@ -23,7 +21,6 @@ import java.util.concurrent.TimeUnit; public class RecipeSourceFromFunction extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { @@ -32,14 +29,12 @@ public class RecipeSourceFromFunction extends RecipeTest { "RecipeSourceFromFunction", ConfigFactory.parseString( "akka.loglevel=DEBUG\nakka.loggers = [akka.testkit.TestEventListener]")); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } @Test @@ -56,7 +51,11 @@ public class RecipeSourceFromFunction extends RecipeTest { // #source-from-function final List result = - source.take(2).runWith(Sink.seq(), mat).toCompletableFuture().get(3, TimeUnit.SECONDS); + source + .take(2) + .runWith(Sink.seq(), system) + .toCompletableFuture() + .get(3, TimeUnit.SECONDS); Assert.assertEquals(2, result.size()); } diff --git a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java index d4d76413b1..23802d9827 100644 --- a/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java +++ b/akka-docs/src/test/java/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java @@ -23,19 +23,16 @@ import static org.junit.Assert.assertTrue; public class RecipeWorkerPool extends RecipeTest { static ActorSystem system; - static Materializer mat; @BeforeClass public static void setup() { system = ActorSystem.create("RecipeWorkerPool"); - mat = ActorMaterializer.create(system); } @AfterClass public static void tearDown() { TestKit.shutdownActorSystem(system); system = null; - mat = null; } // #worker-pool @@ -75,7 +72,7 @@ public class RecipeWorkerPool extends RecipeTest { FiniteDuration timeout = FiniteDuration.create(200, TimeUnit.MILLISECONDS); CompletionStage> future = - processedJobs.map(m -> m.msg).limit(10).runWith(Sink.seq(), mat); + processedJobs.map(m -> m.msg).limit(10).runWith(Sink.seq(), system); List got = future.toCompletableFuture().get(1, TimeUnit.SECONDS); assertTrue(got.contains("1 done")); assertTrue(got.contains("2 done")); diff --git a/akka-docs/src/test/java/jdocs/stream/operators/SinkDocExamples.java b/akka-docs/src/test/java/jdocs/stream/operators/SinkDocExamples.java index 44c6d1c73f..94f1e665f0 100644 --- a/akka-docs/src/test/java/jdocs/stream/operators/SinkDocExamples.java +++ b/akka-docs/src/test/java/jdocs/stream/operators/SinkDocExamples.java @@ -7,8 +7,6 @@ package jdocs.stream.operators; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; // #takeLast-operator-example @@ -22,13 +20,12 @@ import java.util.concurrent.TimeoutException; public class SinkDocExamples { private static final ActorSystem system = ActorSystem.create("SourceFromExample"); - private static final Materializer materializer = ActorMaterializer.create(system); static void reduceExample() throws InterruptedException, ExecutionException, TimeoutException { // #reduce-operator-example Source ints = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - CompletionStage sum = ints.runWith(Sink.reduce((a, b) -> a + b), materializer); + CompletionStage sum = ints.runWith(Sink.reduce((a, b) -> a + b), system); sum.thenAccept(System.out::println); // 55 // #reduce-operator-example @@ -48,7 +45,7 @@ public class SinkDocExamples { Source studentSource = Source.from(sortedStudents); - CompletionStage> topThree = studentSource.runWith(Sink.takeLast(3), materializer); + CompletionStage> topThree = studentSource.runWith(Sink.takeLast(3), system); topThree.thenAccept( result -> { @@ -70,7 +67,7 @@ public class SinkDocExamples { static void lastExample() throws InterruptedException, ExecutionException, TimeoutException { // #last-operator-example Source source = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - CompletionStage result = source.runWith(Sink.last(), materializer); + CompletionStage result = source.runWith(Sink.last(), system); result.thenAccept(System.out::println); // 10 // #last-operator-example @@ -80,7 +77,7 @@ public class SinkDocExamples { throws InterruptedException, ExecutionException, TimeoutException { // #lastOption-operator-example Source source = Source.empty(); - CompletionStage> result = source.runWith(Sink.lastOption(), materializer); + CompletionStage> result = source.runWith(Sink.lastOption(), system); result.thenAccept(System.out::println); // Optional.empty // #lastOption-operator-example diff --git a/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java b/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java index 3ee9a6e92e..7f21c4122e 100644 --- a/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java +++ b/akka-docs/src/test/java/jdocs/stream/operators/SourceDocExamples.java @@ -10,8 +10,6 @@ import akka.NotUsed; import akka.actor.ActorSystem; import akka.actor.testkit.typed.javadsl.ManualTime; import akka.actor.testkit.typed.javadsl.TestKitJunitResource; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import akka.stream.javadsl.Source; // #range-imports @@ -35,23 +33,21 @@ public class SourceDocExamples { public static void fromExample() { // #source-from-example final ActorSystem system = ActorSystem.create("SourceFromExample"); - final Materializer materializer = ActorMaterializer.create(system); Source ints = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5)); - ints.runForeach(System.out::println, materializer); + ints.runForeach(System.out::println, system); String text = "Perfection is finally attained not when there is no longer more to add," + "but when there is no longer anything to take away."; Source words = Source.from(Arrays.asList(text.split("\\s"))); - words.runForeach(System.out::println, materializer); + words.runForeach(System.out::println, system); // #source-from-example } static void rangeExample() { final ActorSystem system = ActorSystem.create("Source"); - final Materializer materializer = ActorMaterializer.create(system); // #range @@ -69,7 +65,7 @@ public class SourceDocExamples { // #range // #run-range - source.runForeach(i -> System.out.println(i), materializer); + source.runForeach(i -> System.out.println(i), system); // #run-range } @@ -77,12 +73,11 @@ public class SourceDocExamples { // #actor-ref final ActorSystem system = ActorSystem.create(); - final Materializer materializer = ActorMaterializer.create(system); int bufferSize = 100; Source source = Source.actorRef(bufferSize, OverflowStrategy.dropHead()); - ActorRef actorRef = source.to(Sink.foreach(System.out::println)).run(materializer); + ActorRef actorRef = source.to(Sink.foreach(System.out::println)).run(system); actorRef.tell("hello", ActorRef.noSender()); actorRef.tell("hello", ActorRef.noSender()); @@ -96,11 +91,10 @@ public class SourceDocExamples { // #actor-ref-with-ack final ActorSystem system = ActorSystem.create(); - final Materializer materializer = ActorMaterializer.create(system); Source source = Source.actorRefWithAck("ack"); - ActorRef actorRef = source.to(Sink.foreach(System.out::println)).run(materializer); + ActorRef actorRef = source.to(Sink.foreach(System.out::println)).run(system); probe.send(actorRef, "hello"); probe.expectMsg("ack"); probe.send(actorRef, "hello"); diff --git a/akka-docs/src/test/scala/docs/persistence/query/LeveldbPersistenceQueryDocSpec.scala b/akka-docs/src/test/scala/docs/persistence/query/LeveldbPersistenceQueryDocSpec.scala index c373cf523d..b493733f05 100644 --- a/akka-docs/src/test/scala/docs/persistence/query/LeveldbPersistenceQueryDocSpec.scala +++ b/akka-docs/src/test/scala/docs/persistence/query/LeveldbPersistenceQueryDocSpec.scala @@ -5,16 +5,10 @@ package docs.persistence.query import akka.NotUsed -import akka.persistence.journal.{ EventAdapter, EventSeq } import akka.testkit.AkkaSpec import akka.persistence.query.{ EventEnvelope, PersistenceQuery, Sequence } -import akka.persistence.query.scaladsl._ import akka.persistence.query.journal.leveldb.scaladsl.LeveldbReadJournal -import akka.persistence.journal.Tagged import akka.stream.scaladsl.Source -import akka.stream.ActorMaterializer - -import scala.annotation.tailrec object LeveldbPersistenceQueryDocSpec { //#tagger @@ -54,7 +48,6 @@ class LeveldbPersistenceQueryDocSpec(config: String) extends AkkaSpec(config) { "demonstrate EventsByPersistenceId" in { //#EventsByPersistenceId - implicit val mat = ActorMaterializer()(system) val queries = PersistenceQuery(system).readJournalFor[LeveldbReadJournal](LeveldbReadJournal.Identifier) val src: Source[EventEnvelope, NotUsed] = @@ -66,7 +59,6 @@ class LeveldbPersistenceQueryDocSpec(config: String) extends AkkaSpec(config) { "demonstrate AllPersistenceIds" in { //#AllPersistenceIds - implicit val mat = ActorMaterializer()(system) val queries = PersistenceQuery(system).readJournalFor[LeveldbReadJournal](LeveldbReadJournal.Identifier) val src: Source[String, NotUsed] = queries.persistenceIds() @@ -75,7 +67,6 @@ class LeveldbPersistenceQueryDocSpec(config: String) extends AkkaSpec(config) { "demonstrate EventsByTag" in { //#EventsByTag - implicit val mat = ActorMaterializer()(system) val queries = PersistenceQuery(system).readJournalFor[LeveldbReadJournal](LeveldbReadJournal.Identifier) val src: Source[EventEnvelope, NotUsed] = diff --git a/akka-docs/src/test/scala/docs/persistence/query/PersistenceQueryDocSpec.scala b/akka-docs/src/test/scala/docs/persistence/query/PersistenceQueryDocSpec.scala index c635d73859..78f8ad6e75 100644 --- a/akka-docs/src/test/scala/docs/persistence/query/PersistenceQueryDocSpec.scala +++ b/akka-docs/src/test/scala/docs/persistence/query/PersistenceQueryDocSpec.scala @@ -6,14 +6,11 @@ package docs.persistence.query import akka.NotUsed import akka.actor._ -import akka.persistence.{ PersistentActor, Recovery } import akka.persistence.query._ -import akka.stream.{ ActorMaterializer, FlowShape } import akka.stream.scaladsl.{ Flow, Sink, Source } import akka.stream.javadsl import akka.testkit.AkkaSpec import akka.util.Timeout -import docs.persistence.query.PersistenceQueryDocSpec.TheOneWhoWritesToQueryJournal import org.reactivestreams.Subscriber import scala.collection.immutable @@ -151,7 +148,6 @@ object PersistenceQueryDocSpec { //#projection-into-different-store-rs implicit val system = ActorSystem() - implicit val mat = ActorMaterializer() val readJournal = PersistenceQuery(system).readJournalFor[MyScaladslReadJournal](JournalId) @@ -202,8 +198,6 @@ class PersistenceQueryDocSpec(s: String) extends AkkaSpec(s) { """) } - implicit val mat = ActorMaterializer() - class BasicUsage { //#basic-usage // obtain read journal by plugin id @@ -215,7 +209,6 @@ class PersistenceQueryDocSpec(s: String) extends AkkaSpec(s) { readJournal.eventsByPersistenceId("user-1337", 0, Long.MaxValue) // materialize stream, consuming events - implicit val mat = ActorMaterializer() source.runForeach { event => println("Event: " + event) } diff --git a/akka-docs/src/test/scala/docs/stream/BidiFlowDocSpec.scala b/akka-docs/src/test/scala/docs/stream/BidiFlowDocSpec.scala index 62798d7a9b..486f07572b 100644 --- a/akka-docs/src/test/scala/docs/stream/BidiFlowDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/BidiFlowDocSpec.scala @@ -148,8 +148,6 @@ object BidiFlowDocSpec { class BidiFlowDocSpec extends AkkaSpec { import BidiFlowDocSpec._ - implicit val materializer = ActorMaterializer() - "A BidiFlow" must { "compose" in { diff --git a/akka-docs/src/test/scala/docs/stream/CompositionDocSpec.scala b/akka-docs/src/test/scala/docs/stream/CompositionDocSpec.scala index eecd7dcd4d..02cf97e5c6 100644 --- a/akka-docs/src/test/scala/docs/stream/CompositionDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/CompositionDocSpec.scala @@ -16,7 +16,6 @@ import scala.concurrent.{ Future, Promise } class CompositionDocSpec extends AkkaSpec { implicit val ec = system.dispatcher - implicit val materializer = ActorMaterializer() "nonnested flow" in { //#non-nested-flow diff --git a/akka-docs/src/test/scala/docs/stream/FlowDocSpec.scala b/akka-docs/src/test/scala/docs/stream/FlowDocSpec.scala index f6e8af7b7c..fc7e9c7923 100644 --- a/akka-docs/src/test/scala/docs/stream/FlowDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/FlowDocSpec.scala @@ -4,9 +4,11 @@ package docs.stream -import akka.{ Done, NotUsed } +import akka.NotUsed import akka.actor.{ Actor, ActorSystem, Cancellable } -import akka.stream.{ ActorMaterializer, ClosedShape, FlowShape, Materializer, OverflowStrategy } +import akka.stream.ActorMaterializer +import akka.stream.Materializer +import akka.stream.{ ClosedShape, FlowShape, OverflowStrategy } import akka.stream.scaladsl._ import akka.testkit.AkkaSpec import docs.CompileOnlySpec @@ -18,12 +20,6 @@ class FlowDocSpec extends AkkaSpec with CompileOnlySpec { implicit val ec = system.dispatcher - //#imports - import akka.stream.ActorMaterializer - //#imports - - implicit val materializer = ActorMaterializer() - "source is immutable" in { //#source-immutable val source = Source(1 to 10) @@ -247,14 +243,6 @@ class FlowDocSpec extends AkkaSpec with CompileOnlySpec { object FlowDocSpec { - { - //#materializer-from-system - implicit val system = ActorSystem("ExampleSystem") - - implicit val mat = ActorMaterializer() // created from `system` - //#materializer-from-system - } - //#materializer-from-actor-context final class RunWithMyself extends Actor { implicit val mat = ActorMaterializer() diff --git a/akka-docs/src/test/scala/docs/stream/FlowErrorDocSpec.scala b/akka-docs/src/test/scala/docs/stream/FlowErrorDocSpec.scala index 5b35c48717..0da418c593 100644 --- a/akka-docs/src/test/scala/docs/stream/FlowErrorDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/FlowErrorDocSpec.scala @@ -18,7 +18,6 @@ class FlowErrorDocSpec extends AkkaSpec { "demonstrate fail stream" in { //#stop - implicit val materializer = ActorMaterializer() val source = Source(0 to 5).map(100 / _) val result = source.runWith(Sink.fold(0)(_ + _)) // division by zero will fail the stream and the @@ -48,7 +47,6 @@ class FlowErrorDocSpec extends AkkaSpec { "demonstrate resume section" in { //#resume-section - implicit val materializer = ActorMaterializer() val decider: Supervision.Decider = { case _: ArithmeticException => Supervision.Resume case _ => Supervision.Stop @@ -69,7 +67,6 @@ class FlowErrorDocSpec extends AkkaSpec { "demonstrate restart section" in { //#restart-section - implicit val materializer = ActorMaterializer() val decider: Supervision.Decider = { case _: IllegalArgumentException => Supervision.Restart case _ => Supervision.Stop @@ -91,7 +88,6 @@ class FlowErrorDocSpec extends AkkaSpec { } "demonstrate recover" in { - implicit val materializer = ActorMaterializer() //#recover Source(0 to 6) .map(n => @@ -117,7 +113,6 @@ stream truncated } "demonstrate recoverWithRetries" in { - implicit val materializer = ActorMaterializer() //#recoverWithRetries val planB = Source(List("five", "six", "seven", "eight")) diff --git a/akka-docs/src/test/scala/docs/stream/FlowStreamRefsDocSpec.scala b/akka-docs/src/test/scala/docs/stream/FlowStreamRefsDocSpec.scala index 8bc2709e4d..2894a8148b 100644 --- a/akka-docs/src/test/scala/docs/stream/FlowStreamRefsDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/FlowStreamRefsDocSpec.scala @@ -10,7 +10,6 @@ import akka.stream.ActorMaterializer import akka.stream.scaladsl._ import akka.testkit.AkkaSpec import docs.CompileOnlySpec -import scala.concurrent.Future class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec { @@ -91,7 +90,6 @@ class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec { //#offer-sink - implicit val mat = ActorMaterializer() def localMetrics(): Source[String, NotUsed] = Source.single("") //#offer-sink-use @@ -106,8 +104,6 @@ class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec { } "show how to configure timeouts with attrs" in compileOnlySpec { - - implicit val mat: ActorMaterializer = null //#attr-sub-timeout // configure the timeout for source import scala.concurrent.duration._ diff --git a/akka-docs/src/test/scala/docs/stream/GraphCyclesSpec.scala b/akka-docs/src/test/scala/docs/stream/GraphCyclesSpec.scala index 9ad76240a1..9ada92a825 100644 --- a/akka-docs/src/test/scala/docs/stream/GraphCyclesSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/GraphCyclesSpec.scala @@ -10,8 +10,6 @@ import akka.testkit.AkkaSpec class GraphCyclesSpec extends AkkaSpec { - implicit val materializer = ActorMaterializer() - "Cycle demonstration" must { val source = Source.fromIterator(() => Iterator.from(0)) diff --git a/akka-docs/src/test/scala/docs/stream/GraphDSLDocSpec.scala b/akka-docs/src/test/scala/docs/stream/GraphDSLDocSpec.scala index d873b75e74..74666e0caa 100644 --- a/akka-docs/src/test/scala/docs/stream/GraphDSLDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/GraphDSLDocSpec.scala @@ -17,8 +17,6 @@ class GraphDSLDocSpec extends AkkaSpec { implicit val ec = system.dispatcher - implicit val materializer = ActorMaterializer() - "build simple graph" in { //format: OFF //#simple-graph-dsl diff --git a/akka-docs/src/test/scala/docs/stream/GraphStageDocSpec.scala b/akka-docs/src/test/scala/docs/stream/GraphStageDocSpec.scala index f7b8f35e1a..76af5f0a8e 100644 --- a/akka-docs/src/test/scala/docs/stream/GraphStageDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/GraphStageDocSpec.scala @@ -18,8 +18,6 @@ import scala.collection.immutable.Iterable class GraphStageDocSpec extends AkkaSpec { - implicit val materializer = ActorMaterializer() - "Demonstrate creation of GraphStage boilerplate" in { //#boilerplate-example import akka.stream.SourceShape diff --git a/akka-docs/src/test/scala/docs/stream/GraphStageLoggingDocSpec.scala b/akka-docs/src/test/scala/docs/stream/GraphStageLoggingDocSpec.scala index 1f68faf43c..ca1777f3ea 100644 --- a/akka-docs/src/test/scala/docs/stream/GraphStageLoggingDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/GraphStageLoggingDocSpec.scala @@ -12,7 +12,6 @@ import akka.testkit.{ AkkaSpec, EventFilter } class GraphStageLoggingDocSpec extends AkkaSpec("akka.loglevel = DEBUG") { - implicit val materializer = ActorMaterializer() implicit val ec = system.dispatcher //#operator-with-logging diff --git a/akka-docs/src/test/scala/docs/stream/HubsDocSpec.scala b/akka-docs/src/test/scala/docs/stream/HubsDocSpec.scala index 51f86cb06f..b6b03192b9 100644 --- a/akka-docs/src/test/scala/docs/stream/HubsDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/HubsDocSpec.scala @@ -5,7 +5,7 @@ package docs.stream import akka.NotUsed -import akka.stream.{ ActorMaterializer, KillSwitches, UniqueKillSwitch } +import akka.stream.{ KillSwitches, UniqueKillSwitch } import akka.stream.scaladsl._ import akka.testkit.AkkaSpec import docs.CompileOnlySpec @@ -14,7 +14,6 @@ import scala.concurrent.duration._ import akka.stream.ThrottleMode class HubsDocSpec extends AkkaSpec with CompileOnlySpec { - implicit val materializer = ActorMaterializer() "Hubs" must { diff --git a/akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala b/akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala index 7c38e8f156..53f96397f4 100644 --- a/akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/IntegrationDocSpec.scala @@ -13,7 +13,7 @@ import akka.stream._ import scala.concurrent.Future import akka.testkit.TestProbe -import akka.actor.{ Actor, ActorLogging, ActorRef, Props, Status } +import akka.actor.{ Actor, ActorLogging, ActorRef, Props } import com.typesafe.config.ConfigFactory import akka.util.Timeout @@ -21,9 +21,6 @@ import scala.concurrent.ExecutionContext import java.util.concurrent.atomic.AtomicInteger import akka.stream.scaladsl.Flow -import akka.Done -import akka.actor.Status.Status -import akka.stream.QueueOfferResult.{ Dropped, Enqueued } object IntegrationDocSpec { import TwitterStreamQuickstartDocSpec._ @@ -137,7 +134,6 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) { import TwitterStreamQuickstartDocSpec._ import IntegrationDocSpec._ - implicit val materializer = ActorMaterializer() val ref: ActorRef = system.actorOf(Props[Translator]) "ask" in { diff --git a/akka-docs/src/test/scala/docs/stream/KillSwitchDocSpec.scala b/akka-docs/src/test/scala/docs/stream/KillSwitchDocSpec.scala index 14a22511c4..546c0a29a0 100644 --- a/akka-docs/src/test/scala/docs/stream/KillSwitchDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/KillSwitchDocSpec.scala @@ -5,7 +5,7 @@ package docs.stream import akka.stream.scaladsl._ -import akka.stream.{ ActorMaterializer, DelayOverflowStrategy, KillSwitches } +import akka.stream.{ DelayOverflowStrategy, KillSwitches } import akka.testkit.AkkaSpec import docs.CompileOnlySpec @@ -14,8 +14,6 @@ import scala.concurrent.duration._ class KillSwitchDocSpec extends AkkaSpec with CompileOnlySpec { - implicit val materializer = ActorMaterializer() - "Unique kill switch" must { "control graph completion with shutdown" in compileOnlySpec { diff --git a/akka-docs/src/test/scala/docs/stream/QuickStartDocSpec.scala b/akka-docs/src/test/scala/docs/stream/QuickStartDocSpec.scala index 7227f28e34..a8654941fd 100644 --- a/akka-docs/src/test/scala/docs/stream/QuickStartDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/QuickStartDocSpec.scala @@ -23,6 +23,7 @@ import org.scalatest.concurrent._ //#main-app object Main extends App { + implicit val system = ActorSystem("QuickStart") // Code here } //#main-app @@ -33,17 +34,14 @@ class QuickStartDocSpec extends WordSpec with BeforeAndAfterAll with ScalaFuture def println(any: Any) = () // silence printing stuff "demonstrate Source" in { - //#create-materializer implicit val system = ActorSystem("QuickStart") - implicit val materializer = ActorMaterializer() - //#create-materializer //#create-source val source: Source[Int, NotUsed] = Source(1 to 100) //#create-source //#run-source - source.runForeach(i => println(i))(materializer) + source.runForeach(i => println(i)) //#run-source //#transform-source @@ -68,7 +66,7 @@ class QuickStartDocSpec extends WordSpec with BeforeAndAfterAll with ScalaFuture //#add-streams //#run-source-and-terminate - val done: Future[Done] = source.runForeach(i => println(i))(materializer) + val done: Future[Done] = source.runForeach(i => println(i)) implicit val ec = system.dispatcher done.onComplete(_ => system.terminate()) diff --git a/akka-docs/src/test/scala/docs/stream/RateTransformationDocSpec.scala b/akka-docs/src/test/scala/docs/stream/RateTransformationDocSpec.scala index 540246259e..17e6bc4491 100644 --- a/akka-docs/src/test/scala/docs/stream/RateTransformationDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/RateTransformationDocSpec.scala @@ -4,7 +4,6 @@ package docs.stream -import akka.stream._ import akka.stream.scaladsl._ import akka.stream.testkit.scaladsl._ @@ -18,8 +17,6 @@ import scala.concurrent.Await class RateTransformationDocSpec extends AkkaSpec { - implicit val materializer = ActorMaterializer() - "conflate should summarize" in { //#conflate-summarize val statsFlow = Flow[Double].conflateWithSeed(immutable.Seq(_))(_ :+ _).map { s => diff --git a/akka-docs/src/test/scala/docs/stream/ReactiveStreamsDocSpec.scala b/akka-docs/src/test/scala/docs/stream/ReactiveStreamsDocSpec.scala index 9d00d770fc..f7a3b3df38 100644 --- a/akka-docs/src/test/scala/docs/stream/ReactiveStreamsDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/ReactiveStreamsDocSpec.scala @@ -5,7 +5,6 @@ package docs.stream import akka.NotUsed -import akka.stream.ActorMaterializer import akka.stream.scaladsl.{ Flow, Sink, Source } import akka.stream.testkit._ import org.reactivestreams.Processor @@ -14,8 +13,6 @@ import akka.testkit.AkkaSpec class ReactiveStreamsDocSpec extends AkkaSpec { import TwitterStreamQuickstartDocSpec._ - implicit val materializer = ActorMaterializer() - //#imports import org.reactivestreams.Publisher import org.reactivestreams.Subscriber diff --git a/akka-docs/src/test/scala/docs/stream/RestartDocSpec.scala b/akka-docs/src/test/scala/docs/stream/RestartDocSpec.scala index ec2e1d1724..f6b8483004 100644 --- a/akka-docs/src/test/scala/docs/stream/RestartDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/RestartDocSpec.scala @@ -5,7 +5,7 @@ package docs.stream import akka.NotUsed -import akka.stream.{ ActorMaterializer, KillSwitches } +import akka.stream.KillSwitches import akka.stream.scaladsl._ import akka.testkit.AkkaSpec import docs.CompileOnlySpec @@ -14,7 +14,6 @@ import scala.concurrent.duration._ import scala.concurrent._ class RestartDocSpec extends AkkaSpec with CompileOnlySpec { - implicit val materializer = ActorMaterializer() import system.dispatcher // Mock akka-http interfaces diff --git a/akka-docs/src/test/scala/docs/stream/StreamBuffersRateSpec.scala b/akka-docs/src/test/scala/docs/stream/StreamBuffersRateSpec.scala index e9bc6c60be..a7a4b5e61a 100644 --- a/akka-docs/src/test/scala/docs/stream/StreamBuffersRateSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/StreamBuffersRateSpec.scala @@ -10,7 +10,6 @@ import akka.stream.scaladsl._ import akka.testkit.AkkaSpec class StreamBuffersRateSpec extends AkkaSpec { - implicit val materializer = ActorMaterializer() "Demonstrate pipelining" in { def println(s: Any) = () diff --git a/akka-docs/src/test/scala/docs/stream/StreamPartialGraphDSLDocSpec.scala b/akka-docs/src/test/scala/docs/stream/StreamPartialGraphDSLDocSpec.scala index 9c5edf753e..2d5a6bd3bc 100644 --- a/akka-docs/src/test/scala/docs/stream/StreamPartialGraphDSLDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/StreamPartialGraphDSLDocSpec.scala @@ -16,8 +16,6 @@ class StreamPartialGraphDSLDocSpec extends AkkaSpec { implicit val ec = system.dispatcher - implicit val materializer = ActorMaterializer() - "build with open ports" in { //#simple-partial-graph-dsl val pickMaxOfThree = GraphDSL.create() { implicit b => diff --git a/akka-docs/src/test/scala/docs/stream/StreamTestKitDocSpec.scala b/akka-docs/src/test/scala/docs/stream/StreamTestKitDocSpec.scala index 7bf420b7b3..99d624d275 100644 --- a/akka-docs/src/test/scala/docs/stream/StreamTestKitDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/StreamTestKitDocSpec.scala @@ -6,7 +6,6 @@ package docs.stream import akka.stream._ import akka.stream.scaladsl._ -import akka.stream.testkit._ import akka.stream.testkit.scaladsl._ import scala.util._ import scala.concurrent.duration._ @@ -16,8 +15,6 @@ import akka.pattern class StreamTestKitDocSpec extends AkkaSpec { - implicit val materializer = ActorMaterializer() - "strict collection" in { //#strict-collection val sinkUnderTest = Flow[Int].map(_ * 2).toMat(Sink.fold(0)(_ + _))(Keep.right) diff --git a/akka-docs/src/test/scala/docs/stream/SubstreamDocSpec.scala b/akka-docs/src/test/scala/docs/stream/SubstreamDocSpec.scala index cc534414a1..eba54cd2bb 100644 --- a/akka-docs/src/test/scala/docs/stream/SubstreamDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/SubstreamDocSpec.scala @@ -5,11 +5,10 @@ package docs.stream import akka.stream.scaladsl.{ Sink, Source } -import akka.stream.{ ActorMaterializer, SubstreamCancelStrategy } +import akka.stream.{ SubstreamCancelStrategy } import akka.testkit.AkkaSpec class SubstreamDocSpec extends AkkaSpec { - implicit val materializer = ActorMaterializer() "generate substreams by groupBy" in { //#groupBy1 diff --git a/akka-docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala b/akka-docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala index 8a68f49ff7..e06e2c0621 100644 --- a/akka-docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala @@ -8,7 +8,7 @@ package docs.stream import akka.{ Done, NotUsed } import akka.actor.ActorSystem -import akka.stream.{ ActorMaterializer, ClosedShape, OverflowStrategy } +import akka.stream.{ ClosedShape, OverflowStrategy } import akka.stream.scaladsl._ import scala.concurrent.Await import scala.concurrent.Future @@ -79,17 +79,14 @@ class TwitterStreamQuickstartDocSpec extends AkkaSpec { trait Example1 { //#fiddle_code //#first-sample - //#materializer-setup + //#system-setup implicit val system = ActorSystem("reactive-tweets") - implicit val materializer = ActorMaterializer() - //#materializer-setup + //#system-setup //#first-sample //#fiddle_code } - implicit val materializer = ActorMaterializer() - "filter and map" in { //#first-sample diff --git a/akka-docs/src/test/scala/docs/stream/cookbook/RecipeSpec.scala b/akka-docs/src/test/scala/docs/stream/cookbook/RecipeSpec.scala index 62656347a4..140fb328bf 100644 --- a/akka-docs/src/test/scala/docs/stream/cookbook/RecipeSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/cookbook/RecipeSpec.scala @@ -4,12 +4,10 @@ package docs.stream.cookbook -import akka.stream.ActorMaterializer import akka.testkit.AkkaSpec trait RecipeSpec extends AkkaSpec { - implicit val m = ActorMaterializer() type Message = String } diff --git a/akka-docs/src/test/scala/docs/stream/io/StreamFileDocSpec.scala b/akka-docs/src/test/scala/docs/stream/io/StreamFileDocSpec.scala index 29b73fd82e..54114aefb5 100644 --- a/akka-docs/src/test/scala/docs/stream/io/StreamFileDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/io/StreamFileDocSpec.scala @@ -17,7 +17,6 @@ import scala.concurrent.Future class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) { implicit val ec = system.dispatcher - implicit val materializer = ActorMaterializer() // silence sysout def println(s: String) = () diff --git a/akka-docs/src/test/scala/docs/stream/io/StreamTcpDocSpec.scala b/akka-docs/src/test/scala/docs/stream/io/StreamTcpDocSpec.scala index c8efe20895..5acad115a5 100644 --- a/akka-docs/src/test/scala/docs/stream/io/StreamTcpDocSpec.scala +++ b/akka-docs/src/test/scala/docs/stream/io/StreamTcpDocSpec.scala @@ -6,7 +6,6 @@ package docs.stream.io import java.util.concurrent.atomic.AtomicReference -import akka.stream._ import akka.stream.scaladsl.Tcp._ import akka.stream.scaladsl._ import akka.testkit.AkkaSpec @@ -19,7 +18,6 @@ import akka.testkit.SocketUtil class StreamTcpDocSpec extends AkkaSpec { implicit val ec = system.dispatcher - implicit val materializer = ActorMaterializer() // silence sysout def println(s: String) = () diff --git a/akka-docs/src/test/scala/docs/stream/operators/SourceOperators.scala b/akka-docs/src/test/scala/docs/stream/operators/SourceOperators.scala index 86d511686e..484b786f9d 100644 --- a/akka-docs/src/test/scala/docs/stream/operators/SourceOperators.scala +++ b/akka-docs/src/test/scala/docs/stream/operators/SourceOperators.scala @@ -5,7 +5,6 @@ package docs.stream.operators import akka.actor.ActorSystem -import akka.stream.ActorMaterializer import akka.testkit.TestProbe object SourceOperators { @@ -21,7 +20,6 @@ object SourceOperators { import scala.concurrent.Future implicit val system: ActorSystem = ActorSystem() - implicit val materializer: ActorMaterializer = ActorMaterializer() val source: Source[Int, NotUsed] = Source.fromFuture(Future.successful(10)) val sink: Sink[Int, Future[Done]] = Sink.foreach((i: Int) => println(i)) @@ -40,7 +38,6 @@ object SourceOperators { import akka.stream.scaladsl._ implicit val system: ActorSystem = ActorSystem() - implicit val materializer: ActorMaterializer = ActorMaterializer() val bufferSize = 100 val source: Source[Any, ActorRef] = Source.actorRef[Any](bufferSize, OverflowStrategy.dropHead) @@ -63,7 +60,6 @@ object SourceOperators { import akka.stream.scaladsl._ implicit val system: ActorSystem = ActorSystem() - implicit val materializer: ActorMaterializer = ActorMaterializer() val probe = TestProbe() val source: Source[Any, ActorRef] = Source.actorRefWithAck[Any]("ack") diff --git a/akka-docs/src/test/scala/docs/stream/operators/sourceorflow/Scan.scala b/akka-docs/src/test/scala/docs/stream/operators/sourceorflow/Scan.scala index 34dc336259..065583e656 100644 --- a/akka-docs/src/test/scala/docs/stream/operators/sourceorflow/Scan.scala +++ b/akka-docs/src/test/scala/docs/stream/operators/sourceorflow/Scan.scala @@ -11,7 +11,6 @@ object Scan { import akka.stream.ActorMaterializer implicit val system: ActorSystem = ActorSystem() - implicit val materializer: ActorMaterializer = ActorMaterializer() //#scan val source = Source(1 to 5) diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala index c369e33fa5..f465f033f8 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala @@ -17,6 +17,8 @@ import scala.annotation.tailrec import scala.concurrent.duration._ import java.util.concurrent.ThreadLocalRandom +import akka.stream.SystemMaterializer + trait ScriptedTest extends Matchers { class ScriptException(msg: String) extends RuntimeException(msg) @@ -228,6 +230,10 @@ trait ScriptedTest extends Matchers { } + def runScript[In, Out, M](script: Script[In, Out])(op: Flow[In, In, NotUsed] => Flow[In, Out, M])( + implicit system: ActorSystem): Unit = + runScript(script, SystemMaterializer(system).materializer.settings)(op)(system) + def runScript[In, Out, M]( script: Script[In, Out], settings: ActorMaterializerSettings, diff --git a/akka-stream-tests/src/test/java/akka/stream/StreamTest.java b/akka-stream-tests/src/test/java/akka/stream/StreamTest.java index 9cee0fdaeb..62194e842a 100644 --- a/akka-stream-tests/src/test/java/akka/stream/StreamTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/StreamTest.java @@ -4,33 +4,14 @@ package akka.stream; -import akka.stream.testkit.javadsl.StreamTestKit; -import org.junit.After; -import org.junit.Before; -import org.scalatest.junit.JUnitSuite; - import akka.actor.ActorSystem; import akka.testkit.AkkaJUnitActorSystemResource; +import org.scalatest.junit.JUnitSuite; public abstract class StreamTest extends JUnitSuite { protected final ActorSystem system; - private final ActorMaterializerSettings settings; - - protected ActorMaterializer materializer; protected StreamTest(AkkaJUnitActorSystemResource actorSystemResource) { system = actorSystemResource.getSystem(); - settings = ActorMaterializerSettings.create(system); - } - - @Before - public void setUp() { - materializer = ActorMaterializer.create(settings, system); - } - - @After - public void tearDown() { - StreamTestKit.assertAllStagesStopped(materializer); - materializer.shutdown(); } } diff --git a/akka-stream-tests/src/test/java/akka/stream/io/InputStreamSinkTest.java b/akka-stream-tests/src/test/java/akka/stream/io/InputStreamSinkTest.java index 3f0de81105..eae19d4756 100644 --- a/akka-stream-tests/src/test/java/akka/stream/io/InputStreamSinkTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/io/InputStreamSinkTest.java @@ -41,7 +41,7 @@ public class InputStreamSinkTest extends StreamTest { final Sink sink = StreamConverters.asInputStream(timeout); final List list = Collections.singletonList(ByteString.fromString("a")); - final InputStream stream = Source.from(list).runWith(sink, materializer); + final InputStream stream = Source.from(list).runWith(sink, system); byte[] a = new byte[1]; stream.read(a); diff --git a/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSinkTest.java b/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSinkTest.java index 9f7e37f462..cb0be44066 100644 --- a/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSinkTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSinkTest.java @@ -53,7 +53,7 @@ public class OutputStreamSinkTest extends StreamTest { }; final CompletionStage resultFuture = Source.single(ByteString.fromString("123456")) - .runWith(StreamConverters.fromOutputStream(() -> os), materializer); + .runWith(StreamConverters.fromOutputStream(() -> os), system); try { resultFuture.toCompletableFuture().get(3, TimeUnit.SECONDS); Assert.fail("expected IOIncompleteException"); diff --git a/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSourceTest.java b/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSourceTest.java index df6e0bce74..fa9aa39e60 100644 --- a/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSourceTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/io/OutputStreamSourceTest.java @@ -49,7 +49,7 @@ public class OutputStreamSourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } })) - .run(materializer); + .run(system); s.write("a".getBytes()); diff --git a/akka-stream-tests/src/test/java/akka/stream/io/SinkAsJavaSourceTest.java b/akka-stream-tests/src/test/java/akka/stream/io/SinkAsJavaSourceTest.java index d812404279..d7dab05dd4 100644 --- a/akka-stream-tests/src/test/java/akka/stream/io/SinkAsJavaSourceTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/io/SinkAsJavaSourceTest.java @@ -33,8 +33,7 @@ public class SinkAsJavaSourceTest extends StreamTest { public void mustBeAbleToUseAsJavaStream() throws Exception { final List list = Arrays.asList(1, 2, 3); final Sink> streamSink = StreamConverters.asJavaStream(); - java.util.stream.Stream javaStream = - Source.from(list).runWith(streamSink, materializer); + java.util.stream.Stream javaStream = Source.from(list).runWith(streamSink, system); assertEquals(list, javaStream.collect(Collectors.toList())); } } diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java index 463630dfcf..7e3991c995 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java @@ -103,7 +103,7 @@ public class FlowTest extends StreamTest { }); ints.via(flow1.via(flow2)) - .runFold("", (acc, elem) -> acc + elem, materializer) + .runFold("", (acc, elem) -> acc + elem, system) .thenAccept(elem -> probe.getRef().tell(elem, ActorRef.noSender())); probe.expectMsgEquals("de"); @@ -118,8 +118,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals(2); probe.expectMsgEquals(3); @@ -144,7 +143,7 @@ public class FlowTest extends StreamTest { }); ints.via(flow) - .runFold("", (acc, elem) -> acc + elem, materializer) + .runFold("", (acc, elem) -> acc + elem, system) .thenAccept(elem -> probe.getRef().tell(elem, ActorRef.noSender())); probe.expectMsgEquals("2334445555"); @@ -159,8 +158,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals("["); probe.expectMsgEquals("0"); @@ -183,8 +181,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = Source.single(">> ") .concat(source.via(flow)) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals(">> "); probe.expectMsgEquals("0"); @@ -213,8 +210,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals(0); probe.expectMsgEquals(1); @@ -281,8 +277,7 @@ public class FlowTest extends StreamTest { Source.from(input) .via(flow) .runForeach( - (Procedure) elem -> probe.getRef().tell(elem, ActorRef.noSender()), - materializer); + (Procedure) elem -> probe.getRef().tell(elem, ActorRef.noSender()), system); probe.expectMsgEquals(0); probe.expectMsgEquals(0); @@ -312,7 +307,7 @@ public class FlowTest extends StreamTest { .mergeSubstreams(); final CompletionStage>> future = - Source.from(input).via(flow).limit(10).runWith(Sink.>seq(), materializer); + Source.from(input).via(flow).limit(10).runWith(Sink.>seq(), system); final Object[] result = future.toCompletableFuture().get(1, TimeUnit.SECONDS).toArray(); Arrays.sort( result, @@ -347,7 +342,7 @@ public class FlowTest extends StreamTest { .concatSubstreams(); final CompletionStage>> future = - Source.from(input).via(flow).limit(10).runWith(Sink.>seq(), materializer); + Source.from(input).via(flow).limit(10).runWith(Sink.>seq(), system); final List> result = future.toCompletableFuture().get(1, TimeUnit.SECONDS); assertEquals( @@ -371,7 +366,7 @@ public class FlowTest extends StreamTest { .concatSubstreams(); final CompletionStage>> future = - Source.from(input).via(flow).limit(10).runWith(Sink.>seq(), materializer); + Source.from(input).via(flow).limit(10).runWith(Sink.>seq(), system); final List> result = future.toCompletableFuture().get(1, TimeUnit.SECONDS); assertEquals( @@ -445,9 +440,9 @@ public class FlowTest extends StreamTest { })); // collecting - final Publisher pub = source.runWith(publisher, materializer); + final Publisher pub = source.runWith(publisher, system); final CompletionStage> all = - Source.fromPublisher(pub).limit(100).runWith(Sink.seq(), materializer); + Source.fromPublisher(pub).limit(100).runWith(Sink.seq(), system); final List result = all.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals( @@ -498,9 +493,9 @@ public class FlowTest extends StreamTest { final Source> source = Source.fromSourceCompletionStage(stage); // collecting - final Publisher pub = source.runWith(publisher, materializer); + final Publisher pub = source.runWith(publisher, system); final CompletionStage> all = - Source.fromPublisher(pub).limit(100).runWith(Sink.seq(), materializer); + Source.fromPublisher(pub).limit(100).runWith(Sink.seq(), system); final List result = all.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals( @@ -538,7 +533,7 @@ public class FlowTest extends StreamTest { return ClosedShape.getInstance(); } })) - .run(materializer); + .run(system); List output = probe.receiveN(3); List> expected = @@ -567,7 +562,7 @@ public class FlowTest extends StreamTest { }); Flow, NotUsed> fl = Flow.create().zipAll(src2, "MISSING", -1); - src1.via(fl).runWith(sink, materializer); + src1.via(fl).runWith(sink, system); List output = probe.receiveN(4); List> expected = @@ -595,7 +590,7 @@ public class FlowTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); List output = probe.receiveN(6); assertEquals(Arrays.asList("A", "B", "C", "D", "E", "F"), output); @@ -617,7 +612,7 @@ public class FlowTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); List output = probe.receiveN(6); assertEquals(Arrays.asList("A", "B", "C", "D", "E", "F"), output); @@ -632,13 +627,13 @@ public class FlowTest extends StreamTest { CompletionStage, Source>> future = Source.from(input) .via(flow) - .runWith(Sink., Source>>head(), materializer); + .runWith(Sink., Source>>head(), system); Pair, Source> result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(Arrays.asList(1, 2, 3), result.first()); CompletionStage> tailFuture = - result.second().limit(4).runWith(Sink.seq(), materializer); + result.second().limit(4).runWith(Sink.seq(), system); List tailResult = tailFuture.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(Arrays.asList(4, 5, 6), tailResult); } @@ -658,7 +653,7 @@ public class FlowTest extends StreamTest { .flatMapConcat(ConstantFun.>javaIdentityFunction()) .grouped(6); CompletionStage> future = - Source.from(mainInputs).via(flow).runWith(Sink.>head(), materializer); + Source.from(mainInputs).via(flow).runWith(Sink.>head(), system); List result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); @@ -684,7 +679,7 @@ public class FlowTest extends StreamTest { .flatMapMerge(3, ConstantFun.>javaIdentityFunction()) .grouped(60); CompletionStage> future = - Source.from(mainInputs).via(flow).runWith(Sink.>head(), materializer); + Source.from(mainInputs).via(flow).runWith(Sink.>head(), system); List result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); final Set set = new HashSet(); @@ -706,7 +701,7 @@ public class FlowTest extends StreamTest { final Flow, NotUsed> flow = Flow.of(String.class).buffer(2, OverflowStrategy.backpressure()).grouped(4); final CompletionStage> future = - Source.from(input).via(flow).runWith(Sink.>head(), materializer); + Source.from(input).via(flow).runWith(Sink.>head(), system); List result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(input, result); @@ -716,7 +711,7 @@ public class FlowTest extends StreamTest { public void mustBeAbleToUseWatchTermination() throws Exception { final List input = Arrays.asList("A", "B", "C"); CompletionStage future = - Source.from(input).watchTermination(Keep.right()).to(Sink.ignore()).run(materializer); + Source.from(input).watchTermination(Keep.right()).to(Sink.ignore()).run(system); assertEquals(done(), future.toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -741,14 +736,14 @@ public class FlowTest extends StreamTest { } }); CompletionStage future = - Source.from(input).via(flow).runFold("", (aggr, in) -> aggr + in, materializer); + Source.from(input).via(flow).runFold("", (aggr, in) -> aggr + in, system); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result); final Flow flow2 = Flow.of(String.class).conflate((a, b) -> a + b); CompletionStage future2 = - Source.from(input).via(flow2).runFold("", (a, b) -> a + b, materializer); + Source.from(input).via(flow2).runFold("", (a, b) -> a + b, system); String result2 = future2.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result2); } @@ -774,7 +769,7 @@ public class FlowTest extends StreamTest { } }); CompletionStage future = - Source.from(input).via(flow).runFold("", (aggr, in) -> aggr + in, materializer); + Source.from(input).via(flow).runFold("", (aggr, in) -> aggr + in, system); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result); } @@ -806,7 +801,7 @@ public class FlowTest extends StreamTest { } }); CompletionStage future = - Source.from(input).via(flow).runFold("", (aggr, in) -> aggr + in, materializer); + Source.from(input).via(flow).runFold("", (aggr, in) -> aggr + in, system); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result); } @@ -818,7 +813,7 @@ public class FlowTest extends StreamTest { final Flow flow = Flow.of(String.class).expand(in -> Stream.iterate(in, i -> i).iterator()); final Sink> sink = Sink.head(); - CompletionStage future = Source.from(input).via(flow).runWith(sink, materializer); + CompletionStage future = Source.from(input).via(flow).runWith(sink, system); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("A", result); } @@ -838,7 +833,7 @@ public class FlowTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgEquals("A"); probe.expectMsgEquals("B"); probe.expectMsgEquals("C"); @@ -852,7 +847,7 @@ public class FlowTest extends StreamTest { List result = Source.from(input) .via(flow) - .runWith(Sink.seq(), materializer) + .runWith(Sink.seq(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); @@ -867,7 +862,7 @@ public class FlowTest extends StreamTest { Source.from(input) .via(Flow.of(FlowSpec.Fruit.class).collectType(FlowSpec.Apple.class)) - .runForeach((apple) -> probe.getRef().tell(apple, ActorRef.noSender()), materializer); + .runForeach((apple) -> probe.getRef().tell(apple, ActorRef.noSender()), system); probe.expectMsgAnyClassOf(FlowSpec.Apple.class); } @@ -896,8 +891,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); final PublisherProbeSubscription s = publisherProbe.expectSubscription(); @@ -929,8 +923,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); final PublisherProbeSubscription s = publisherProbe.expectSubscription(); @@ -969,8 +962,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); final PublisherProbeSubscription s = publisherProbe.expectSubscription(); @@ -1004,8 +996,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); final PublisherProbeSubscription s = publisherProbe.expectSubscription(); @@ -1041,8 +1032,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); final PublisherProbeSubscription s = publisherProbe.expectSubscription(); @@ -1076,8 +1066,7 @@ public class FlowTest extends StreamTest { final CompletionStage future = source .via(flow) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); final PublisherProbeSubscription s = publisherProbe.expectSubscription(); @@ -1108,7 +1097,7 @@ public class FlowTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }), - materializer); + system); probe.expectMsgAllOf("A", "B", "C"); } @@ -1130,7 +1119,7 @@ public class FlowTest extends StreamTest { } }))); - Source.from(input).to(sink).run(materializer); + Source.from(input).to(sink).run(system); probe.expectMsgAllOf("A", "B", "C"); } @@ -1154,7 +1143,7 @@ public class FlowTest extends StreamTest { final TestKit probe = new TestKit(system); Source source = Source.actorRef(1, OverflowStrategy.dropNew()); - final ActorRef actor = source.toMat(sink, Keep.left()).run(materializer); + final ActorRef actor = source.toMat(sink, Keep.left()).run(system); probe.watch(actor); probe.expectTerminated(actor); } @@ -1181,7 +1170,7 @@ public class FlowTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgEquals("A-D"); probe.expectMsgEquals("B-E"); @@ -1202,7 +1191,7 @@ public class FlowTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgEquals(new Pair("A", "D")); probe.expectMsgEquals(new Pair("B", "E")); @@ -1223,7 +1212,7 @@ public class FlowTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgAllOf("A", "B", "C", "D", "E", "F"); } @@ -1234,7 +1223,7 @@ public class FlowTest extends StreamTest { try { Source.maybe() .via(Flow.of(Integer.class).initialTimeout(Duration.ofSeconds(1))) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); org.junit.Assert.fail("A TimeoutException was expected"); @@ -1252,7 +1241,7 @@ public class FlowTest extends StreamTest { try { Source.maybe() .via(Flow.of(Integer.class).completionTimeout(Duration.ofSeconds(1))) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); org.junit.Assert.fail("A TimeoutException was expected"); @@ -1270,7 +1259,7 @@ public class FlowTest extends StreamTest { try { Source.maybe() .via(Flow.of(Integer.class).idleTimeout(Duration.ofSeconds(1))) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); org.junit.Assert.fail("A TimeoutException was expected"); @@ -1289,7 +1278,7 @@ public class FlowTest extends StreamTest { .via( Flow.of(Integer.class).keepAlive(Duration.ofSeconds(1), (Creator) () -> 0)) .takeWithin(Duration.ofMillis(1500)) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); @@ -1301,7 +1290,7 @@ public class FlowTest extends StreamTest { List out = Source.range(0, 2) .via(Flow.fromFunction((Integer x) -> x + 1)) - .runWith(Sink.seq(), materializer) + .runWith(Sink.seq(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); @@ -1341,7 +1330,7 @@ public class FlowTest extends StreamTest { Integer result = Source.range(1, 10) .via(Flow.lazyInitAsync(() -> future)) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowThrottleTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowThrottleTest.java index ff88d44230..80a0907539 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowThrottleTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowThrottleTest.java @@ -35,7 +35,7 @@ public class FlowThrottleTest extends StreamTest { .throttle(1, java.time.Duration.ofDays(1), 1, ThrottleMode.enforcing()); CompletionStage> result1 = - Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), materializer); + Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), system); // If there is accidental shared state then we would not be able to pass through the single // element @@ -44,7 +44,7 @@ public class FlowThrottleTest extends StreamTest { // It works with a new stream, too CompletionStage> result2 = - Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), materializer); + Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), system); assertEquals( result2.toCompletableFuture().get(3, TimeUnit.SECONDS), Collections.singletonList(1)); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowWithContextTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowWithContextTest.java index a442e2895e..0661431a9e 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowWithContextTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowWithContextTest.java @@ -37,7 +37,7 @@ public class FlowWithContextTest extends StreamTest { final CompletionStage>> result = Source.single(new Pair<>(1, "context")) .via(flow.map(n -> n + 1).mapContext(ctx -> ctx + "-mapped")) - .runWith(Sink.seq(), materializer); + .runWith(Sink.seq(), system); final List> pairs = result.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(1, pairs.size()); assertEquals(Integer.valueOf(2), pairs.get(0).first()); @@ -54,9 +54,7 @@ public class FlowWithContextTest extends StreamTest { final FlowWithContext flow3 = flow1.via(flow2); final CompletionStage>> result = - Source.single(new Pair<>(1, notUsed())) - .via(flow3.asFlow()) - .runWith(Sink.seq(), materializer); + Source.single(new Pair<>(1, notUsed())).via(flow3.asFlow()).runWith(Sink.seq(), system); List> pairs = result.toCompletableFuture().get(3, TimeUnit.SECONDS); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/FramingTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/FramingTest.java index 68d9259654..1bd5c61162 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/FramingTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/FramingTest.java @@ -27,6 +27,6 @@ public class FramingTest extends StreamTest { in.via( Framing.delimiter( ByteString.fromString(","), Integer.MAX_VALUE, FramingTruncation.ALLOW)) - .runWith(Sink.ignore(), materializer); + .runWith(Sink.ignore(), system); } } diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/GraphDslTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/GraphDslTest.java index a10f1f394a..d2820d9a0e 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/GraphDslTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/GraphDslTest.java @@ -67,8 +67,7 @@ public class GraphDslTest extends StreamTest { return ClosedShape.getInstance(); })); // #simple-graph-dsl - final List list = - result.run(materializer).toCompletableFuture().get(3, TimeUnit.SECONDS); + final List list = result.run(system).toCompletableFuture().get(3, TimeUnit.SECONDS); final String[] res = list.toArray(new String[] {}); Arrays.sort(res, null); assertArrayEquals( @@ -128,7 +127,7 @@ public class GraphDslTest extends StreamTest { return ClosedShape.getInstance(); })); // #graph-dsl-reusing-a-flow - final Pair, CompletionStage> pair = g.run(materializer); + final Pair, CompletionStage> pair = g.run(system); assertEquals(Integer.valueOf(2), pair.first().toCompletableFuture().get(3, TimeUnit.SECONDS)); assertEquals(Integer.valueOf(2), pair.second().toCompletableFuture().get(3, TimeUnit.SECONDS)); } @@ -209,7 +208,7 @@ public class GraphDslTest extends StreamTest { return ClosedShape.getInstance(); })); - List> result = g.run(materializer); + List> result = g.run(system); // #graph-from-list assertEquals(3, result.size()); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/JsonFramingTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/JsonFramingTest.java index d616b42edc..bff347d966 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/JsonFramingTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/JsonFramingTest.java @@ -44,7 +44,7 @@ public class JsonFramingTest extends StreamTest { acc.add(entry.utf8String()); return acc; }, - materializer); + system); // #using-json-framing List frames = result.toCompletableFuture().get(5, TimeUnit.SECONDS); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/KillSwitchTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/KillSwitchTest.java index ae2c72fe1f..aa871813e8 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/KillSwitchTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/KillSwitchTest.java @@ -39,10 +39,10 @@ public class KillSwitchTest extends StreamTest { Source.fromPublisher(upstream) .viaMat(killSwitch.flow(), Keep.right()) .to(Sink.fromSubscriber(downstream)) - .run(materializer); + .run(system); final CompletionStage completionStage = - Source.single(1).via(killSwitch.flow()).runWith(Sink.ignore(), materializer); + Source.single(1).via(killSwitch.flow()).runWith(Sink.ignore(), system); downstream.request(1); upstream.sendNext(1); @@ -66,7 +66,7 @@ public class KillSwitchTest extends StreamTest { Source.fromPublisher(upstream) .viaMat(killSwitch.flow(), Keep.right()) - .runWith(Sink.fromSubscriber(downstream), materializer); + .runWith(Sink.fromSubscriber(downstream), system); downstream.request(1); upstream.sendNext(1); @@ -92,7 +92,7 @@ public class KillSwitchTest extends StreamTest { Source.fromPublisher(upstream) .viaMat(killSwitchFlow, Keep.right()) .to(Sink.fromSubscriber(downstream)) - .run(materializer); + .run(system); downstream.request(1); upstream.sendNext(1); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/RunnableGraphTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/RunnableGraphTest.java index eccc6057eb..17f8d42afe 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/RunnableGraphTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/RunnableGraphTest.java @@ -6,6 +6,7 @@ package akka.stream.javadsl; import akka.NotUsed; import akka.stream.StreamTest; +import akka.stream.SystemMaterializer; import akka.testkit.AkkaJUnitActorSystemResource; import akka.testkit.AkkaSpec; import org.junit.ClassRule; @@ -26,7 +27,8 @@ public class RunnableGraphTest extends StreamTest { public void beAbleToConvertFromJavaToScala() { final RunnableGraph javaRunnable = Source.empty().to(Sink.ignore()); final akka.stream.scaladsl.RunnableGraph scalaRunnable = javaRunnable.asScala(); - assertEquals(NotUsed.getInstance(), scalaRunnable.run(materializer)); + assertEquals( + NotUsed.getInstance(), scalaRunnable.run(SystemMaterializer.get(system).materializer())); } @Test @@ -34,6 +36,6 @@ public class RunnableGraphTest extends StreamTest { final akka.stream.scaladsl.RunnableGraph scalaRunnable = akka.stream.scaladsl.Source.empty().to(akka.stream.scaladsl.Sink.ignore()); final RunnableGraph javaRunnable = scalaRunnable.asJava(); - assertEquals(NotUsed.getInstance(), javaRunnable.run(materializer)); + assertEquals(NotUsed.getInstance(), javaRunnable.run(system)); } } diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/SetupTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/SetupTest.java index f143b9610a..98632e1d7b 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/SetupTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/SetupTest.java @@ -35,7 +35,7 @@ public class SetupTest extends StreamTest { assertEquals( Pair.create(false, false), - source.runWith(Sink.head(), materializer).toCompletableFuture().get(5, TimeUnit.SECONDS)); + source.runWith(Sink.head(), system).toCompletableFuture().get(5, TimeUnit.SECONDS)); } @Test @@ -51,7 +51,7 @@ public class SetupTest extends StreamTest { Pair.create(false, false), Source.empty() .via(flow) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(5, TimeUnit.SECONDS)); } @@ -67,7 +67,7 @@ public class SetupTest extends StreamTest { assertEquals( Pair.create(false, false), Source.empty() - .runWith(sink, materializer) + .runWith(sink, system) .thenCompose(c -> c) .toCompletableFuture() .get(5, TimeUnit.SECONDS)); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java index 145bef5180..a663af542c 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java @@ -41,14 +41,14 @@ public class SinkTest extends StreamTest { final Sink> pubSink = Sink.asPublisher(AsPublisher.WITH_FANOUT); @SuppressWarnings("unused") final Publisher publisher = - Source.from(new ArrayList()).runWith(pubSink, materializer); + Source.from(new ArrayList()).runWith(pubSink, system); } @Test public void mustBeAbleToUseFuture() throws Exception { final Sink> futSink = Sink.head(); final List list = Collections.singletonList(1); - final CompletionStage future = Source.from(list).runWith(futSink, materializer); + final CompletionStage future = Source.from(list).runWith(futSink, system); assert future.toCompletableFuture().get(1, TimeUnit.SECONDS).equals(1); } @@ -57,14 +57,14 @@ public class SinkTest extends StreamTest { Sink> foldSink = Sink.fold(0, (arg1, arg2) -> arg1 + arg2); @SuppressWarnings("unused") CompletionStage integerFuture = - Source.from(new ArrayList()).runWith(foldSink, materializer); + Source.from(new ArrayList()).runWith(foldSink, system); } @Test public void mustBeAbleToUseActorRefSink() throws Exception { final TestKit probe = new TestKit(system); final Sink actorRefSink = Sink.actorRef(probe.getRef(), "done"); - Source.from(Arrays.asList(1, 2, 3)).runWith(actorRefSink, materializer); + Source.from(Arrays.asList(1, 2, 3)).runWith(actorRefSink, system); probe.expectMsgEquals(1); probe.expectMsgEquals(2); probe.expectMsgEquals(3); @@ -76,7 +76,7 @@ public class SinkTest extends StreamTest { final List list = Arrays.asList(1, 2, 3); final Sink>> collectorSink = StreamConverters.javaCollector(Collectors::toList); - CompletionStage> result = Source.from(list).runWith(collectorSink, materializer); + CompletionStage> result = Source.from(list).runWith(collectorSink, system); assertEquals(list, result.toCompletableFuture().get(1, TimeUnit.SECONDS)); } @@ -99,7 +99,7 @@ public class SinkTest extends StreamTest { } }); - Source.from(Arrays.asList(0, 1)).runWith(sink, materializer); + Source.from(Arrays.asList(0, 1)).runWith(sink, system); probe1.expectMsgEquals(0); probe2.expectMsgEquals(0); @@ -115,7 +115,7 @@ public class SinkTest extends StreamTest { List out = Source.range(0, 2) .toMat(Sink.seq().contramap(x -> x + 1), Keep.right()) - .run(materializer) + .run(system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); @@ -125,13 +125,13 @@ public class SinkTest extends StreamTest { @Test public void mustBeAbleToUsePreMaterialize() throws Exception { Pair, Sink> pair = - Sink.head().preMaterialize(materializer); + Sink.head().preMaterialize(system); CompletableFuture future = pair.first().toCompletableFuture(); assertEquals(false, future.isDone()); // not yet, only once actually source attached String element = "element"; - Source.single(element).runWith(pair.second(), materializer); + Source.single(element).runWith(pair.second(), system); String got = future.get(3, TimeUnit.SECONDS); // should complete nicely assertEquals(element, got); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java index beeefe3489..0b09d68c10 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java @@ -84,7 +84,7 @@ public class SourceTest extends StreamTest { .mapConcat(elem -> elem) .groupedWithin(100, Duration.ofMillis(50)) .mapConcat(elem -> elem) - .runFold("", (acc, elem) -> acc + elem, materializer) + .runFold("", (acc, elem) -> acc + elem, system) .thenAccept(elem -> probe.getRef().tell(elem, ActorRef.noSender())); probe.expectMsgEquals("de"); @@ -97,7 +97,7 @@ public class SourceTest extends StreamTest { Source ints = Source.from(input); final CompletionStage completion = - ints.runForeach(elem -> probe.getRef().tell(elem, ActorRef.noSender()), materializer); + ints.runForeach(elem -> probe.getRef().tell(elem, ActorRef.noSender()), system); completion.thenAccept(elem -> probe.getRef().tell(String.valueOf(elem), ActorRef.noSender())); @@ -161,8 +161,7 @@ public class SourceTest extends StreamTest { } }) .runForeach( - (Procedure) elem -> probe.getRef().tell(elem, ActorRef.noSender()), - materializer); + (Procedure) elem -> probe.getRef().tell(elem, ActorRef.noSender()), system); probe.expectMsgEquals(0); probe.expectMsgEquals(0); @@ -192,7 +191,7 @@ public class SourceTest extends StreamTest { .mergeSubstreams(); final CompletionStage>> future = - source.grouped(10).runWith(Sink.>>head(), materializer); + source.grouped(10).runWith(Sink.>>head(), system); final Object[] result = future.toCompletableFuture().get(1, TimeUnit.SECONDS).toArray(); Arrays.sort( result, @@ -227,7 +226,7 @@ public class SourceTest extends StreamTest { .concatSubstreams(); final CompletionStage>> future = - source.grouped(10).runWith(Sink.>>head(), materializer); + source.grouped(10).runWith(Sink.>>head(), system); final List> result = future.toCompletableFuture().get(1, TimeUnit.SECONDS); assertEquals( @@ -251,7 +250,7 @@ public class SourceTest extends StreamTest { .concatSubstreams(); final CompletionStage>> future = - source.grouped(10).runWith(Sink.>>head(), materializer); + source.grouped(10).runWith(Sink.>>head(), system); final List> result = future.toCompletableFuture().get(1, TimeUnit.SECONDS); assertEquals( @@ -276,7 +275,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); List output = probe.receiveN(6); assertEquals(Arrays.asList("A", "B", "C", "D", "E", "F"), output); @@ -298,7 +297,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); List output = probe.receiveN(6); assertEquals(Arrays.asList("A", "B", "C", "D", "E", "F"), output); @@ -322,7 +321,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); List output = probe.receiveN(5); assertEquals(Arrays.asList(4, 3, 2, 1, 0), output); @@ -343,7 +342,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(param.get(), ActorRef.noSender()); } }), - materializer); + system); probe.expectMsgClass(Done.class); } @@ -358,7 +357,7 @@ public class SourceTest extends StreamTest { in -> { throw new RuntimeException("simulated err"); }) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .whenComplete( (s, ex) -> { if (ex == null) { @@ -375,7 +374,7 @@ public class SourceTest extends StreamTest { public void mustBeAbleToUseToFuture() throws Exception { final TestKit probe = new TestKit(system); final Iterable input = Arrays.asList("A", "B", "C"); - CompletionStage future = Source.from(input).runWith(Sink.head(), materializer); + CompletionStage future = Source.from(input).runWith(Sink.head(), system); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("A", result); } @@ -383,7 +382,7 @@ public class SourceTest extends StreamTest { @Test public void mustBeAbleToUseSingle() throws Exception { // #source-single - CompletionStage> future = Source.single("A").runWith(Sink.seq(), materializer); + CompletionStage> future = Source.single("A").runWith(Sink.seq(), system); CompletableFuture> completableFuture = future.toCompletableFuture(); completableFuture.thenAccept(result -> System.out.printf("collected elements: %s\n", result)); // result list will contain exactly one element "A" @@ -402,13 +401,13 @@ public class SourceTest extends StreamTest { CompletionStage, Source>> future = Source.from(input) .prefixAndTail(3) - .runWith(Sink., Source>>head(), materializer); + .runWith(Sink., Source>>head(), system); Pair, Source> result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(Arrays.asList(1, 2, 3), result.first()); CompletionStage> tailFuture = - result.second().limit(4).runWith(Sink.seq(), materializer); + result.second().limit(4).runWith(Sink.seq(), system); List tailResult = tailFuture.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(Arrays.asList(4, 5, 6), tailResult); } @@ -428,7 +427,7 @@ public class SourceTest extends StreamTest { .flatMapConcat( ConstantFun.>javaIdentityFunction()) .grouped(6) - .runWith(Sink.>head(), materializer); + .runWith(Sink.>head(), system); List result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); @@ -453,7 +452,7 @@ public class SourceTest extends StreamTest { Source.from(mainInputs) .flatMapMerge(3, ConstantFun.>javaIdentityFunction()) .grouped(60) - .runWith(Sink.>head(), materializer); + .runWith(Sink.>head(), system); List result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); final Set set = new HashSet(); @@ -476,7 +475,7 @@ public class SourceTest extends StreamTest { Source.from(input) .buffer(2, OverflowStrategy.backpressure()) .grouped(4) - .runWith(Sink.>head(), materializer); + .runWith(Sink.>head(), system); List result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(input, result); @@ -489,7 +488,7 @@ public class SourceTest extends StreamTest { CompletionStage future = Source.from(input) .conflateWithSeed(s -> s, (aggr, in) -> aggr + in) - .runFold("", (aggr, in) -> aggr + in, materializer); + .runFold("", (aggr, in) -> aggr + in, system); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result); @@ -498,7 +497,7 @@ public class SourceTest extends StreamTest { CompletionStage future2 = Source.from(input) .conflate((String a, String b) -> a + b) - .runFold("", (a, b) -> a + b, materializer); + .runFold("", (a, b) -> a + b, system); String result2 = future2.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result2); } @@ -510,7 +509,7 @@ public class SourceTest extends StreamTest { CompletionStage future = Source.from(input) .expand(in -> Stream.iterate(in, i -> i).iterator()) - .runWith(Sink.head(), materializer); + .runWith(Sink.head(), system); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("A", result); } @@ -530,7 +529,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } })) - .run(materializer); + .run(system); probe.expectNoMessage(Duration.ofMillis(600)); probe.expectMsgEquals("tick"); probe.expectNoMessage(Duration.ofMillis(200)); @@ -552,7 +551,7 @@ public class SourceTest extends StreamTest { final Iterable input = Arrays.asList("a", "b", "c"); Source.from(input) .mapAsync(4, elem -> CompletableFuture.completedFuture(elem.toUpperCase())) - .runForeach(elem -> probe.getRef().tell(elem, ActorRef.noSender()), materializer); + .runForeach(elem -> probe.getRef().tell(elem, ActorRef.noSender()), system); probe.expectMsgEquals("A"); probe.expectMsgEquals("B"); probe.expectMsgEquals("C"); @@ -571,16 +570,16 @@ public class SourceTest extends StreamTest { (elem) -> { probe.getRef().tell(elem, ActorRef.noSender()); }, - materializer); + system); probe.expectMsgAnyClassOf(FlowSpec.Apple.class); } @Test public void mustWorkFromFuture() throws Exception { final Iterable input = Arrays.asList("A", "B", "C"); - CompletionStage future1 = Source.from(input).runWith(Sink.head(), materializer); + CompletionStage future1 = Source.from(input).runWith(Sink.head(), system); CompletionStage future2 = - Source.fromCompletionStage(future1).runWith(Sink.head(), materializer); + Source.fromCompletionStage(future1).runWith(Sink.head(), system); String result = future2.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("A", result); } @@ -589,7 +588,7 @@ public class SourceTest extends StreamTest { public void mustWorkFromFutureVoid() throws Exception { CompletionStage future = CompletableFuture.completedFuture(null); CompletionStage> future2 = - Source.fromCompletionStage(future).runWith(Sink.seq(), materializer); + Source.fromCompletionStage(future).runWith(Sink.seq(), system); List result = future2.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(0, result.size()); } @@ -597,7 +596,7 @@ public class SourceTest extends StreamTest { @Test public void mustWorkFromRange() throws Exception { CompletionStage> f = - Source.range(0, 10).grouped(20).runWith(Sink.>head(), materializer); + Source.range(0, 10).grouped(20).runWith(Sink.>head(), system); final List result = f.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(11, result.size()); Integer counter = 0; @@ -607,7 +606,7 @@ public class SourceTest extends StreamTest { @Test public void mustWorkFromRangeWithStep() throws Exception { CompletionStage> f = - Source.range(0, 10, 2).grouped(20).runWith(Sink.>head(), materializer); + Source.range(0, 10, 2).grouped(20).runWith(Sink.>head(), system); final List result = f.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(6, result.size()); Integer counter = 0; @@ -620,7 +619,7 @@ public class SourceTest extends StreamTest { @Test public void mustRepeat() throws Exception { final CompletionStage> f = - Source.repeat(42).grouped(10000).runWith(Sink.>head(), materializer); + Source.repeat(42).grouped(10000).runWith(Sink.>head(), system); final List result = f.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals(result.size(), 10000); for (Integer i : result) assertEquals(i, (Integer) 42); @@ -629,8 +628,7 @@ public class SourceTest extends StreamTest { @Test public void mustBeAbleToUseQueue() throws Exception { final Pair, CompletionStage>> x = - Flow.of(String.class) - .runWith(Source.queue(2, OverflowStrategy.fail()), Sink.seq(), materializer); + Flow.of(String.class).runWith(Source.queue(2, OverflowStrategy.fail()), Sink.seq(), system); final SourceQueueWithComplete source = x.first(); final CompletionStage> result = x.second(); source.offer("hello"); @@ -653,7 +651,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } })) - .run(materializer); + .run(system); ref.tell(1, ActorRef.noSender()); probe.expectMsgEquals(1); ref.tell(2, ActorRef.noSender()); @@ -677,7 +675,7 @@ public class SourceTest extends StreamTest { }; }); - ints.runFold("", (acc, elem) -> acc + elem, materializer) + ints.runFold("", (acc, elem) -> acc + elem, system) .thenAccept(elem -> probe.getRef().tell(elem, ActorRef.noSender())); probe.expectMsgEquals("2334445555"); @@ -691,7 +689,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = source.runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals("["); probe.expectMsgEquals("0"); @@ -714,8 +712,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = Source.single(">> ") .concat(source) - .runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + .runWith(Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals(">> "); probe.expectMsgEquals("0"); @@ -742,7 +739,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = source.runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals(2); probe.expectMsgEquals(3); @@ -763,7 +760,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = source.runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgEquals(0); probe.expectMsgEquals(1); @@ -790,7 +787,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = source.runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); final PublisherProbeSubscription s = publisherProbe.expectSubscription(); s.sendNext(0); probe.expectMsgEquals(0); @@ -815,7 +812,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = source.runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgAllOf(0, 1, 2, 3); @@ -842,7 +839,7 @@ public class SourceTest extends StreamTest { combined .toMat( Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), Keep.left()) - .run(materializer); + .run(system); queue.offer(0); queue.offer(1); @@ -866,7 +863,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = source.runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgAllOf(Arrays.asList(0, 2), Arrays.asList(1, 3)); @@ -886,7 +883,7 @@ public class SourceTest extends StreamTest { final CompletionStage future = source.runWith( - Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer); + Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), system); probe.expectMsgAllOf(Boolean.TRUE, Boolean.FALSE); @@ -911,7 +908,7 @@ public class SourceTest extends StreamTest { } }); Source, NotUsed> zippedSrc = src1.zipAll(src2, "MISSING", -1); - zippedSrc.runWith(sink, materializer); + zippedSrc.runWith(sink, system); List output = probe.receiveN(6); List> expected = @@ -928,7 +925,7 @@ public class SourceTest extends StreamTest { @Test public void createEmptySource() throws Exception { List actual = - Source.empty(Integer.class).runWith(Sink.seq(), materializer).toCompletableFuture().get(); + Source.empty(Integer.class).runWith(Sink.seq(), system).toCompletableFuture().get(); assertThat(actual, is(Collections.emptyList())); } @@ -936,7 +933,7 @@ public class SourceTest extends StreamTest { public void cycleSourceMustGenerateSameSequenceInRepeatedFashion() throws Exception { // #cycle final Source source = Source.cycle(() -> Arrays.asList(1, 2, 3).iterator()); - CompletionStage> result = source.grouped(9).runWith(Sink.head(), materializer); + CompletionStage> result = source.grouped(9).runWith(Sink.head(), system); List emittedValues = result.toCompletableFuture().get(); assertThat(emittedValues, is(Arrays.asList(1, 2, 3, 1, 2, 3, 1, 2, 3))); // #cycle @@ -949,7 +946,7 @@ public class SourceTest extends StreamTest { // #cycle-error Iterator emptyIterator = Collections.emptyList().iterator(); Source.cycle(() -> emptyIterator) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) // stream will be terminated with IllegalArgumentException // #cycle-error .toCompletableFuture() @@ -973,7 +970,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgAllOf("A", "B", "C", "D", "E", "F"); } @@ -998,7 +995,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgEquals("A-D"); probe.expectMsgEquals("B-E"); @@ -1019,7 +1016,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgEquals(new Pair("A", "D")); probe.expectMsgEquals(new Pair("B", "E")); @@ -1040,7 +1037,7 @@ public class SourceTest extends StreamTest { probe.getRef().tell(elem, ActorRef.noSender()); } }, - materializer); + system); probe.expectMsgAllOf("A", "B", "C", "D", "E", "F"); } @@ -1051,7 +1048,7 @@ public class SourceTest extends StreamTest { try { Source.maybe() .initialTimeout(Duration.ofSeconds(1)) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); org.junit.Assert.fail("A TimeoutException was expected"); @@ -1069,7 +1066,7 @@ public class SourceTest extends StreamTest { try { Source.maybe() .completionTimeout(Duration.ofSeconds(1)) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); org.junit.Assert.fail("A TimeoutException was expected"); @@ -1087,7 +1084,7 @@ public class SourceTest extends StreamTest { try { Source.maybe() .idleTimeout(Duration.ofSeconds(1)) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); org.junit.Assert.fail("A TimeoutException was expected"); @@ -1105,7 +1102,7 @@ public class SourceTest extends StreamTest { Source.maybe() .keepAlive(Duration.ofSeconds(1), () -> 0) .takeWithin(Duration.ofMillis(1500)) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); @@ -1127,7 +1124,7 @@ public class SourceTest extends StreamTest { Source.from(Arrays.asList(0, 1, 2)) .throttle(10, Duration.ofSeconds(1), 10, ThrottleMode.shaping()) .throttle(10, Duration.ofSeconds(1), 10, ThrottleMode.enforcing()) - .runWith(Sink.head(), materializer) + .runWith(Sink.head(), system) .toCompletableFuture() .get(3, TimeUnit.SECONDS); @@ -1151,7 +1148,7 @@ public class SourceTest extends StreamTest { @Test public void mustBeAbleToUsePreMaterialize() { final Pair> p = - Source.empty().preMaterialize(materializer); + Source.empty().preMaterialize(system); } @Test diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/TcpTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/TcpTest.java index fcc8ccf4d8..2e25004720 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/TcpTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/TcpTest.java @@ -57,7 +57,7 @@ public class TcpTest extends StreamTest { Sink.foreach( new Procedure() { public void apply(IncomingConnection conn) { - conn.handleWith(Flow.of(ByteString.class), materializer); + conn.handleWith(Flow.of(ByteString.class), system); } }); @@ -76,7 +76,7 @@ public class TcpTest extends StreamTest { final Source> binding = Tcp.get(system).bind(serverAddress.getHostString(), serverAddress.getPort()); - final CompletionStage future = binding.to(echoHandler).run(materializer); + final CompletionStage future = binding.to(echoHandler).run(system); final ServerBinding b = future.toCompletableFuture().get(5, TimeUnit.SECONDS); assertEquals(b.localAddress().getPort(), serverAddress.getPort()); @@ -92,7 +92,7 @@ public class TcpTest extends StreamTest { return acc.concat(elem); } }, - materializer); + system); final byte[] result = resultFuture.toCompletableFuture().get(5, TimeUnit.SECONDS).toArray(); for (int i = 0; i < testInput.size(); i++) { @@ -109,7 +109,7 @@ public class TcpTest extends StreamTest { final Source> binding = Tcp.get(system).bind(serverAddress.getHostString(), serverAddress.getPort()); - final CompletionStage future = binding.to(echoHandler).run(materializer); + final CompletionStage future = binding.to(echoHandler).run(system); final ServerBinding b = future.toCompletableFuture().get(5, TimeUnit.SECONDS); assertEquals(b.localAddress().getPort(), serverAddress.getPort()); @@ -122,7 +122,7 @@ public class TcpTest extends StreamTest { try { binding .to(echoHandler) - .run(materializer) + .run(system) .toCompletableFuture() .get(5, TimeUnit.SECONDS); assertTrue("Expected BindFailedException, but nothing was reported", false); @@ -152,7 +152,7 @@ public class TcpTest extends StreamTest { .outgoingConnection(serverAddress.getHostString(), serverAddress.getPort()), Keep.right()) .to(Sink.ignore()) - .run(materializer) + .run(system) .toCompletableFuture() .get(5, TimeUnit.SECONDS); assertTrue("Expected StreamTcpException, but nothing was reported", false); diff --git a/akka-stream-tests/src/test/java/akka/stream/stage/StageTest.java b/akka-stream-tests/src/test/java/akka/stream/stage/StageTest.java index 3dd4f44cae..e188e3b121 100644 --- a/akka-stream-tests/src/test/java/akka/stream/stage/StageTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/stage/StageTest.java @@ -36,10 +36,7 @@ public class StageTest extends StreamTest { final JavaIdentityStage identity = new JavaIdentityStage(); final CompletionStage> result = - ints.via(identity) - .via(identity) - .grouped(1000) - .runWith(Sink.>head(), materializer); + ints.via(identity).via(identity).grouped(1000).runWith(Sink.>head(), system); assertEquals( Arrays.asList(0, 1, 2, 3, 4, 5), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); diff --git a/akka-stream-tests/src/test/scala-jdk9-only/akka/stream/scaladsl/FlowPublisherSinkSpec.scala b/akka-stream-tests/src/test/scala-jdk9-only/akka/stream/scaladsl/FlowPublisherSinkSpec.scala index b38acdc0cd..026b8aeea5 100644 --- a/akka-stream-tests/src/test/scala-jdk9-only/akka/stream/scaladsl/FlowPublisherSinkSpec.scala +++ b/akka-stream-tests/src/test/scala-jdk9-only/akka/stream/scaladsl/FlowPublisherSinkSpec.scala @@ -5,7 +5,7 @@ package akka.stream.scaladsl import akka.stream.testkit.StreamSpec -import akka.stream.{ ClosedShape, ActorMaterializer } +import akka.stream.ClosedShape import akka.stream.testkit.Utils._ import akka.stream.testkit.scaladsl.StreamTestKit._ @@ -15,8 +15,6 @@ import scala.concurrent.Await class FlowPublisherSinkSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A FlowPublisherSink" must { "work with SubscriberSource" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/FusingSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FusingSpec.scala index 9b646a76d3..b770b12b70 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/FusingSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/FusingSpec.scala @@ -10,8 +10,6 @@ import akka.stream.testkit.StreamSpec class FusingSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - def actorRunningStage = { GraphInterpreter.currentInterpreter.context } diff --git a/akka-stream-tests/src/test/scala/akka/stream/SystemMaterializerSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/SystemMaterializerSpec.scala new file mode 100644 index 0000000000..a5774521d3 --- /dev/null +++ b/akka-stream-tests/src/test/scala/akka/stream/SystemMaterializerSpec.scala @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2009-2019 Lightbend Inc. + */ + +package akka.stream + +import akka.stream.scaladsl.Keep +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source +import akka.stream.testkit.StreamSpec +import org.scalatest.concurrent.ScalaFutures + +import scala.concurrent.Future + +class SystemMaterializerSpec extends StreamSpec with ScalaFutures { + + def compileOnly(): Unit = { + Source(1 to 3).to(Sink.ignore).run() + Source(1 to 3).runWith(Sink.ignore) + Source(1 to 3).runFold(0)((acc, elem) => acc + elem) + Source(1 to 3).runFoldAsync(0)((acc, elem) => Future.successful(acc + elem)) + Source(1 to 3).runForeach(_ => ()) + Source(1 to 3).runReduce(_ + _) + } + + "The SystemMaterializer" must { + + "be implicitly provided when implicit actor system is in scope" in { + val result = Source(1 to 3).toMat(Sink.seq)(Keep.right).run() + result.futureValue should ===(Seq(1, 2, 3)) + } + } + +} diff --git a/akka-stream-tests/src/test/scala/akka/stream/impl/FanoutProcessorSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/impl/FanoutProcessorSpec.scala index 53f23facaf..4ceaa037e6 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/impl/FanoutProcessorSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/impl/FanoutProcessorSpec.scala @@ -4,8 +4,9 @@ package akka.stream.impl -import akka.stream.ActorMaterializer -import akka.stream.scaladsl.{ Keep, Sink, Source } +import akka.stream.scaladsl.Keep +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import akka.stream.testkit.StreamSpec import akka.stream.testkit.Utils.TE import akka.stream.testkit.scaladsl.StreamTestKit.assertAllStagesStopped @@ -13,8 +14,6 @@ import akka.testkit.TestProbe class FanoutProcessorSpec extends StreamSpec { - implicit val mat = ActorMaterializer() - "The FanoutProcessor" must { // #25634 diff --git a/akka-stream-tests/src/test/scala/akka/stream/impl/GraphStageLogicSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/impl/GraphStageLogicSpec.scala index b7a590cdac..ec153e4546 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/impl/GraphStageLogicSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/impl/GraphStageLogicSpec.scala @@ -19,8 +19,6 @@ import scala.concurrent.duration.Duration class GraphStageLogicSpec extends StreamSpec with GraphInterpreterSpecKit with ScalaFutures { - implicit val materializer = ActorMaterializer() - object emit1234 extends GraphStage[FlowShape[Int, Int]] { val in = Inlet[Int]("in") val out = Outlet[Int]("out") diff --git a/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala index 665df72f11..755094c19d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala @@ -18,7 +18,6 @@ import scala.concurrent.duration._ import scala.concurrent.{ Await, Future } class TimeoutsSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() "InitialTimeout" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/ActorGraphInterpreterSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/ActorGraphInterpreterSpec.scala index 6bc2deefe7..2e3fbb3c55 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/ActorGraphInterpreterSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/ActorGraphInterpreterSpec.scala @@ -22,8 +22,6 @@ import scala.concurrent.duration._ import org.reactivestreams.{ Publisher, Subscriber, Subscription } class ActorGraphInterpreterSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "ActorGraphInterpreter" must { "be able to interpret a simple identity graph stage" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/KeepGoingStageSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/KeepGoingStageSpec.scala index e1dfaa0c57..c1fa8f4a8b 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/KeepGoingStageSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/impl/fusing/KeepGoingStageSpec.scala @@ -4,21 +4,28 @@ package akka.stream.impl.fusing -import akka.actor.{ ActorRef, NoSerializationVerificationNeeded } -import akka.stream.scaladsl.{ Keep, Source } +import akka.actor.ActorRef +import akka.actor.NoSerializationVerificationNeeded +import akka.stream.scaladsl.Keep +import akka.stream.scaladsl.Source +import akka.stream.stage.AsyncCallback +import akka.stream.stage.GraphStageLogic +import akka.stream.stage.GraphStageWithMaterializedValue +import akka.stream.stage.InHandler import akka.stream.testkit.StreamSpec -import akka.stream.{ ActorMaterializer, Attributes, Inlet, SinkShape } -import akka.stream.stage.{ AsyncCallback, GraphStageLogic, GraphStageWithMaterializedValue, InHandler } import akka.stream.testkit.Utils._ import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.Attributes +import akka.stream.Inlet +import akka.stream.SinkShape -import scala.concurrent.{ Await, Future, Promise } import scala.concurrent.duration._ +import scala.concurrent.Await +import scala.concurrent.Future +import scala.concurrent.Promise class KeepGoingStageSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - trait PingCmd extends NoSerializationVerificationNeeded case class Register(probe: ActorRef) extends PingCmd case object Ping extends PingCmd diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/ByteStringParserSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/ByteStringParserSpec.scala index 371fcdd55f..7747c2a130 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/ByteStringParserSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/ByteStringParserSpec.scala @@ -5,18 +5,23 @@ package akka.stream.io import akka.stream.impl.io.ByteStringParser -import akka.stream.impl.io.ByteStringParser.{ ByteReader, ParseResult, ParseStep } -import akka.stream.scaladsl.{ Sink, Source } +import akka.stream.impl.io.ByteStringParser.ByteReader +import akka.stream.impl.io.ByteStringParser.ParseResult +import akka.stream.impl.io.ByteStringParser.ParseStep +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import akka.stream.stage.GraphStageLogic -import akka.stream.testkit.{ StreamSpec, TestPublisher, TestSubscriber } -import akka.stream.{ ActorMaterializer, Attributes, ThrottleMode } +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber +import akka.stream.Attributes +import akka.stream.ThrottleMode import akka.util.ByteString import scala.concurrent.Await import scala.concurrent.duration._ class ByteStringParserSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() "ByteStringParser" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala index 8635881b52..7e549cac86 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala @@ -96,7 +96,6 @@ class TlsSpec extends StreamSpec(TlsSpec.configOverrides) with WithLogCapturing import TlsSpec._ import system.dispatcher - implicit val materializer = ActorMaterializer() import GraphDSL.Implicits._ diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/compression/CodecSpecSupport.scala b/akka-stream-tests/src/test/scala/akka/stream/io/compression/CodecSpecSupport.scala index 6aee0f6aa3..388af3b96b 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/compression/CodecSpecSupport.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/compression/CodecSpecSupport.scala @@ -5,10 +5,11 @@ package akka.stream.io.compression import akka.actor.ActorSystem -import akka.stream.ActorMaterializer import akka.testkit.TestKit import akka.util.ByteString -import org.scalatest.{ BeforeAndAfterAll, Matchers, Suite } +import org.scalatest.BeforeAndAfterAll +import org.scalatest.Matchers +import org.scalatest.Suite trait CodecSpecSupport extends Matchers with BeforeAndAfterAll { self: Suite => @@ -73,7 +74,6 @@ est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscin "\n") implicit val system = ActorSystem(getClass.getSimpleName) - implicit val materializer = ActorMaterializer() override def afterAll() = TestKit.shutdownActorSystem(system) } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSinkSpec.scala index cc62888697..5f83f342e8 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSinkSpec.scala @@ -51,7 +51,6 @@ object ActorRefBackpressureSinkSpec { class ActorRefBackpressureSinkSpec extends StreamSpec { import ActorRefBackpressureSinkSpec._ - implicit val mat = ActorMaterializer() def createActor[T](c: Class[T]) = system.actorOf(Props(c, testActor).withDispatcher("akka.test.stream-dispatcher")) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSourceSpec.scala index f70fb9ec1f..d0b1ff9175 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefBackpressureSourceSpec.scala @@ -8,7 +8,6 @@ import akka.actor.Status import akka.stream.testkit.Utils.TE import akka.stream.testkit.scaladsl.StreamTestKit.assertAllStagesStopped import akka.stream.testkit.scaladsl.TestSink -import akka.stream.ActorMaterializer import akka.stream.testkit.StreamSpec import akka.testkit.TestProbe @@ -21,8 +20,6 @@ private object ActorRefBackpressureSourceSpec { class ActorRefBackpressureSourceSpec extends StreamSpec { import ActorRefBackpressureSourceSpec._ - private implicit val materializer: ActorMaterializer = ActorMaterializer() - "An Source.actorRefWithAck" must { "emit received messages to the stream and ack" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSinkSpec.scala index 59a9ddba37..5b80639698 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSinkSpec.scala @@ -5,7 +5,6 @@ package akka.stream.scaladsl import akka.actor.{ Actor, ActorRef, Props } -import akka.stream.ActorMaterializer import akka.stream.testkit._ import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit.scaladsl._ @@ -25,7 +24,6 @@ object ActorRefSinkSpec { class ActorRefSinkSpec extends StreamSpec { import ActorRefSinkSpec._ - implicit val materializer = ActorMaterializer() "A ActorRefSink" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala index 62e9ed82d8..d88a79688c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala @@ -17,7 +17,6 @@ import akka.actor.ActorRef import org.reactivestreams.Publisher class ActorRefSourceSpec extends StreamSpec { - private implicit val materializer = ActorMaterializer() "A ActorRefSource" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AttributesSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AttributesSpec.scala index d3c1cf39ed..2cb119f394 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AttributesSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AttributesSpec.scala @@ -420,7 +420,7 @@ class AttributesSpec // this is now just for map since there already is one in-between stage and map .async .addAttributes(ActorAttributes.dispatcher("my-dispatcher")) - .runWith(javadsl.Sink.head(), materializer) + .runWith(javadsl.Sink.head[String](), materializer) val dispatcher = dispatcherF.toCompletableFuture.get(remainingOrDefault.toMillis, TimeUnit.MILLISECONDS) @@ -433,7 +433,7 @@ class AttributesSpec .fromGraph(new ThreadNameSnitchingStage(ActorAttributes.IODispatcher.dispatcher)) .async .withAttributes(ActorAttributes.dispatcher("my-dispatcher")) - .runWith(javadsl.Sink.head(), materializer) + .runWith(javadsl.Sink.head[String](), materializer) val dispatcher = dispatcherF.toCompletableFuture.get(remainingOrDefault.toMillis, TimeUnit.MILLISECONDS) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/BidiFlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/BidiFlowSpec.scala index d8675b103b..7130e09261 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/BidiFlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/BidiFlowSpec.scala @@ -20,8 +20,6 @@ class BidiFlowSpec extends StreamSpec { import Attributes._ import GraphDSL.Implicits._ - implicit val materializer = ActorMaterializer() - val bidi = BidiFlow.fromFlows( Flow[Int].map(x => x.toLong + 2).withAttributes(name("top")), Flow[ByteString].map(_.decodeString("UTF-8")).withAttributes(name("bottom"))) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/CompressionSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/CompressionSpec.scala index 506095a4ad..47930b9542 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/CompressionSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/CompressionSpec.scala @@ -6,14 +6,12 @@ package akka.stream.scaladsl import java.nio.charset.StandardCharsets -import akka.stream.impl.io.compression.{ DeflateCompressor, GzipCompressor } +import akka.stream.impl.io.compression.DeflateCompressor +import akka.stream.impl.io.compression.GzipCompressor import akka.stream.testkit.StreamSpec -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } import akka.util.ByteString class CompressionSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) def gzip(s: String): ByteString = new GzipCompressor().compressAndFinish(ByteString(s)) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FailedSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FailedSourceSpec.scala index 76f7855ca1..11909e8bf4 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FailedSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FailedSourceSpec.scala @@ -4,16 +4,14 @@ package akka.stream.scaladsl -import akka.stream.ActorMaterializer -import akka.stream.testkit.{ StreamSpec, TestSubscriber } +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestSubscriber import akka.testkit.DefaultTimeout import scala.util.control.NoStackTrace class FailedSourceSpec extends StreamSpec with DefaultTimeout { - implicit val materializer = ActorMaterializer() - "The Failed Source" must { "emit error immediately" in { val ex = new RuntimeException with NoStackTrace diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala index 3cabaeb96e..e4c894154c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala @@ -5,17 +5,13 @@ package akka.stream.scaladsl import akka.actor.ActorSystem -import akka.stream.ActorMaterializer -import akka.stream.ActorMaterializerSettings -import akka.stream.testkit.{ StreamSpec, TestSubscriber } +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestSubscriber import org.reactivestreams.Subscriber import org.scalatest.Matchers class FlowAppendSpec extends StreamSpec with River { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) - "Flow" should { "append Flow" in riverOf[String] { subscriber => val flow = Flow[Int].via(otherFlow) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAskSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAskSpec.scala index db5779c6c1..c350be4615 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAskSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAskSpec.scala @@ -6,16 +6,22 @@ package akka.stream.scaladsl import java.util.concurrent.ThreadLocalRandom -import akka.actor.{ Actor, ActorRef, PoisonPill, Props } +import akka.actor.Actor +import akka.actor.ActorRef +import akka.actor.PoisonPill +import akka.actor.Props import akka.stream.ActorAttributes.supervisionStrategy -import akka.stream.{ ActorAttributes, ActorMaterializer, Supervision } import akka.stream.Supervision.resumingDecider -import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit._ -import akka.testkit.{ TestActors, TestProbe } +import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.ActorAttributes +import akka.stream.Supervision +import akka.testkit.TestActors +import akka.testkit.TestProbe -import scala.concurrent.{ Await, Future } import scala.concurrent.duration._ +import scala.concurrent.Await +import scala.concurrent.Future import scala.reflect.ClassTag object FlowAskSpec { @@ -73,8 +79,6 @@ object FlowAskSpec { class FlowAskSpec extends StreamSpec { import FlowAskSpec._ - implicit val materializer = ActorMaterializer() - "A Flow with ask" must { implicit val timeout = akka.util.Timeout(10.seconds) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectSpec.scala index 5570b942b0..d2da55ee77 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectSpec.scala @@ -4,21 +4,17 @@ package akka.stream.scaladsl +import java.util.concurrent.ThreadLocalRandom.{ current => random } + import akka.stream.ActorAttributes._ import akka.stream.Supervision._ +import akka.stream.testkit.ScriptedTest +import akka.stream.testkit.StreamSpec import akka.stream.testkit.Utils.TE import akka.stream.testkit.scaladsl.TestSink -import java.util.concurrent.ThreadLocalRandom.{ current => random } - -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } -import akka.stream.testkit.{ ScriptedTest, StreamSpec } - class FlowCollectSpec extends StreamSpec with ScriptedTest { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) - "A Collect" must { "collect" in { @@ -28,7 +24,9 @@ class FlowCollectSpec extends StreamSpec with ScriptedTest { Seq(x) -> (if ((x & 1) == 0) Seq((x * x).toString) else Seq.empty[String]) }: _*) TestConfig.RandomTestRange.foreach(_ => - runScript(script, settings)(_.collect { case x if x % 2 == 0 => (x * x).toString })) + runScript(script)(_.collect { + case x if x % 2 == 0 => (x * x).toString + })) } "restart when Collect throws" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectTypeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectTypeSpec.scala index 5a0a4f293c..65f2ff8147 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectTypeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectTypeSpec.scala @@ -5,13 +5,9 @@ package akka.stream.scaladsl import akka.stream.testkit.StreamSpec -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } class FlowCollectTypeSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) - sealed class Fruit class Orange extends Fruit object Orange extends Orange diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala index a78be9ff4f..49ab0dda97 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala @@ -6,13 +6,11 @@ package akka.stream.scaladsl import akka.NotUsed import akka.stream.testkit.StreamSpec +import com.github.ghik.silencer.silent import org.reactivestreams.Publisher import scala.collection.immutable.Seq import scala.concurrent.Future -import akka.stream.ActorMaterializer -import akka.stream.ActorMaterializerSettings -import com.github.ghik.silencer.silent @silent // unused vars are used in shouldNot compile tests class FlowCompileSpec extends StreamSpec { @@ -22,7 +20,6 @@ class FlowCompileSpec extends StreamSpec { import scala.concurrent.ExecutionContext.Implicits.global val intFut = Source.fromFuture(Future { 3 }) - implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system)) "Flow" should { "not run" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala index 6a4a058c1b..07934844ab 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala @@ -7,13 +7,16 @@ package akka.stream.scaladsl import akka.Done import akka.stream.Attributes._ import akka.stream.OverflowStrategies.EmitEarly +import akka.stream._ import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit.scaladsl.TestSink -import akka.stream.testkit.{ StreamSpec, TestPublisher, TestSubscriber } -import akka.stream._ +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber import akka.testkit.TimingTest import org.scalatest.concurrent.PatienceConfiguration -import org.scalatest.time.{ Milliseconds, Span } +import org.scalatest.time.Milliseconds +import org.scalatest.time.Span import scala.concurrent.Await import scala.concurrent.duration._ @@ -21,8 +24,6 @@ import scala.util.control.NoStackTrace class FlowDelaySpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A Delay" must { "deliver elements with some time shift" taggedAs TimingTest in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDetacherSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDetacherSpec.scala index 72d6957ac7..8dfd370f8d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDetacherSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDetacherSpec.scala @@ -4,17 +4,15 @@ package akka.stream.scaladsl -import akka.stream._ -import scala.concurrent.Await -import scala.concurrent.duration._ -import akka.stream.testkit.scaladsl.TestSink import akka.stream.testkit.StreamSpec import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.testkit.scaladsl.TestSink + +import scala.concurrent.Await +import scala.concurrent.duration._ class FlowDetacherSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A Detacher" must { "pass through all elements" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWhileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWhileSpec.scala index 477813a588..406042f3c0 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWhileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWhileSpec.scala @@ -7,18 +7,12 @@ package akka.stream.scaladsl import akka.stream.ActorAttributes._ import akka.stream.Supervision._ import akka.stream.testkit.Utils._ -import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.stream.ActorMaterializer -import akka.stream.ActorMaterializerSettings import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit.scaladsl.TestSink class FlowDropWhileSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer(settings) - "A DropWhile" must { "drop while predicate is true" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala index c67d5c21cc..786d8f8e8f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala @@ -4,13 +4,11 @@ package akka.stream.scaladsl -import scala.concurrent.duration._ -import akka.stream.ActorMaterializer import akka.stream.testkit._ -class FlowDropWithinSpec extends StreamSpec { +import scala.concurrent.duration._ - implicit val materializer = ActorMaterializer() +class FlowDropWithinSpec extends StreamSpec { "A DropWithin" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala index 32505693fe..c26b19f597 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala @@ -5,24 +5,25 @@ package akka.stream.scaladsl import akka.NotUsed -import akka.stream.stage.{ GraphStage, GraphStageLogic, OutHandler } import akka.stream._ +import akka.stream.impl.TraversalBuilder +import akka.stream.impl.fusing.GraphStages.SingleSource +import akka.stream.stage.GraphStage +import akka.stream.stage.GraphStageLogic +import akka.stream.stage.OutHandler import akka.stream.testkit.Utils.TE import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.testkit.TestLatch +import akka.util.OptionVal +import org.scalatest.exceptions.TestFailedException import scala.concurrent._ import scala.concurrent.duration._ -import akka.stream.impl.TraversalBuilder -import akka.stream.impl.fusing.GraphStages.SingleSource -import akka.stream.testkit.{ StreamSpec, TestPublisher } -import org.scalatest.exceptions.TestFailedException -import akka.stream.testkit.scaladsl.TestSink -import akka.testkit.TestLatch -import akka.util.OptionVal - class FlowFlattenMergeSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() import system.dispatcher def src10(i: Int) = Source(i until (i + 10)) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldAsyncSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldAsyncSpec.scala index 8d6edf30b6..c5558d1187 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldAsyncSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldAsyncSpec.scala @@ -6,22 +6,23 @@ package akka.stream.scaladsl import akka.NotUsed import akka.stream.ActorAttributes.supervisionStrategy -import akka.stream.ActorMaterializer -import akka.stream.Supervision.{ restartingDecider, resumingDecider } +import akka.stream.Supervision.restartingDecider +import akka.stream.Supervision.resumingDecider import akka.stream.impl.ReactiveStreamsCompliance import akka.stream.testkit.Utils._ -import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.testkit.LongRunningTest import org.scalatest.concurrent.PatienceConfiguration.Timeout import scala.concurrent.duration._ -import scala.concurrent.{ Await, Future } +import scala.concurrent.Await +import scala.concurrent.Future import scala.util.control.NoStackTrace -import akka.testkit.LongRunningTest class FlowFoldAsyncSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - implicit def ec = materializer.executionContext + + implicit def ec = system.dispatcher val timeout = Timeout(3.seconds) "A FoldAsync" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldSpec.scala index 12bf4a842e..b7e0e1f6c8 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldSpec.scala @@ -6,16 +6,15 @@ package akka.stream.scaladsl import akka.NotUsed import akka.stream.testkit.StreamSpec - -import scala.concurrent.Await -import akka.stream.{ ActorAttributes, ActorMaterializer, Supervision } import akka.stream.testkit.Utils._ import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.ActorAttributes +import akka.stream.Supervision +import scala.concurrent.Await import scala.concurrent.duration._ class FlowFoldSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() "A Fold" must { val input = 1 to 100 diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala index 25ff4e8dcb..82f879e971 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala @@ -4,17 +4,16 @@ package akka.stream.scaladsl -import scala.util.control.NoStackTrace -import akka.stream.ActorMaterializer -import akka.stream.testkit._ import akka.stream.testkit.Utils._ +import akka.stream.testkit._ import akka.stream.testkit.scaladsl.StreamTestKit._ + import scala.concurrent.Await import scala.concurrent.duration._ +import scala.util.control.NoStackTrace class FlowForeachSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() import system.dispatcher "A runForeach" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala index 28201dc72b..ef4366f2c9 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala @@ -4,20 +4,16 @@ package akka.stream.scaladsl -import scala.concurrent.{ Future, Promise } -import scala.concurrent.duration._ -import scala.util.control.NoStackTrace -import akka.stream.ActorMaterializer -import akka.stream.ActorMaterializerSettings import akka.stream.testkit._ import akka.stream.testkit.scaladsl.StreamTestKit._ +import scala.concurrent.duration._ +import scala.concurrent.Future +import scala.concurrent.Promise +import scala.util.control.NoStackTrace + class FlowFromFutureSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer(settings) - "A Flow based on a Future" must { "produce one element from already successful Future" in assertAllStagesStopped { val c = TestSubscriber.manualProbe[Int]() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala index 19e43e8f3c..ee0a6145ab 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala @@ -4,23 +4,19 @@ package akka.stream.scaladsl -import scala.collection.immutable -import scala.concurrent.duration._ import java.util.concurrent.ThreadLocalRandom.{ current => random } -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings, ThrottleMode } +import akka.stream.ThrottleMode import akka.stream.testkit._ import akka.stream.testkit.scaladsl.StreamTestKit._ - import akka.testkit.TimingTest import akka.util.ConstantFun +import scala.collection.immutable +import scala.concurrent.duration._ + class FlowGroupedWithinSpec extends StreamSpec with ScriptedTest { - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer() - "A GroupedWithin" must { "group elements within the duration" taggedAs TimingTest in assertAllStagesStopped { @@ -168,7 +164,7 @@ class FlowGroupedWithinSpec extends StreamSpec with ScriptedTest { Script(TestConfig.RandomTestRange.map { _ => val x, y, z = random.nextInt(); Seq(x, y, z) -> Seq(immutable.Seq(x, y, z)) }: _*) - TestConfig.RandomTestRange.foreach(_ => runScript(script, settings)(_.groupedWithin(3, 10.minutes))) + TestConfig.RandomTestRange.foreach(_ => runScript(script)(_.groupedWithin(3, 10.minutes))) } "group with rest" taggedAs TimingTest in { @@ -177,7 +173,7 @@ class FlowGroupedWithinSpec extends StreamSpec with ScriptedTest { val x, y, z = random.nextInt(); Seq(x, y, z) -> Seq(immutable.Seq(x, y, z)) } :+ { val x = random.nextInt(); Seq(x) -> Seq(immutable.Seq(x)) }): _*) - TestConfig.RandomTestRange.foreach(_ => runScript(script, settings)(_.groupedWithin(3, 10.minutes))) + TestConfig.RandomTestRange.foreach(_ => runScript(script)(_.groupedWithin(3, 10.minutes))) } "group with small groups with backpressure" taggedAs TimingTest in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowKillSwitchSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowKillSwitchSpec.scala index d875c77b1a..3c02f161e4 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowKillSwitchSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowKillSwitchSpec.scala @@ -6,17 +6,17 @@ package akka.stream.scaladsl import akka.Done import akka.stream.testkit.StreamSpec -import akka.stream.{ ActorMaterializer, ClosedShape, KillSwitches } -import akka.stream.testkit.scaladsl.{ TestSink, TestSource } -import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit.Utils.TE +import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.scaladsl.TestSource +import akka.stream.ClosedShape +import akka.stream.KillSwitches import scala.concurrent.duration._ class FlowKillSwitchSpec extends StreamSpec { - implicit val mat = ActorMaterializer() - "A UniqueKillSwitch" must { "stop a stream if requested" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowLogSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowLogSpec.scala index 2ca473348c..32c9c22052 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowLogSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowLogSpec.scala @@ -22,8 +22,6 @@ class FlowLogSpec extends StreamSpec(""" akka.actor.serialize-messages = off """) with ScriptedTest { - implicit val mat: Materializer = ActorMaterializer() - val logProbe = { val p = TestProbe() system.eventStream.subscribe(p.ref, classOf[Logging.LogEvent]) @@ -32,7 +30,7 @@ class FlowLogSpec extends StreamSpec(""" "A Log" must { - val supervisorPath = ActorMaterializerHelper.downcast(mat).supervisor.path + val supervisorPath = ActorMaterializerHelper.downcast(SystemMaterializer(system).materializer).supervisor.path val LogSrc = s"akka.stream.Log($supervisorPath)" val LogClazz = classOf[Materializer] @@ -70,7 +68,7 @@ class FlowLogSpec extends StreamSpec(""" .log("log-3", new akka.japi.function.Function[Integer, Integer] { def apply(i: Integer) = i }, log) .log("log-4", log) - javadsl.Source.single[Integer](1).via(debugging).runWith(javadsl.Sink.ignore(), mat) + javadsl.Source.single[Integer](1).via(debugging).runWith(javadsl.Sink.ignore[Integer](), system) var counter = 0 var finishCounter = 0 @@ -163,7 +161,7 @@ class FlowLogSpec extends StreamSpec(""" .log("log-2", new akka.japi.function.Function[Integer, Integer] { def apply(i: Integer) = i }) .log("log-3", new akka.japi.function.Function[Integer, Integer] { def apply(i: Integer) = i }, log) .log("log-4", log) - .runWith(javadsl.Sink.ignore(), mat) + .runWith(javadsl.Sink.ignore[Integer](), system) var counter = 1 import scala.concurrent.duration._ diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala index 043e69bd0c..8785ccc81d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala @@ -4,28 +4,31 @@ package akka.stream.scaladsl -import java.util.concurrent.{ LinkedBlockingQueue, ThreadLocalRandom } import java.util.concurrent.atomic.AtomicInteger +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.ThreadLocalRandom import akka.stream.ActorAttributes.supervisionStrategy -import akka.stream.{ ActorAttributes, ActorMaterializer, Supervision } import akka.stream.Supervision.resumingDecider import akka.stream.testkit.Utils._ -import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit.scaladsl.TestSink -import akka.testkit.{ TestLatch, TestProbe } +import akka.stream.ActorAttributes +import akka.stream.Supervision +import akka.testkit.TestLatch +import akka.testkit.TestProbe import org.scalatest.concurrent.PatienceConfiguration.Timeout import scala.annotation.tailrec -import scala.concurrent.{ Await, Future, Promise } import scala.concurrent.duration._ +import scala.concurrent.Await +import scala.concurrent.Future +import scala.concurrent.Promise import scala.util.control.NoStackTrace class FlowMapAsyncSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A Flow with mapAsync" must { "produce future elements" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala index 02ef828d06..67431c8a95 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala @@ -4,30 +4,27 @@ package akka.stream.scaladsl -import scala.concurrent.Await -import scala.concurrent.Future -import scala.concurrent.duration._ -import scala.util.control.NoStackTrace -import akka.stream.ActorMaterializer -import akka.stream.testkit._ -import akka.stream.testkit.scaladsl._ -import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.testkit.TestLatch -import akka.testkit.TestProbe -import akka.stream.ActorAttributes.supervisionStrategy -import akka.stream.Supervision.resumingDecider +import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.atomic.AtomicInteger -import scala.concurrent.Promise -import java.util.concurrent.LinkedBlockingQueue +import akka.stream.ActorAttributes.supervisionStrategy +import akka.stream.Supervision.resumingDecider +import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.testkit.scaladsl._ +import akka.testkit.TestLatch +import akka.testkit.TestProbe import org.scalatest.concurrent.PatienceConfiguration.Timeout import scala.annotation.tailrec +import scala.concurrent.Await +import scala.concurrent.Future +import scala.concurrent.Promise +import scala.concurrent.duration._ +import scala.util.control.NoStackTrace class FlowMapAsyncUnorderedSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A Flow with mapAsyncUnordered" must { "produce future elements in the order they are ready" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMonitorSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMonitorSpec.scala index 6d843cf3a3..381f8486ba 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMonitorSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMonitorSpec.scala @@ -4,19 +4,17 @@ package akka.stream.scaladsl -import akka.stream.testkit.StreamSpec -import akka.stream.testkit.scaladsl.{ TestSink, TestSource } -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings, FlowMonitorState } import akka.stream.FlowMonitorState._ +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.scaladsl.TestSource +import akka.stream.ActorMaterializer +import akka.stream.FlowMonitorState import scala.concurrent.duration._ class FlowMonitorSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer(settings) - "A FlowMonitor" must { "return Finished when stream is completed" in { val ((source, monitor), sink) = diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOrElseSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOrElseSpec.scala index 80e8c38254..5fdcba6678 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOrElseSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOrElseSpec.scala @@ -4,23 +4,16 @@ package akka.stream.scaladsl -//#or-else - -//#or-else -import scala.concurrent.duration._ import akka.stream.testkit.Utils.TE -import akka.stream.testkit.{ TestPublisher, TestSubscriber } -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber import akka.testkit.AkkaSpec import scala.collection.immutable.Seq +import scala.concurrent.duration._ class FlowOrElseSpec extends AkkaSpec { - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer(settings) - "An OrElse flow" should { "pass elements from the first input" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrependSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrependSpec.scala index 32bfd69853..0cd2ab2919 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrependSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrependSpec.scala @@ -4,7 +4,6 @@ package akka.stream.scaladsl -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } import akka.testkit.AkkaSpec import com.github.ghik.silencer.silent @@ -12,15 +11,9 @@ import com.github.ghik.silencer.silent class FlowPrependSpec extends AkkaSpec { //#prepend - import akka.stream.scaladsl.Source - import akka.stream.scaladsl.Sink //#prepend - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer(settings) - "An Prepend flow" should { "work in entrance example" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowReduceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowReduceSpec.scala index 777231962d..87b47cc59e 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowReduceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowReduceSpec.scala @@ -5,16 +5,15 @@ package akka.stream.scaladsl import akka.stream.testkit.StreamSpec - -import scala.concurrent.Await -import akka.stream.{ ActorAttributes, ActorMaterializer, Supervision } import akka.stream.testkit.Utils._ import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.ActorAttributes +import akka.stream.Supervision +import scala.concurrent.Await import scala.concurrent.duration._ class FlowReduceSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() "A Reduce" must { val input = 1 to 100 diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowScanAsyncSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowScanAsyncSpec.scala index 2081fbb0a3..17e589c8d8 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowScanAsyncSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowScanAsyncSpec.scala @@ -5,23 +5,25 @@ package akka.stream.scaladsl import akka.pattern -import akka.stream.{ ActorAttributes, ActorMaterializer, Supervision } import akka.stream.impl.ReactiveStreamsCompliance import akka.stream.testkit.TestSubscriber.Probe import akka.stream.testkit.Utils.TE import akka.stream.testkit._ import akka.stream.testkit.scaladsl._ import org.scalatest.Matchers +import akka.stream.ActorAttributes +import akka.stream.Supervision import scala.collection.immutable import scala.concurrent.duration._ import scala.concurrent.{ Future, Promise } +import scala.concurrent.Future +import scala.concurrent.Promise import scala.util.Failure class FlowScanAsyncSpec extends StreamSpec with Matchers { - implicit val materializer: ActorMaterializer = ActorMaterializer() - implicit val executionContext = materializer.executionContext + implicit val executionContext = system.dispatcher "A ScanAsync" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSectionSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSectionSpec.scala index 01b15edfe2..df0d071f4a 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSectionSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSectionSpec.scala @@ -4,11 +4,10 @@ package akka.stream.scaladsl -import akka.stream.Attributes._ -import akka.stream.ActorAttributes._ -import akka.stream.ActorMaterializer -import akka.stream.testkit.StreamSpec import akka.actor.ActorRef +import akka.stream.ActorAttributes._ +import akka.stream.Attributes._ +import akka.stream.testkit.StreamSpec import akka.testkit.TestProbe object FlowSectionSpec { @@ -21,8 +20,6 @@ object FlowSectionSpec { class FlowSectionSpec extends StreamSpec(FlowSectionSpec.config) { - implicit val materializer = ActorMaterializer() - "A flow".can { "have an op with a different dispatcher" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSupervisionSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSupervisionSpec.scala index c9cc7cb309..dfcd8b2e21 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSupervisionSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSupervisionSpec.scala @@ -4,22 +4,20 @@ package akka.stream.scaladsl -import scala.collection.immutable -import scala.concurrent.duration._ -import akka.stream.ActorMaterializer -import akka.stream.testkit._ -import scala.util.control.NoStackTrace -import scala.concurrent.Await +import akka.NotUsed +import akka.stream.ActorAttributes import akka.stream.Supervision import akka.stream.impl.ReactiveStreamsCompliance -import akka.stream.ActorAttributes -import akka.NotUsed +import akka.stream.testkit._ + +import scala.collection.immutable +import scala.concurrent.Await +import scala.concurrent.duration._ +import scala.util.control.NoStackTrace class FlowSupervisionSpec extends StreamSpec { import ActorAttributes.supervisionStrategy - implicit val materializer = ActorMaterializer()(system) - val exc = new RuntimeException("simulated exc") with NoStackTrace val failingMap = Flow[Int].map(n => if (n == 3) throw exc else n) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWhileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWhileSpec.scala index 6e2e44b4d7..c01e9ba49d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWhileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWhileSpec.scala @@ -6,19 +6,14 @@ package akka.stream.scaladsl import akka.stream.ActorAttributes._ import akka.stream.Supervision._ -import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.stream.ActorMaterializer -import akka.stream.ActorMaterializerSettings import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit.scaladsl.TestSink + import scala.util.control.NoStackTrace class FlowTakeWhileSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer(settings) - "A TakeWhile" must { "take while predicate is true" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala index dd0615b91c..a56ef843d4 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala @@ -4,14 +4,12 @@ package akka.stream.scaladsl -import scala.concurrent.duration._ -import akka.stream.ActorMaterializer import akka.stream.testkit._ import akka.stream.testkit.scaladsl.StreamTestKit._ -class FlowTakeWithinSpec extends StreamSpec { +import scala.concurrent.duration._ - implicit val materializer = ActorMaterializer() +class FlowTakeWithinSpec extends StreamSpec { "A TakeWithin" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchSpec.scala index ee790be392..f1c8258a09 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchSpec.scala @@ -4,10 +4,11 @@ package akka.stream.scaladsl -import akka.actor.{ Actor, PoisonPill, Props } -import akka.stream.ActorMaterializer -import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.actor.Actor +import akka.actor.PoisonPill +import akka.actor.Props import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.testkit.TestActors import scala.concurrent.Await @@ -27,8 +28,6 @@ object FlowWatchSpec { class FlowWatchSpec extends StreamSpec { import FlowWatchSpec._ - implicit val materializer = ActorMaterializer() - "A Flow with watch" must { val replyOnInts = diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchTerminationSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchTerminationSpec.scala index f58c16cbca..2ead33158f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchTerminationSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWatchTerminationSpec.scala @@ -9,17 +9,14 @@ import akka.pattern.pipe import akka.stream._ import akka.stream.testkit.StreamSpec import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.stream.testkit.scaladsl.{ TestSink, TestSource } +import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.scaladsl.TestSource -import scala.util.control.NoStackTrace import scala.concurrent.duration._ +import scala.util.control.NoStackTrace class FlowWatchTerminationSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - - implicit val materializer = ActorMaterializer(settings) - "A WatchTermination" must { "complete future when stream is completed" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWireTapSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWireTapSpec.scala index 30f9b327a8..34032d1825 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWireTapSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWireTapSpec.scala @@ -5,15 +5,14 @@ package akka.stream.scaladsl import akka.Done -import akka.stream.ActorMaterializer import akka.stream.testkit.Utils._ -import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ import scala.util.control.NoStackTrace class FlowWireTapSpec extends StreamSpec("akka.stream.materializer.debug.fuzzing-mode = off") { - implicit val materializer = ActorMaterializer() + import system.dispatcher "A wireTap" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextLogSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextLogSpec.scala index 6161775b6c..4013e1ea37 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextLogSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextLogSpec.scala @@ -6,8 +6,9 @@ package akka.stream.scaladsl import akka.event.Logging import akka.stream.Attributes.LogLevels -import akka.stream.testkit.{ ScriptedTest, StreamSpec } import akka.stream._ +import akka.stream.testkit.ScriptedTest +import akka.stream.testkit.StreamSpec import akka.testkit.TestProbe class FlowWithContextLogSpec extends StreamSpec(""" @@ -15,8 +16,6 @@ class FlowWithContextLogSpec extends StreamSpec(""" akka.actor.serialize-messages = off """) with ScriptedTest { - implicit val mat: Materializer = ActorMaterializer() - val logProbe = { val p = TestProbe() system.eventStream.subscribe(p.ref, classOf[Logging.LogEvent]) @@ -25,7 +24,7 @@ class FlowWithContextLogSpec extends StreamSpec(""" "log() from FlowWithContextOps" must { - val supervisorPath = ActorMaterializerHelper.downcast(mat).supervisor.path + val supervisorPath = ActorMaterializerHelper.downcast(SystemMaterializer(system).materializer).supervisor.path val LogSrc = s"akka.stream.Log($supervisorPath)" val LogClazz = classOf[Materializer] diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextSpec.scala index 72b02563f5..174a49429f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowWithContextSpec.scala @@ -4,15 +4,11 @@ package akka.stream.scaladsl -import akka.stream.testkit.scaladsl.TestSink -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } import akka.stream.testkit.StreamSpec +import akka.stream.testkit.scaladsl.TestSink class FlowWithContextSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) - "A FlowWithContext" must { "get created from Flow.asFlowWithContext" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FramingSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FramingSpec.scala index 574c7211d5..07c3f5fed4 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FramingSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FramingSpec.scala @@ -9,9 +9,14 @@ import java.util.concurrent.ThreadLocalRandom import akka.stream._ import akka.stream.scaladsl.Framing.FramingException -import akka.stream.stage.{ GraphStage, _ } -import akka.stream.testkit.{ StreamSpec, TestPublisher, TestSubscriber } -import akka.util.{ unused, ByteString, ByteStringBuilder } +import akka.stream.stage.GraphStage +import akka.stream.stage._ +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber +import akka.util.ByteString +import akka.util.ByteStringBuilder +import akka.util.unused import scala.collection.immutable import scala.concurrent.Future @@ -20,9 +25,6 @@ import scala.util.Random class FramingSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) - class Rechunker extends GraphStage[FlowShape[ByteString, ByteString]] { val out: Outlet[ByteString] = Outlet("Rechunker.out") diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FutureFlattenSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FutureFlattenSourceSpec.scala index 01f193a0ec..be269cd1bc 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FutureFlattenSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FutureFlattenSourceSpec.scala @@ -17,7 +17,6 @@ import scala.concurrent.{ Await, Future, Promise } class FutureFlattenSourceSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() implicit def ec = system.dispatcher "Future source" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphDSLCompileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphDSLCompileSpec.scala index 362ad5249a..23aed61c96 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphDSLCompileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphDSLCompileSpec.scala @@ -19,8 +19,6 @@ object GraphDSLCompileSpec { class GraphDSLCompileSpec extends StreamSpec { import GraphDSLCompileSpec._ - implicit val materializer = ActorMaterializer() - def op[In, Out] = new GraphStage[FlowShape[In, Out]] { val in = Inlet[In]("op.in") val out = Outlet[Out]("op.out") diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala index 97eccd224c..210637f7bc 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala @@ -5,18 +5,20 @@ package akka.stream.scaladsl import akka.actor.ActorRef -import akka.stream.{ ActorMaterializer, Attributes } +import akka.stream.Attributes import akka.stream.impl.fusing.GraphStages.SimpleLinearGraphStage -import akka.stream.stage.{ AsyncCallback, InHandler, OutHandler, TimerGraphStageLogic } +import akka.stream.stage.AsyncCallback +import akka.stream.stage.InHandler +import akka.stream.stage.OutHandler +import akka.stream.stage.TimerGraphStageLogic +import akka.stream.testkit.Utils._ +import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.testkit.TestDuration import scala.concurrent.Promise import scala.concurrent.duration._ -import akka.stream.testkit._ -import akka.stream.testkit.Utils._ -import akka.stream.testkit.scaladsl.StreamTestKit._ - object GraphStageTimersSpec { case object TestSingleTimer case object TestSingleTimerResubmit @@ -40,8 +42,6 @@ object GraphStageTimersSpec { class GraphStageTimersSpec extends StreamSpec { import GraphStageTimersSpec._ - implicit val materializer = ActorMaterializer() - class TestStage(probe: ActorRef, sideChannel: SideChannel) extends SimpleLinearGraphStage[Int] { override def createLogic(inheritedAttributes: Attributes) = new TimerGraphStageLogic(shape) { val tickCount = Iterator.from(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipLatestSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipLatestSpec.scala index f50329cd62..cdfb88d505 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipLatestSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipLatestSpec.scala @@ -4,11 +4,14 @@ package akka.stream.scaladsl +import akka.stream.ClosedShape import akka.stream.testkit.TestPublisher.Probe -import akka.stream.testkit.scaladsl.{ TestSink, TestSource } -import akka.stream.testkit.{ StreamSpec, TestPublisher, TestSubscriber } -import akka.stream.{ ActorMaterializer, ClosedShape } import akka.stream.testkit.scaladsl.StreamTestKit.assertAllStagesStopped +import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.scaladsl.TestSource +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber import org.scalacheck.Gen import org.scalatest.concurrent.ScalaFutures import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks @@ -24,8 +27,6 @@ object GraphZipLatestSpec { class GraphZipLatestSpec extends StreamSpec with ScalaCheckPropertyChecks with ScalaFutures { import GraphZipLatestSpec._ - implicit val materializer = ActorMaterializer() - "ZipLatest" must { "only emit when at least one pair is available" in assertAllStagesStopped { val (probe, bools, ints) = testGraph[Boolean, Int] diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HubSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HubSpec.scala index 0a7891e8a1..898d488919 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HubSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HubSpec.scala @@ -4,11 +4,15 @@ package akka.stream.scaladsl -import akka.stream.{ ActorMaterializer, KillSwitches, ThrottleMode } -import akka.stream.testkit.{ StreamSpec, TestPublisher, TestSubscriber } import akka.stream.testkit.Utils.TE -import akka.stream.testkit.scaladsl.{ TestSink, TestSource } import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.scaladsl.TestSource +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber +import akka.stream.KillSwitches +import akka.stream.ThrottleMode import akka.testkit.EventFilter import scala.collection.immutable @@ -17,8 +21,6 @@ import scala.concurrent.duration._ class HubSpec extends StreamSpec { - implicit val mat = ActorMaterializer() - "MergeHub" must { "work in the happy case" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/JsonFramingSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/JsonFramingSpec.scala index d177cfe56b..c3ed738449 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/JsonFramingSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/JsonFramingSpec.scala @@ -4,11 +4,11 @@ package akka.stream.scaladsl -import akka.stream.ActorMaterializer import akka.stream.impl.JsonObjectParser import akka.stream.scaladsl.Framing.FramingException -import akka.stream.testkit.{ TestPublisher, TestSubscriber } import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber import akka.testkit.AkkaSpec import akka.util.ByteString @@ -18,8 +18,6 @@ import scala.concurrent.duration._ class JsonFramingSpec extends AkkaSpec { - implicit val mat = ActorMaterializer() - "collecting multiple json" should { "parse json array" in { // #using-json-framing diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LastSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LastSinkSpec.scala index ae2d09895e..acbddec176 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LastSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LastSinkSpec.scala @@ -4,18 +4,15 @@ package akka.stream.scaladsl -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } import akka.stream.testkit._ import akka.stream.testkit.scaladsl.StreamTestKit._ import scala.concurrent.duration._ -import scala.concurrent.{ Await, Future } +import scala.concurrent.Await +import scala.concurrent.Future class LastSinkSpec extends StreamSpec with ScriptedTest { - val settings = ActorMaterializerSettings(system) - - implicit val materializer: ActorMaterializer = ActorMaterializer(settings) implicit val ec = system.dispatcher "A Flow with Sink.last" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazilyAsyncSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazilyAsyncSpec.scala index ac1d9d7ad7..b98269b341 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazilyAsyncSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazilyAsyncSpec.scala @@ -7,9 +7,9 @@ package akka.stream.scaladsl import java.util.concurrent.atomic.AtomicBoolean import akka.Done -import akka.stream.ActorMaterializer -import akka.stream.testkit.{ StreamSpec, TestSubscriber } import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestSubscriber import akka.testkit.DefaultTimeout import org.scalatest.concurrent.ScalaFutures @@ -17,9 +17,7 @@ import scala.concurrent.Future class LazilyAsyncSpec extends StreamSpec with DefaultTimeout with ScalaFutures { - private implicit val mat: ActorMaterializer = ActorMaterializer() - - import mat.executionContext + import system.dispatcher "A lazy async source" should { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazySourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazySourceSpec.scala index 2556b40a69..e50454a8ab 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazySourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/LazySourceSpec.scala @@ -8,11 +8,16 @@ import java.util.concurrent.atomic.AtomicBoolean import akka.Done import akka.stream.impl.LazySource -import akka.stream.stage.{ GraphStage, GraphStageLogic } +import akka.stream.stage.GraphStage +import akka.stream.stage.GraphStageLogic import akka.stream.testkit.Utils.TE import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.stream.testkit.{ StreamSpec, TestPublisher, TestSubscriber } -import akka.stream.{ ActorMaterializer, Attributes, Outlet, SourceShape } +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber +import akka.stream.Attributes +import akka.stream.Outlet +import akka.stream.SourceShape import akka.testkit.DefaultTimeout import org.scalatest.concurrent.ScalaFutures @@ -21,8 +26,6 @@ import scala.concurrent.Future class LazySourceSpec extends StreamSpec with DefaultTimeout with ScalaFutures { - implicit val materializer = ActorMaterializer() - "A lazy source" should { "work like a normal source, happy path" in assertAllStagesStopped { val result = Source.fromGraph(LazySource(() => Source(List(1, 2, 3)))).runWith(Sink.seq) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/MaybeSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/MaybeSourceSpec.scala index 3e9b7bfadd..23a48971d1 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/MaybeSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/MaybeSourceSpec.scala @@ -4,9 +4,11 @@ package akka.stream.scaladsl -import akka.stream.{ AbruptStageTerminationException, ActorMaterializer } -import akka.stream.testkit.{ StreamSpec, TestSubscriber } import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestSubscriber +import akka.stream.AbruptStageTerminationException +import akka.stream.ActorMaterializer import akka.testkit.DefaultTimeout import scala.concurrent.duration._ @@ -14,8 +16,6 @@ import scala.util.control.NoStackTrace class MaybeSourceSpec extends StreamSpec with DefaultTimeout { - implicit val materializer = ActorMaterializer() - "The Maybe Source" must { "complete materialized future with None when stream cancels" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala index 02796d9abb..b970593cc5 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala @@ -4,18 +4,15 @@ package akka.stream.scaladsl +import akka.stream.ClosedShape import akka.stream.testkit.StreamSpec -import akka.stream.{ ActorMaterializer, ClosedShape } - import akka.stream.testkit.scaladsl.StreamTestKit._ -import scala.concurrent.duration._ import scala.concurrent.Await +import scala.concurrent.duration._ class PublisherSinkSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A PublisherSink" must { "be unique when created twice" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/QueueSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/QueueSinkSpec.scala index 7be285c850..82efdea38b 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/QueueSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/QueueSinkSpec.scala @@ -7,17 +7,17 @@ package akka.stream.scaladsl import akka.actor.Status import akka.pattern.pipe import akka.stream.Attributes.inputBuffer -import akka.stream.{ ActorMaterializer, StreamDetachedException } -import akka.stream.testkit.scaladsl.StreamTestKit._ +import akka.stream.StreamDetachedException import akka.stream.testkit._ +import akka.stream.testkit.scaladsl.StreamTestKit._ -import scala.concurrent.{ Await, Promise } import scala.concurrent.duration._ +import scala.concurrent.Await +import scala.concurrent.Promise import scala.util.control.NoStackTrace class QueueSinkSpec extends StreamSpec { implicit val ec = system.dispatcher - implicit val materializer = ActorMaterializer() val ex = new RuntimeException("ex") with NoStackTrace diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RestartSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RestartSpec.scala index 036b5ef723..e2282a6e60 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RestartSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RestartSpec.scala @@ -7,22 +7,27 @@ package akka.stream.scaladsl import java.util.concurrent.atomic.AtomicInteger import akka.stream.scaladsl.RestartWithBackoffFlow.Delay -import akka.stream.testkit.{ StreamSpec, TestPublisher, TestSubscriber } import akka.stream.testkit.Utils.TE -import akka.stream.testkit.scaladsl.{ TestSink, TestSource } import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.stream.{ ActorMaterializer, Attributes, OverflowStrategy } -import akka.testkit.{ DefaultTimeout, TestDuration } -import akka.{ Done, NotUsed } +import akka.stream.testkit.scaladsl.TestSink +import akka.stream.testkit.scaladsl.TestSource +import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.TestSubscriber +import akka.stream.Attributes +import akka.stream.OverflowStrategy +import akka.testkit.DefaultTimeout +import akka.testkit.TestDuration +import akka.Done +import akka.NotUsed import scala.concurrent.Promise import scala.concurrent.duration._ -import scala.util.{ Failure, Success } +import scala.util.Failure +import scala.util.Success class RestartSpec extends StreamSpec(Map("akka.test.single-expect-default" -> "10s")) with DefaultTimeout { - implicit val mat = ActorMaterializer() - import system.dispatcher private val shortMinBackoff = 10.millis diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala index a82efb5729..510a49c4a9 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala @@ -4,15 +4,15 @@ package akka.stream.scaladsl -import akka.stream.testkit._ import akka.stream._ +import akka.stream.testkit._ + import scala.concurrent.Await import scala.concurrent.duration._ class ReverseArrowSpec extends StreamSpec { import GraphDSL.Implicits._ - implicit val materializer = ActorMaterializer() val source = Source(List(1, 2, 3)) val sink = Flow[Int].limit(10).toMat(Sink.seq)(Keep.right) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RunnableGraphSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RunnableGraphSpec.scala index 2285462e44..6300e743ad 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RunnableGraphSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/RunnableGraphSpec.scala @@ -5,14 +5,12 @@ package akka.stream.scaladsl import akka.NotUsed -import akka.stream.{ ActorMaterializer, Attributes } -import akka.stream.testkit.StreamSpec +import akka.stream.Attributes import akka.stream.javadsl +import akka.stream.testkit.StreamSpec class RunnableGraphSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A RunnableGraph" must { "suitably override attribute handling methods" in { @@ -26,7 +24,7 @@ class RunnableGraphSpec extends StreamSpec { "allow conversion from scala to java" in { val runnable: javadsl.RunnableGraph[NotUsed] = Source.empty.to(Sink.ignore).asJava - runnable.run(materializer) shouldBe NotUsed + runnable.run(system) shouldBe NotUsed } "allow conversion from java to scala" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SetupSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SetupSpec.scala index 477b88ab1e..9832c22690 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SetupSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SetupSpec.scala @@ -5,12 +5,10 @@ package akka.stream.scaladsl import akka.NotUsed -import akka.stream.ActorMaterializer import akka.stream.testkit.StreamSpec class SetupSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() import system.dispatcher "Source.setup" should { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachAsyncSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachAsyncSpec.scala index e93791e869..7adc8a7b5e 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachAsyncSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachAsyncSpec.scala @@ -4,23 +4,27 @@ package akka.stream.scaladsl -import java.util.concurrent.{ CountDownLatch, Executors, TimeUnit } +import java.util.concurrent.CountDownLatch +import java.util.concurrent.Executors +import java.util.concurrent.TimeUnit import akka.Done import akka.stream.ActorAttributes.supervisionStrategy -import akka.stream.ActorMaterializer -import akka.stream.Supervision.{ resumingDecider, stoppingDecider } +import akka.stream.Supervision.resumingDecider +import akka.stream.Supervision.stoppingDecider import akka.stream.testkit.StreamSpec import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.testkit.{ TestLatch, TestProbe } +import akka.testkit.TestLatch +import akka.testkit.TestProbe import scala.concurrent.duration._ -import scala.concurrent.{ Await, ExecutionContext, Future } +import scala.concurrent.Await +import scala.concurrent.ExecutionContext +import scala.concurrent.Future import scala.language.postfixOps import scala.util.control.NoStackTrace class SinkForeachAsyncSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() "A foreachAsync" must { "handle empty source" in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachParallelSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachParallelSpec.scala index 54d34944e8..740159b48a 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachParallelSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkForeachParallelSpec.scala @@ -4,14 +4,15 @@ package akka.stream.scaladsl -import java.util.concurrent.{ CountDownLatch, TimeUnit } +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit -import akka.stream.ActorMaterializer import akka.stream.ActorAttributes._ import akka.stream.Supervision._ import akka.stream.testkit.StreamSpec import akka.stream.testkit.scaladsl.StreamTestKit._ -import akka.testkit.{ TestLatch, TestProbe } +import akka.testkit.TestLatch +import akka.testkit.TestProbe import com.github.ghik.silencer.silent import scala.concurrent.Await @@ -21,8 +22,6 @@ import scala.util.control.NoStackTrace @silent // tests deprecated APIs class SinkForeachParallelSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A ForeachParallel" must { "produce elements in the order they are ready" in assertAllStagesStopped { import system.dispatcher diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala index 11da3a8f5e..6bee83c124 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala @@ -20,8 +20,6 @@ class SinkSpec extends StreamSpec with DefaultTimeout with ScalaFutures { import GraphDSL.Implicits._ - implicit val materializer = ActorMaterializer() - "A Sink" must { "be composable without importing modules" in { val probes = Array.fill(3)(TestSubscriber.manualProbe[Int]) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala index debe5852da..c13370ffb5 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala @@ -4,27 +4,27 @@ package akka.stream.scaladsl +import akka.stream.testkit.Utils.TE import akka.testkit.DefaultTimeout -import org.scalatest.time.{ Millis, Span } +import com.github.ghik.silencer.silent +import org.scalatest.time.Millis +import org.scalatest.time.Span import scala.concurrent.Future -import akka.stream.testkit.Utils.TE -import com.github.ghik.silencer.silent //#imports import akka.stream._ //#imports -import akka.stream.testkit._ import akka.NotUsed -import akka.testkit.EventFilter -import scala.collection.immutable - +import akka.stream.testkit._ import akka.stream.testkit.scaladsl.TestSink +import akka.testkit.EventFilter + +import scala.collection.immutable @silent // tests assigning to typed val class SourceSpec extends StreamSpec with DefaultTimeout { - implicit val materializer = ActorMaterializer() implicit val config = PatienceConfig(timeout = Span(timeout.duration.toMillis, Millis)) "Single Source" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceWithContextSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceWithContextSpec.scala index 702bb4dd9a..2c65d418d7 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceWithContextSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceWithContextSpec.scala @@ -4,17 +4,13 @@ package akka.stream.scaladsl -import akka.stream.testkit.scaladsl.TestSink -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } import akka.stream.testkit.StreamSpec +import akka.stream.testkit.scaladsl.TestSink case class Message(data: String, offset: Long) class SourceWithContextSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) - "A SourceWithContext" must { "get created from Source.asSourceWithContext" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StageActorRefSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StageActorRefSpec.scala index ec3d65a41e..af15a6ce38 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StageActorRefSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StageActorRefSpec.scala @@ -4,19 +4,26 @@ package akka.stream.scaladsl -import akka.actor.{ ActorRef, Kill, NoSerializationVerificationNeeded, PoisonPill } +import akka.actor.ActorRef +import akka.actor.Kill +import akka.actor.NoSerializationVerificationNeeded +import akka.actor.PoisonPill import akka.event.Logging import akka.stream._ -import akka.stream.stage.{ GraphStageLogic, GraphStageWithMaterializedValue, InHandler } +import akka.stream.stage.GraphStageLogic +import akka.stream.stage.GraphStageWithMaterializedValue +import akka.stream.stage.InHandler import akka.stream.testkit.StreamSpec -import akka.testkit.{ EventFilter, ImplicitSender, TestEvent, TestProbe } +import akka.testkit.EventFilter +import akka.testkit.ImplicitSender +import akka.testkit.TestEvent +import akka.testkit.TestProbe -import scala.concurrent.{ Future, Promise } import scala.concurrent.duration._ +import scala.concurrent.Future +import scala.concurrent.Promise class StageActorRefSpec extends StreamSpec with ImplicitSender { - implicit val materializer = ActorMaterializer() - import StageActorRefSpec._ import ControlProtocol._ diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamConvertersSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamConvertersSpec.scala index 22605f1446..e17df6ccd1 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamConvertersSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamConvertersSpec.scala @@ -5,27 +5,33 @@ package akka.stream.scaladsl import java.util -import java.util.function.{ BiConsumer, BinaryOperator, Supplier, ToIntFunction } +import java.util.function.BiConsumer +import java.util.function.BinaryOperator +import java.util.function.Supplier +import java.util.function.ToIntFunction import java.util.stream.Collector.Characteristics -import java.util.stream.{ BaseStream, Collector, Collectors } +import java.util.stream.BaseStream +import java.util.stream.Collector +import java.util.stream.Collectors -import akka.stream.ActorMaterializer import akka.stream.testkit.StreamSpec import akka.stream.testkit.Utils.TE import akka.testkit.DefaultTimeout -import org.scalatest.time.{ Millis, Span } +import org.scalatest.time.Millis +import org.scalatest.time.Span import scala.concurrent.Await import scala.concurrent.duration._ class StreamConvertersSpec extends StreamSpec with DefaultTimeout { - implicit val materializer = ActorMaterializer() implicit val config = PatienceConfig(timeout = Span(timeout.duration.toMillis, Millis)) "Java Stream source" must { + import java.util.stream.IntStream + import java.util.stream.Stream + import scala.compat.java8.FunctionConverters._ - import java.util.stream.{ IntStream, Stream } def javaStreamInts = IntStream.iterate(1, { i: Int => diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamRefsSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamRefsSpec.scala index e4866060df..9215446890 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamRefsSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/StreamRefsSpec.scala @@ -5,21 +5,32 @@ package akka.stream.scaladsl import akka.NotUsed +import akka.actor.Actor +import akka.actor.ActorIdentity +import akka.actor.ActorLogging +import akka.actor.ActorRef +import akka.actor.ActorSystem +import akka.actor.ActorSystemImpl +import akka.actor.Identify +import akka.actor.Props import akka.actor.Status.Failure -import akka.actor.{ Actor, ActorIdentity, ActorLogging, ActorRef, ActorSystem, ActorSystemImpl, Identify, Props } import akka.pattern._ -import akka.stream.testkit.TestPublisher -import akka.stream.testkit.scaladsl._ import akka.stream._ import akka.stream.impl.streamref.SinkRefImpl import akka.stream.impl.streamref.SourceRefImpl -import akka.testkit.{ AkkaSpec, ImplicitSender, TestKit, TestProbe } +import akka.stream.testkit.TestPublisher +import akka.stream.testkit.scaladsl._ +import akka.testkit.AkkaSpec +import akka.testkit.ImplicitSender +import akka.testkit.TestKit +import akka.testkit.TestProbe import akka.util.ByteString import com.typesafe.config._ import scala.collection.immutable +import scala.concurrent.Await +import scala.concurrent.Future import scala.concurrent.duration._ -import scala.concurrent.{ Await, Future } import scala.util.control.NoStackTrace object StreamRefsSpec { @@ -30,7 +41,8 @@ object StreamRefsSpec { } class DataSourceActor(probe: ActorRef) extends Actor with ActorLogging { - implicit val mat = ActorMaterializer() + + import context.system def receive = { case "give" => @@ -177,7 +189,6 @@ class StreamRefsSpec extends AkkaSpec(StreamRefsSpec.config()) with ImplicitSend import StreamRefsSpec._ val remoteSystem = ActorSystem("RemoteSystem", StreamRefsSpec.config()) - implicit val mat = ActorMaterializer() override protected def beforeTermination(): Unit = TestKit.shutdownActorSystem(remoteSystem) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala index a9d2b5c8bc..05fb59446f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala @@ -4,17 +4,13 @@ package akka.stream.scaladsl -import akka.stream.ActorMaterializer import akka.stream.testkit.StreamSpec +import scala.concurrent.Await import scala.concurrent.duration._ -import scala.concurrent.Await - class SubscriberSourceSpec extends StreamSpec { - implicit val materializer = ActorMaterializer() - "A SubscriberSource" must { "be able to use Subscriber in materialized value transformation" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala index ec140268a8..3b160feeea 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala @@ -4,15 +4,14 @@ package akka.stream.scaladsl -import scala.concurrent.duration._ -import akka.stream.{ ActorMaterializer, ClosedShape } +import akka.stream.ClosedShape import akka.stream.testkit._ import akka.stream.testkit.scaladsl.StreamTestKit._ import akka.testkit.TimingTest -class TickSourceSpec extends StreamSpec { +import scala.concurrent.duration._ - implicit val materializer = ActorMaterializer() +class TickSourceSpec extends StreamSpec { "A Flow based on tick publisher" must { "produce ticks" taggedAs TimingTest in assertAllStagesStopped { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/WithContextUsageSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/WithContextUsageSpec.scala index 0b21640d50..2014e30d6b 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/WithContextUsageSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/WithContextUsageSpec.scala @@ -4,18 +4,15 @@ package akka.stream.scaladsl -import scala.collection.immutable import akka.NotUsed -import akka.stream.testkit.scaladsl.TestSink -import akka.stream.testkit.TestSubscriber.Probe -import akka.stream.{ ActorMaterializer, ActorMaterializerSettings } import akka.stream.testkit.StreamSpec +import akka.stream.testkit.TestSubscriber.Probe +import akka.stream.testkit.scaladsl.TestSink + +import scala.collection.immutable class WithContextUsageSpec extends StreamSpec { - val settings = ActorMaterializerSettings(system) - implicit val materializer = ActorMaterializer(settings) - "Context propagation used for committing offsets" must { "be able to commit on offset change" in { diff --git a/akka-stream-tests/src/test/scala/akka/stream/snapshot/MaterializerStateSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/snapshot/MaterializerStateSpec.scala index 7dc193c5bf..0f4ce7723a 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/snapshot/MaterializerStateSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/snapshot/MaterializerStateSpec.scala @@ -9,6 +9,8 @@ import akka.stream.scaladsl.{ Flow, GraphDSL, Keep, Merge, Partition, Sink, Sour import akka.stream.testkit.scaladsl.TestSink import akka.stream.testkit.StreamSpec +import scala.concurrent.Promise + class MaterializerStateSpec extends StreamSpec { "The MaterializerSnapshotting" must { @@ -30,6 +32,20 @@ class MaterializerStateSpec extends StreamSpec { } } + "snapshot a running stream on the default dispatcher" in { + val promise = Promise[Int]() + Source.fromFuture(promise.future).map(_.toString).zipWithIndex.runWith(Sink.seq) + + awaitAssert({ + val snapshot = MaterializerState.streamSnapshots(system).futureValue + + snapshot should have size (1) + snapshot.head.activeInterpreters should have size (1) + snapshot.head.activeInterpreters.head.logics should have size (4) // all 4 operators + }, remainingOrDefault) + promise.success(1) + } + "snapshot a stream that has a stopped stage" in { implicit val mat = ActorMaterializer() try { diff --git a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala index 7dc7fdd5a0..8b409eff45 100644 --- a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala +++ b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala @@ -27,8 +27,6 @@ object ActorFlowSpec { class ActorFlowSpec extends ScalaTestWithActorTestKit with WordSpecLike { import ActorFlowSpec._ - implicit val mat = ActorMaterializer() - "ActorFlow" should { val replier = spawn(Behaviors.receiveMessage[Asking] { diff --git a/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala b/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala index b1325af162..c7c150556e 100644 --- a/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala +++ b/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala @@ -7,13 +7,10 @@ package docs.akka.stream.typed import akka.NotUsed import akka.actor.typed.{ ActorRef, ActorSystem } import akka.actor.typed.scaladsl.Behaviors -import akka.stream.typed.scaladsl.ActorMaterializer object ActorSourceSinkExample { - val system: ActorSystem[_] = ActorSystem(Behaviors.empty, "ActorSourceSinkExample") - - implicit val mat: ActorMaterializer = ActorMaterializer()(system) + implicit val system: ActorSystem[_] = ActorSystem(Behaviors.empty, "ActorSourceSinkExample") { // #actor-source-ref diff --git a/akka-stream/src/main/scala/akka/stream/Materializer.scala b/akka-stream/src/main/scala/akka/stream/Materializer.scala index 0e4f66c42c..166b8a2acf 100644 --- a/akka-stream/src/main/scala/akka/stream/Materializer.scala +++ b/akka-stream/src/main/scala/akka/stream/Materializer.scala @@ -4,6 +4,7 @@ package akka.stream +import akka.actor.ClassicActorSystemProvider import akka.actor.Cancellable import akka.annotation.InternalApi import com.github.ghik.silencer.silent @@ -145,6 +146,16 @@ abstract class Materializer { } +object Materializer { + + /** + * Implicitly provides the system wide materializer from a classic or typed `ActorSystem` + */ + implicit def matFromSystem(implicit provider: ClassicActorSystemProvider): Materializer = + SystemMaterializer(provider.classicSystem).materializer + +} + /** * INTERNAL API */ diff --git a/akka-stream/src/main/scala/akka/stream/SystemMaterializer.scala b/akka-stream/src/main/scala/akka/stream/SystemMaterializer.scala new file mode 100644 index 0000000000..7c9e0ae9c2 --- /dev/null +++ b/akka-stream/src/main/scala/akka/stream/SystemMaterializer.scala @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2009-2019 Lightbend Inc. + */ + +package akka.stream + +import akka.actor.ActorSystem +import akka.actor.ExtendedActorSystem +import akka.actor.Extension +import akka.actor.ExtensionId +import akka.actor.ExtensionIdProvider + +/** + * The system materializer is a default materializer to use for most cases running streams, it is a single instance + * per actor system that is tied to the lifecycle of that system. + * + * Not intended to be manually used in user code. + */ +object SystemMaterializer extends ExtensionId[SystemMaterializer] with ExtensionIdProvider { + override def get(system: ActorSystem): SystemMaterializer = super.get(system) + + override def lookup = SystemMaterializer + + override def createExtension(system: ExtendedActorSystem): SystemMaterializer = + new SystemMaterializer(system) +} + +final class SystemMaterializer(system: ExtendedActorSystem) extends Extension { + val materializer = { + val settings = ActorMaterializerSettings(system) + ActorMaterializer.systemMaterializer(settings, "default", system) + } +} diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala index 754ff9ece0..7dd910b08c 100755 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala @@ -4,27 +4,33 @@ package akka.stream.javadsl -import akka.util.{ ConstantFun, Timeout } -import akka.{ Done, NotUsed } -import akka.event.LoggingAdapter -import akka.japi.{ function, Pair, Util } -import akka.stream._ -import org.reactivestreams.Processor - -import scala.concurrent.duration.FiniteDuration -import java.util.{ Comparator, Optional } import java.util.concurrent.CompletionStage -import java.util.function.{ BiFunction, Supplier } +import java.util.function.BiFunction +import java.util.function.Supplier +import java.util.Comparator +import java.util.Optional -import akka.util.JavaDurationConverters._ import akka.actor.ActorRef +import akka.actor.ClassicActorSystemProvider import akka.dispatch.ExecutionContexts +import akka.event.LoggingAdapter +import akka.japi.Pair +import akka.japi.Util +import akka.japi.function +import akka.stream._ import akka.stream.impl.fusing.LazyFlow +import akka.util.JavaDurationConverters._ import akka.util.unused +import akka.util.ConstantFun +import akka.util.Timeout +import akka.Done +import akka.NotUsed import com.github.ghik.silencer.silent +import org.reactivestreams.Processor import scala.annotation.unchecked.uncheckedVariance import scala.compat.java8.FutureConverters._ +import scala.concurrent.duration.FiniteDuration import scala.reflect.ClassTag object Flow { @@ -496,6 +502,25 @@ final class Flow[In, Out, Mat](delegate: scaladsl.Flow[In, Out, Mat]) extends Gr * @tparam T materialized type of given Source * @tparam U materialized type of given Sink */ + def runWith[T, U]( + source: Graph[SourceShape[In], T], + sink: Graph[SinkShape[Out], U], + systemProvider: ClassicActorSystemProvider): akka.japi.Pair[T, U] = { + val (som, sim) = delegate.runWith(source, sink)(SystemMaterializer(systemProvider.classicSystem).materializer) + akka.japi.Pair(som, sim) + } + + /** + * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. + * + * The returned tuple contains the materialized values of the `Source` and `Sink`, + * e.g. the `Subscriber` of a `Source.asSubscriber` and `Publisher` of a `Sink.asPublisher`. + * + * Prefer the method taking an ActorSystem unless you have special requirements. + * + * @tparam T materialized type of given Source + * @tparam U materialized type of given Sink + */ def runWith[T, U]( source: Graph[SourceShape[In], T], sink: Graph[SinkShape[Out], U], @@ -3580,6 +3605,17 @@ abstract class RunnableGraph[+Mat] extends Graph[ClosedShape, Mat] { /** * Run this flow and return the materialized values of the flow. + * + * Uses the system materializer. + */ + def run(systemProvider: ClassicActorSystemProvider): Mat = { + run(SystemMaterializer(systemProvider.classicSystem).materializer) + } + + /** + * Run this flow using a special materializer and return the materialized values of the flow. + * + * Prefer the method taking an ActorSystem unless you have special requirements. */ def run(materializer: Materializer): Mat diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala index b57b0d5320..f0eccff181 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala @@ -5,24 +5,29 @@ package akka.stream.javadsl import java.util.Optional - -import akka.{ japi, Done, NotUsed } -import akka.actor.ActorRef -import akka.dispatch.ExecutionContexts -import akka.japi.function -import akka.stream.impl.LinearTraversalBuilder -import akka.stream.{ javadsl, scaladsl, _ } -import org.reactivestreams.{ Publisher, Subscriber } - -import scala.compat.java8.OptionConverters._ -import scala.concurrent.ExecutionContext -import scala.util.Try import java.util.concurrent.CompletionStage import java.util.function.BiFunction -import scala.collection.immutable +import akka.Done +import akka.NotUsed +import akka.actor.ActorRef +import akka.actor.ClassicActorSystemProvider +import akka.dispatch.ExecutionContexts +import akka.japi +import akka.japi.function +import akka.stream._ +import akka.stream.impl.LinearTraversalBuilder +import akka.stream.javadsl +import akka.stream.scaladsl +import org.reactivestreams.Publisher +import org.reactivestreams.Subscriber + import scala.annotation.unchecked.uncheckedVariance +import scala.collection.immutable import scala.compat.java8.FutureConverters._ +import scala.compat.java8.OptionConverters._ +import scala.concurrent.ExecutionContext +import scala.util.Try /** Java API */ object Sink { @@ -379,6 +384,12 @@ final class Sink[In, Mat](delegate: scaladsl.Sink[In, Mat]) extends Graph[SinkSh */ def asScala: scaladsl.Sink[In, Mat] = delegate + /** + * Connect this `Sink` to a `Source` and run it. + */ + def runWith[M](source: Graph[SourceShape[In], M], systemProvider: ClassicActorSystemProvider): M = + asScala.runWith(source)(SystemMaterializer(systemProvider.classicSystem).materializer) + /** * Connect this `Sink` to a `Source` and run it. */ @@ -407,6 +418,22 @@ final class Sink[In, Mat](delegate: scaladsl.Sink[In, Mat]) extends Graph[SinkSh * that can be consume elements 'into' the pre-materialized one. * * Useful for when you need a materialized value of a Sink when handing it out to someone to materialize it for you. + * + * Note that the `ActorSystem` can be used as the `systemProvider` parameter. + */ + def preMaterialize(systemProvider: ClassicActorSystemProvider) + : japi.Pair[Mat @uncheckedVariance, Sink[In @uncheckedVariance, NotUsed]] = { + val (mat, sink) = delegate.preMaterialize()(SystemMaterializer(systemProvider.classicSystem).materializer) + akka.japi.Pair(mat, sink.asJava) + } + + /** + * Materializes this Sink, immediately returning (1) its materialized value, and (2) a new Sink + * that can be consume elements 'into' the pre-materialized one. + * + * Useful for when you need a materialized value of a Sink when handing it out to someone to materialize it for you. + * + * Prefer the method taking an ActorSystem unless you have special requirements. */ def preMaterialize( materializer: Materializer): japi.Pair[Mat @uncheckedVariance, Sink[In @uncheckedVariance, NotUsed]] = { diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala index d0812b404a..da3336b2f7 100755 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala @@ -28,6 +28,7 @@ import java.util.concurrent.CompletionStage import java.util.concurrent.CompletableFuture import java.util.function.{ BiFunction, Supplier } +import akka.actor.ClassicActorSystemProvider import akka.util.unused import com.github.ghik.silencer.silent @@ -566,6 +567,20 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[ /** * Materializes this Source, immediately returning (1) its materialized value, and (2) a new Source * that can be used to consume elements from the newly materialized Source. + * + * Note that the `ActorSystem` can be used as the `systemProvider` parameter. + */ + def preMaterialize(systemProvider: ClassicActorSystemProvider) + : Pair[Mat @uncheckedVariance, Source[Out @uncheckedVariance, NotUsed]] = { + val (mat, src) = delegate.preMaterialize()(SystemMaterializer(systemProvider.classicSystem).materializer) + Pair(mat, new Source(src)) + } + + /** + * Materializes this Source, immediately returning (1) its materialized value, and (2) a new Source + * that can be used to consume elements from the newly materialized Source. + * + * Prefer the method taking an `ActorSystem` unless you have special requirements. */ def preMaterialize( materializer: Materializer): Pair[Mat @uncheckedVariance, Source[Out @uncheckedVariance, NotUsed]] = { @@ -662,6 +677,17 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[ /** * Connect this `Source` to a `Sink` and run it. The returned value is the materialized value * of the `Sink`, e.g. the `Publisher` of a `Sink.asPublisher`. + * + * Note that the classic or typed `ActorSystem` can be used as the `systemProvider` parameter. + */ + def runWith[M](sink: Graph[SinkShape[Out], M], systemProvider: ClassicActorSystemProvider): M = + delegate.runWith(sink)(SystemMaterializer(systemProvider.classicSystem).materializer) + + /** + * Connect this `Source` to a `Sink` and run it. The returned value is the materialized value + * of the `Sink`, e.g. the `Publisher` of a `Sink.asPublisher`. + * + * Prefer the method taking an `ActorSystem` unless you have special requirements */ def runWith[M](sink: Graph[SinkShape[Out], M], materializer: Materializer): M = delegate.runWith(sink)(materializer) @@ -673,6 +699,24 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[ * The returned [[java.util.concurrent.CompletionStage]] will be completed with value of the final * function evaluation when the input stream ends, or completed with `Failure` * if there is a failure is signaled in the stream. + * + * Note that the classic or typed `ActorSystem` can be used as the `systemProvider` parameter. + */ + def runFold[U]( + zero: U, + f: function.Function2[U, Out, U], + systemProvider: ClassicActorSystemProvider): CompletionStage[U] = + runWith(Sink.fold(zero, f), systemProvider) + + /** + * Shortcut for running this `Source` with a fold function. + * The given function is invoked for every received element, giving it its previous + * output (or the given `zero` value) and the element as input. + * The returned [[java.util.concurrent.CompletionStage]] will be completed with value of the final + * function evaluation when the input stream ends, or completed with `Failure` + * if there is a failure is signaled in the stream. + * + * Prefer the method taking an ActorSystem unless you have special requirements. */ def runFold[U](zero: U, f: function.Function2[U, Out, U], materializer: Materializer): CompletionStage[U] = runWith(Sink.fold(zero, f), materializer) @@ -684,6 +728,23 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[ * The returned [[java.util.concurrent.CompletionStage]] will be completed with value of the final * function evaluation when the input stream ends, or completed with `Failure` * if there is a failure is signaled in the stream. + * + * Note that the classic or typed `ActorSystem` can be used as the `systemProvider` parameter. + */ + def runFoldAsync[U]( + zero: U, + f: function.Function2[U, Out, CompletionStage[U]], + systemProvider: ClassicActorSystemProvider): CompletionStage[U] = runWith(Sink.foldAsync(zero, f), systemProvider) + + /** + * Shortcut for running this `Source` with an asynchronous fold function. + * The given function is invoked for every received element, giving it its previous + * output (or the given `zero` value) and the element as input. + * The returned [[java.util.concurrent.CompletionStage]] will be completed with value of the final + * function evaluation when the input stream ends, or completed with `Failure` + * if there is a failure is signaled in the stream. + * + * Prefer the method taking an `ActorSystem` unless you have special requirements */ def runFoldAsync[U]( zero: U, @@ -702,6 +763,28 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[ * the reduce operator will fail its downstream with a [[NoSuchElementException]], * which is semantically in-line with that Scala's standard library collections * do in such situations. + * + * Note that the classic or typed `ActorSystem` can be used as the `systemProvider` parameter. + */ + def runReduce( + f: function.Function2[Out, Out, Out], + systemProvider: ClassicActorSystemProvider): CompletionStage[Out] = + runWith(Sink.reduce(f), systemProvider.classicSystem) + + /** + * Shortcut for running this `Source` with a reduce function. + * The given function is invoked for every received element, giving it its previous + * output (from the second ones) an the element as input. + * The returned [[java.util.concurrent.CompletionStage]] will be completed with value of the final + * function evaluation when the input stream ends, or completed with `Failure` + * if there is a failure is signaled in the stream. + * + * If the stream is empty (i.e. completes before signalling any elements), + * the reduce operator will fail its downstream with a [[NoSuchElementException]], + * which is semantically in-line with that Scala's standard library collections + * do in such situations. + * + * Prefer the method taking an `ActorSystem` unless you have special requirements */ def runReduce(f: function.Function2[Out, Out, Out], materializer: Materializer): CompletionStage[Out] = runWith(Sink.reduce(f), materializer) @@ -1387,6 +1470,20 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[ * The returned [[java.util.concurrent.CompletionStage]] will be completed normally when reaching the * normal end of the stream, or completed exceptionally if there is a failure is signaled in * the stream. + * + * Note that the classic or typed `ActorSystem` can be used as the `systemProvider` parameter. + */ + def runForeach(f: function.Procedure[Out], systemProvider: ClassicActorSystemProvider): CompletionStage[Done] = + runWith(Sink.foreach(f), systemProvider) + + /** + * Shortcut for running this `Source` with a foreach procedure. The given procedure is invoked + * for each received element. + * The returned [[java.util.concurrent.CompletionStage]] will be completed normally when reaching the + * normal end of the stream, or completed exceptionally if there is a failure is signaled in + * the stream. + * + * Prefer the method taking an `ActorSystem` unless you have special requirements */ def runForeach(f: function.Procedure[Out], materializer: Materializer): CompletionStage[Done] = runWith(Sink.foreach(f), materializer) diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/SourceWithContext.scala b/akka-stream/src/main/scala/akka/stream/javadsl/SourceWithContext.scala index ea19c4778e..2affc07dd1 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/SourceWithContext.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/SourceWithContext.scala @@ -4,15 +4,18 @@ package akka.stream.javadsl -import akka.japi.{ function, Pair, Util } -import akka.stream._ -import akka.event.LoggingAdapter -import akka.util.ConstantFun - -import scala.annotation.unchecked.uncheckedVariance -import akka.util.ccompat.JavaConverters._ import java.util.concurrent.CompletionStage +import akka.actor.ClassicActorSystemProvider +import akka.event.LoggingAdapter +import akka.japi.Pair +import akka.japi.Util +import akka.japi.function +import akka.stream._ +import akka.util.ConstantFun +import akka.util.ccompat.JavaConverters._ + +import scala.annotation.unchecked.uncheckedVariance import scala.compat.java8.FutureConverters._ object SourceWithContext { @@ -230,6 +233,17 @@ final class SourceWithContext[+Out, +Ctx, +Mat](delegate: scaladsl.SourceWithCon * Connect this [[akka.stream.javadsl.SourceWithContext]] to a [[akka.stream.javadsl.Sink]] and run it. * The returned value is the materialized value of the `Sink`. */ + def runWith[M]( + sink: Graph[SinkShape[Pair[Out @uncheckedVariance, Ctx @uncheckedVariance]], M], + systemProvider: ClassicActorSystemProvider): M = + toMat(sink, Keep.right[Mat, M]).run(systemProvider.classicSystem) + + /** + * Connect this [[akka.stream.javadsl.SourceWithContext]] to a [[akka.stream.javadsl.Sink]] and run it. + * The returned value is the materialized value of the `Sink`. + * + * Prefer the method taking an ActorSystem unless you have special requirements. + */ def runWith[M]( sink: Graph[SinkShape[Pair[Out @uncheckedVariance, Ctx @uncheckedVariance]], M], materializer: Materializer): M = diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Tcp.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Tcp.scala index f388915255..870fa98cc1 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Tcp.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Tcp.scala @@ -26,8 +26,10 @@ import scala.compat.java8.OptionConverters._ import scala.compat.java8.FutureConverters._ import java.util.concurrent.CompletionStage +import akka.actor.ClassicActorSystemProvider import javax.net.ssl.SSLContext import akka.annotation.InternalApi +import akka.stream.SystemMaterializer import akka.stream.TLSProtocol.NegotiateNewSession import com.github.ghik.silencer.silent @@ -79,6 +81,19 @@ object Tcp extends ExtensionId[Tcp] with ExtensionIdProvider { * materialized value is returned. * * Convenience shortcut for: `flow.join(handler).run()`. + * + * Note that the classic or typed `ActorSystem` can be used as the `systemProvider` parameter. + */ + def handleWith[Mat](handler: Flow[ByteString, ByteString, Mat], systemProvider: ClassicActorSystemProvider): Mat = + delegate.handleWith(handler.asScala)(SystemMaterializer(systemProvider.classicSystem).materializer) + + /** + * Handles the connection using the given flow, which is materialized exactly once and the respective + * materialized value is returned. + * + * Convenience shortcut for: `flow.join(handler).run()`. + * + * Prefer the method taking an `ActorSystem` unless you have special requirements */ def handleWith[Mat](handler: Flow[ByteString, ByteString, Mat], materializer: Materializer): Mat = delegate.handleWith(handler.asScala)(materializer) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala index 3e1ba68f70..5eaea9903d 100755 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala @@ -287,6 +287,9 @@ final class Flow[-In, +Out, +Mat]( * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. The returned tuple contains * the materialized values of the `Source` and `Sink`, e.g. the `Subscriber` of a of a [[Source#subscriber]] and * and `Publisher` of a [[Sink#publisher]]. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def runWith[Mat1, Mat2](source: Graph[SourceShape[In], Mat1], sink: Graph[SinkShape[Out], Mat2])( implicit materializer: Materializer): (Mat1, Mat2) = @@ -622,6 +625,9 @@ final case class RunnableGraph[+Mat](override val traversalBuilder: TraversalBui /** * Run this flow and return the materialized instance from the flow. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def run()(implicit materializer: Materializer): Mat = materializer.materialize(this) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala index 66a2a53673..7d9a174c97 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala @@ -4,24 +4,30 @@ package akka.stream.scaladsl -import akka.{ Done, NotUsed } -import akka.dispatch.ExecutionContexts -import akka.actor.{ ActorRef, Status } +import akka.actor.ActorRef +import akka.actor.Status import akka.annotation.InternalApi +import akka.dispatch.ExecutionContexts import akka.stream.impl.Stages.DefaultAttributes import akka.stream.impl._ import akka.stream.impl.fusing.GraphStages import akka.stream.stage._ -import akka.stream.{ javadsl, _ } -import org.reactivestreams.{ Publisher, Subscriber } +import akka.stream.javadsl +import akka.stream._ +import akka.util.ccompat._ +import akka.Done +import akka.NotUsed +import org.reactivestreams.Publisher +import org.reactivestreams.Subscriber import scala.annotation.tailrec -import scala.concurrent.{ ExecutionContext, Future } -import scala.util.{ Failure, Success, Try } -import scala.collection.immutable -import akka.util.ccompat._ - import scala.annotation.unchecked.uncheckedVariance +import scala.collection.immutable +import scala.concurrent.ExecutionContext +import scala.concurrent.Future +import scala.util.Failure +import scala.util.Success +import scala.util.Try /** * A `Sink` is a set of stream processing steps that has one open input. @@ -46,6 +52,9 @@ final class Sink[-In, +Mat](override val traversalBuilder: LinearTraversalBuilde /** * Connect this `Sink` to a `Source` and run it. The returned value is the materialized value * of the `Source`, e.g. the `Subscriber` of a [[Source#subscriber]]. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def runWith[Mat2](source: Graph[SourceShape[In], Mat2])(implicit materializer: Materializer): Mat2 = Source.fromGraph(source).to(this).run() diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala index 1c23f0d05a..0e71b57c23 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala @@ -100,6 +100,9 @@ final class Source[+Out, +Mat]( /** * Connect this `Source` to a `Sink` and run it. The returned value is the materialized value * of the `Sink`, e.g. the `Publisher` of a [[akka.stream.scaladsl.Sink#publisher]]. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def runWith[Mat2](sink: Graph[SinkShape[Out], Mat2])(implicit materializer: Materializer): Mat2 = toMat(sink)(Keep.right).run() @@ -111,6 +114,9 @@ final class Source[+Out, +Mat]( * The returned [[scala.concurrent.Future]] will be completed with value of the final * function evaluation when the input stream ends, or completed with `Failure` * if there is a failure signaled in the stream. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def runFold[U](zero: U)(f: (U, Out) => U)(implicit materializer: Materializer): Future[U] = runWith(Sink.fold(zero)(f)) @@ -122,6 +128,9 @@ final class Source[+Out, +Mat]( * The returned [[scala.concurrent.Future]] will be completed with value of the final * function evaluation when the input stream ends, or completed with `Failure` * if there is a failure signaled in the stream. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def runFoldAsync[U](zero: U)(f: (U, Out) => Future[U])(implicit materializer: Materializer): Future[U] = runWith(Sink.foldAsync(zero)(f)) @@ -138,6 +147,9 @@ final class Source[+Out, +Mat]( * the reduce operator will fail its downstream with a [[NoSuchElementException]], * which is semantically in-line with that Scala's standard library collections * do in such situations. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def runReduce[U >: Out](f: (U, U) => U)(implicit materializer: Materializer): Future[U] = runWith(Sink.reduce(f)) @@ -148,6 +160,9 @@ final class Source[+Out, +Mat]( * The returned [[scala.concurrent.Future]] will be completed with `Success` when reaching the * normal end of the stream, or completed with `Failure` if there is a failure signaled in * the stream. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ // FIXME: Out => Unit should stay, right?? def runForeach(f: Out => Unit)(implicit materializer: Materializer): Future[Done] = runWith(Sink.foreach(f)) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/SourceWithContext.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/SourceWithContext.scala index c4a0d49cce..26c4b1f6e3 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/SourceWithContext.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/SourceWithContext.scala @@ -70,6 +70,9 @@ final class SourceWithContext[+Out, +Ctx, +Mat] private[stream] (delegate: Sourc /** * Connect this [[akka.stream.scaladsl.SourceWithContext]] to a [[akka.stream.scaladsl.Sink]] and run it. * The returned value is the materialized value of the `Sink`. + * + * Note that the `ActorSystem` can be used as the implicit `materializer` parameter to use the + * [[akka.stream.SystemMaterializer]] for running the stream. */ def runWith[Mat2](sink: Graph[SinkShape[(Out, Ctx)], Mat2])(implicit materializer: Materializer): Mat2 = delegate.runWith(sink) diff --git a/akka-stream/src/main/scala/akka/stream/snapshot/MaterializerState.scala b/akka-stream/src/main/scala/akka/stream/snapshot/MaterializerState.scala index 55d8fc7d78..4ade41ce53 100644 --- a/akka-stream/src/main/scala/akka/stream/snapshot/MaterializerState.scala +++ b/akka-stream/src/main/scala/akka/stream/snapshot/MaterializerState.scala @@ -4,10 +4,12 @@ package akka.stream.snapshot +import akka.actor.ActorSystem import akka.actor.{ ActorPath, ActorRef } import akka.annotation.{ ApiMayChange, DoNotInherit, InternalApi } import akka.stream.impl.{ PhasedFusingActorMaterializer, StreamSupervisor } import akka.pattern.ask +import akka.stream.SystemMaterializer import akka.stream.impl.fusing.ActorGraphInterpreter import akka.stream.{ Attributes, Materializer } import akka.util.Timeout @@ -26,6 +28,17 @@ import scala.concurrent.duration._ */ object MaterializerState { + /** + * Dump stream snapshots of all streams of the default system materializer. + */ + @ApiMayChange + def streamSnapshots(system: ActorSystem): Future[immutable.Seq[StreamSnapshot]] = { + SystemMaterializer(system).materializer match { + case impl: PhasedFusingActorMaterializer => + requestFromSupervisor(impl.supervisor)(impl.system.dispatchers.internalDispatcher) + } + } + /** * Dump stream snapshots of all streams of the given materializer. */