= rename FlowGraph* to GraphDSL
This commit is contained in:
parent
66a0aa280d
commit
e9670ee91d
19 changed files with 130 additions and 135 deletions
|
|
@ -27,14 +27,14 @@ import akka.stream.*;
|
|||
import akka.stream.javadsl.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
|
||||
public class FlowGraphDocTest extends AbstractJavaTest {
|
||||
public class GraphDSLDocTest extends AbstractJavaTest {
|
||||
|
||||
static ActorSystem system;
|
||||
static Materializer mat;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create("FlowGraphDocTest");
|
||||
system = ActorSystem.create("GraphDSLDocTest");
|
||||
mat = ActorMaterializer.create(system);
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public class FlowGraphDocTest extends AbstractJavaTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateBuildSimpleGraph() throws Exception {
|
||||
//#simple-flow-graph
|
||||
//#simple-graph-dsl
|
||||
final Source<Integer, NotUsed> in = Source.from(Arrays.asList(1, 2, 3, 4, 5));
|
||||
final Sink<List<String>, CompletionStage<List<String>>> sink = Sink.head();
|
||||
final Sink<List<Integer>, CompletionStage<List<Integer>>> sink2 = Sink.head();
|
||||
|
|
@ -72,7 +72,7 @@ public class FlowGraphDocTest extends AbstractJavaTest {
|
|||
builder.from(bcast).via(builder.add(f4)).toFanIn(merge);
|
||||
return ClosedShape.getInstance();
|
||||
}));
|
||||
//#simple-flow-graph
|
||||
//#simple-graph-dsl
|
||||
final List<String> list = result.run(mat).toCompletableFuture().get(3, TimeUnit.SECONDS);
|
||||
final String[] res = list.toArray(new String[] {});
|
||||
Arrays.sort(res, null);
|
||||
|
|
@ -107,7 +107,7 @@ public class FlowGraphDocTest extends AbstractJavaTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateReusingFlowInGraph() throws Exception {
|
||||
//#flow-graph-reusing-a-flow
|
||||
//#graph-dsl-reusing-a-flow
|
||||
final Sink<Integer, CompletionStage<Integer>> topHeadSink = Sink.head();
|
||||
final Sink<Integer, CompletionStage<Integer>> bottomHeadSink = Sink.head();
|
||||
final Flow<Integer, Integer, NotUsed> sharedDoubler = Flow.of(Integer.class).map(elem -> elem * 2);
|
||||
|
|
@ -129,7 +129,7 @@ public class FlowGraphDocTest extends AbstractJavaTest {
|
|||
}
|
||||
)
|
||||
);
|
||||
//#flow-graph-reusing-a-flow
|
||||
//#graph-dsl-reusing-a-flow
|
||||
final Pair<CompletionStage<Integer>, CompletionStage<Integer>> pair = g.run(mat);
|
||||
assertEquals(Integer.valueOf(2), pair.first().toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
assertEquals(Integer.valueOf(2), pair.second().toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
|
|
@ -137,7 +137,7 @@ public class FlowGraphDocTest extends AbstractJavaTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateMatValue() throws Exception {
|
||||
//#flow-graph-matvalue
|
||||
//#graph-dsl-matvalue
|
||||
final Sink<Integer, CompletionStage<Integer>> foldSink = Sink.<Integer, Integer> fold(0, (a, b) -> {
|
||||
return a + b;
|
||||
});
|
||||
|
|
@ -152,9 +152,9 @@ public class FlowGraphDocTest extends AbstractJavaTest {
|
|||
fold.in(),
|
||||
b.from(b.materializedValue()).via(b.add(flatten)).out());
|
||||
}));
|
||||
//#flow-graph-matvalue
|
||||
//#graph-dsl-matvalue
|
||||
|
||||
//#flow-graph-matvalue-cycle
|
||||
//#graph-dsl-matvalue-cycle
|
||||
// This cannot produce any value:
|
||||
final Source<Integer, CompletionStage<Integer>> cyclicSource = Source.fromGraph(
|
||||
GraphDSL.create(foldSink,
|
||||
|
|
@ -168,6 +168,6 @@ public class FlowGraphDocTest extends AbstractJavaTest {
|
|||
return SourceShape.of(b.from(b.materializedValue()).via(b.add(flatten)).out());
|
||||
}));
|
||||
|
||||
//#flow-graph-matvalue-cycle
|
||||
//#graph-dsl-matvalue-cycle
|
||||
}
|
||||
}
|
||||
|
|
@ -3,36 +3,35 @@
|
|||
*/
|
||||
package docs.stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.Done;
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.Pair;
|
||||
import akka.stream.*;
|
||||
import akka.stream.javadsl.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import docs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import akka.actor.*;
|
||||
import akka.japi.Pair;
|
||||
import akka.stream.*;
|
||||
import akka.stream.javadsl.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class StreamPartialFlowGraphDocTest extends AbstractJavaTest {
|
||||
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("StreamPartialFlowGraphDocTest");
|
||||
system = ActorSystem.create("StreamPartialGraphDSLDocTest");
|
||||
mat = ActorMaterializer.create(system);
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +44,7 @@ public class StreamPartialFlowGraphDocTest extends AbstractJavaTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateBuildWithOpenPorts() throws Exception {
|
||||
//#simple-partial-flow-graph
|
||||
//#simple-partial-graph-dsl
|
||||
final Graph<FanInShape2<Integer, Integer, Integer>, NotUsed> zip =
|
||||
ZipWith.create((Integer left, Integer right) -> Math.max(left, right));
|
||||
|
||||
|
|
@ -65,7 +64,7 @@ public class StreamPartialFlowGraphDocTest extends AbstractJavaTest {
|
|||
final RunnableGraph<CompletionStage<Integer>> g =
|
||||
RunnableGraph.<CompletionStage<Integer>>fromGraph(
|
||||
GraphDSL.create(resultSink, (builder, sink) -> {
|
||||
// import the partial flow graph explicitly
|
||||
// import the partial graph explicitly
|
||||
final UniformFanInShape<Integer, Integer> pm = builder.add(pickMaxOfThree);
|
||||
|
||||
builder.from(builder.add(Source.single(1))).toInlet(pm.in(0));
|
||||
|
|
@ -76,11 +75,11 @@ public class StreamPartialFlowGraphDocTest extends AbstractJavaTest {
|
|||
}));
|
||||
|
||||
final CompletionStage<Integer> max = g.run(mat);
|
||||
//#simple-partial-flow-graph
|
||||
//#simple-partial-graph-dsl
|
||||
assertEquals(Integer.valueOf(3), max.toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
//#source-from-partial-flow-graph
|
||||
//#source-from-partial-graph-dsl
|
||||
// first create an indefinite source of integer numbers
|
||||
class Ints implements Iterator<Integer> {
|
||||
private int next = 0;
|
||||
|
|
@ -93,11 +92,11 @@ public class StreamPartialFlowGraphDocTest extends AbstractJavaTest {
|
|||
return next++;
|
||||
}
|
||||
}
|
||||
//#source-from-partial-flow-graph
|
||||
//#source-from-partial-graph-dsl
|
||||
|
||||
@Test
|
||||
public void demonstrateBuildSourceFromPartialFlowGraphCreate() throws Exception {
|
||||
//#source-from-partial-flow-graph
|
||||
public void demonstrateBuildSourceFromPartialGraphDSLCreate() throws Exception {
|
||||
//#source-from-partial-graph-dsl
|
||||
final Source<Integer, NotUsed> ints = Source.fromIterator(() -> new Ints());
|
||||
|
||||
final Source<Pair<Integer, Integer>, NotUsed> pairs = Source.fromGraph(
|
||||
|
|
@ -114,13 +113,13 @@ public class StreamPartialFlowGraphDocTest extends AbstractJavaTest {
|
|||
|
||||
final CompletionStage<Pair<Integer, Integer>> firstPair =
|
||||
pairs.runWith(Sink.<Pair<Integer, Integer>>head(), mat);
|
||||
//#source-from-partial-flow-graph
|
||||
//#source-from-partial-graph-dsl
|
||||
assertEquals(new Pair<>(0, 1), firstPair.toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateBuildFlowFromPartialFlowGraphCreate() throws Exception {
|
||||
//#flow-from-partial-flow-graph
|
||||
public void demonstrateBuildFlowFromPartialGraphDSLCreate() throws Exception {
|
||||
//#flow-from-partial-graph-dsl
|
||||
final Flow<Integer, Pair<Integer, String>, NotUsed> pairs = Flow.fromGraph(GraphDSL.create(
|
||||
b -> {
|
||||
final UniformFanOutShape<Integer, Integer> bcast = b.add(Broadcast.create(2));
|
||||
|
|
@ -133,11 +132,11 @@ public class StreamPartialFlowGraphDocTest extends AbstractJavaTest {
|
|||
return FlowShape.of(bcast.in(), zip.out());
|
||||
}));
|
||||
|
||||
//#flow-from-partial-flow-graph
|
||||
//#flow-from-partial-graph-dsl
|
||||
final CompletionStage<Pair<Integer, String>> matSink =
|
||||
//#flow-from-partial-flow-graph
|
||||
//#flow-from-partial-graph-dsl
|
||||
Source.single(1).via(pairs).runWith(Sink.<Pair<Integer, String>>head(), mat);
|
||||
//#flow-from-partial-flow-graph
|
||||
//#flow-from-partial-graph-dsl
|
||||
|
||||
assertEquals(new Pair<>(1, "1"), matSink.toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
}
|
||||
|
|
@ -275,10 +275,10 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest {
|
|||
}
|
||||
|
||||
static abstract class HiddenDefinitions {
|
||||
//#flow-graph-broadcast
|
||||
//#graph-dsl-broadcast
|
||||
Sink<Author, NotUsed> writeAuthors;
|
||||
Sink<Hashtag, NotUsed> writeHashtags;
|
||||
//#flow-graph-broadcast
|
||||
//#graph-dsl-broadcast
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -286,7 +286,7 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest {
|
|||
final Sink<Author, CompletionStage<Done>> writeAuthors = Sink.ignore();
|
||||
final Sink<Hashtag, CompletionStage<Done>> writeHashtags = Sink.ignore();
|
||||
|
||||
//#flow-graph-broadcast
|
||||
//#graph-dsl-broadcast
|
||||
RunnableGraph.fromGraph(GraphDSL.create(b -> {
|
||||
final UniformFanOutShape<Tweet, Tweet> bcast = b.add(Broadcast.create(2));
|
||||
final FlowShape<Tweet, Author> toAuthor =
|
||||
|
|
@ -300,7 +300,7 @@ public class TwitterStreamQuickstartDocTest extends AbstractJavaTest {
|
|||
b.from(bcast).via(toTags).to(hashtags);
|
||||
return ClosedShape.getInstance();
|
||||
})).run(mat);
|
||||
//#flow-graph-broadcast
|
||||
//#graph-dsl-broadcast
|
||||
}
|
||||
|
||||
long slowComputation(Tweet t) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue