Materializer settings as attributes (#27499)

* Replace MaterializerSettings with Attributes #25559 
 * Field access to settings deprecated to make stages use attributes instead
 * Internal stages updated to use attributes
 * Docs on ActorMaterializerSettings updated to recommend away from using it
 * Verify all stages stopped after each testcase in FlowGroupBySpec
 * Subscription timeout attributes merged into one
This commit is contained in:
Johan Andrén 2019-09-04 13:37:06 +02:00 committed by GitHub
parent b9a879d722
commit aca63ea198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
132 changed files with 1596 additions and 1116 deletions

View file

@ -13,6 +13,7 @@ import java.util.concurrent.TimeUnit;
import akka.NotUsed;
import akka.japi.pf.PFBuilder;
import akka.stream.javadsl.*;
import jdocs.AbstractJavaTest;
import akka.testkit.javadsl.TestKit;
import org.junit.AfterClass;
@ -22,10 +23,7 @@ import org.junit.Test;
import akka.actor.ActorSystem;
import akka.stream.Materializer;
import akka.stream.Supervision;
import akka.stream.javadsl.Flow;
import akka.stream.ActorAttributes;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;
import akka.japi.function.Function;
public class FlowErrorDocTest extends AbstractJavaTest {
@ -71,7 +69,13 @@ public class FlowErrorDocTest extends AbstractJavaTest {
.map(elem -> 100 / elem)
.withAttributes(ActorAttributes.withSupervisionStrategy(decider));
final Sink<Integer, CompletionStage<Integer>> fold = Sink.fold(0, (acc, elem) -> acc + elem);
final CompletionStage<Integer> result = source.runWith(fold, system);
final RunnableGraph<CompletionStage<Integer>> runnableGraph = source.toMat(fold, Keep.right());
final RunnableGraph<CompletionStage<Integer>> withCustomSupervision =
runnableGraph.withAttributes(ActorAttributes.withSupervisionStrategy(decider));
final CompletionStage<Integer> result = withCustomSupervision.run(system);
// the element causing division by zero will be dropped
// result here will be a CompletionStage completed with 228
// #resume

View file

@ -663,10 +663,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 -> {
@ -674,7 +670,9 @@ public class IntegrationDocTest extends AbstractJavaTest {
return elem;
})
.mapAsync(4, service::convert)
.runForeach(elem -> System.out.println("after: " + elem), system);
.to(Sink.foreach(elem -> System.out.println("after: " + elem)))
.withAttributes(Attributes.inputBuffer(4, 4))
.run(system);
// #sometimes-slow-mapAsync
probe.expectMsg("after: A");

View file

@ -66,12 +66,6 @@ public class StreamBuffersRateDocTest extends AbstractJavaTest {
@Test
@SuppressWarnings("unused")
public void demonstrateBufferSizes() {
// #materializer-buffer
final Materializer materializer =
ActorMaterializer.create(
ActorMaterializerSettings.create(system).withInputBuffer(64, 64), system);
// #materializer-buffer
// #section-buffer
final Flow<Integer, Integer, NotUsed> flow1 =
Flow.of(Integer.class)
@ -81,7 +75,13 @@ public class StreamBuffersRateDocTest extends AbstractJavaTest {
final Flow<Integer, Integer, NotUsed> flow2 =
flow1
.via(Flow.of(Integer.class).map(elem -> elem / 2))
.async(); // the buffer size of this map is the default
.async(); // the buffer size of this map is the value from the surrounding graph it is
// used in
final RunnableGraph<NotUsed> runnableGraph =
Source.range(1, 10).via(flow1).to(Sink.foreach(elem -> System.out.println(elem)));
final RunnableGraph<NotUsed> withOverridenDefaults =
runnableGraph.withAttributes(Attributes.inputBuffer(64, 64));
// #section-buffer
}