Merge pull request #17865 from agolubev/agolubev-#17399-add-boilerplate-remover-for-fan-in-junctions
+str #17399 add boilerplate remover for fan-in junctions
This commit is contained in:
commit
7bdfd4e50f
12 changed files with 290 additions and 16 deletions
|
|
@ -8,6 +8,14 @@ import java.util.Arrays;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.japi.function.Function;
|
||||
import akka.japi.function.Procedure;
|
||||
import akka.stream.Graph;
|
||||
import akka.stream.UniformFanInShape;
|
||||
import akka.stream.UniformFanOutShape;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
|
@ -18,6 +26,7 @@ import akka.stream.StreamTest;
|
|||
import akka.japi.function.Function2;
|
||||
import akka.stream.testkit.AkkaSpec;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
public class SinkTest extends StreamTest {
|
||||
public SinkTest() {
|
||||
|
|
@ -65,4 +74,31 @@ public class SinkTest extends StreamTest {
|
|||
probe.expectMsgEquals("done");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustBeAbleToCombine() throws Exception {
|
||||
final JavaTestKit probe1 = new JavaTestKit(system);
|
||||
final JavaTestKit probe2 = new JavaTestKit(system);
|
||||
|
||||
final Sink<Integer, ?> sink1 = Sink.actorRef(probe1.getRef(), "done1");
|
||||
final Sink<Integer, ?> sink2 = Sink.actorRef(probe2.getRef(), "done2");
|
||||
|
||||
final Sink<Integer, ?> sink = Sink.combine(sink1, sink2, new ArrayList(),
|
||||
new Function<Integer, Graph<UniformFanOutShape<Integer, Integer>, BoxedUnit>>() {
|
||||
public Graph<UniformFanOutShape<Integer, Integer>, BoxedUnit> apply(Integer elem) {
|
||||
return Broadcast.create(elem);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Source.from(Arrays.asList(0, 1)).runWith(sink, materializer);
|
||||
|
||||
probe1.expectMsgEquals(0);
|
||||
probe2.expectMsgEquals(0);
|
||||
probe1.expectMsgEquals(1);
|
||||
probe2.expectMsgEquals(1);
|
||||
|
||||
probe1.expectMsgEquals("done1");
|
||||
probe2.expectMsgEquals("done2");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,15 @@ import akka.dispatch.Futures;
|
|||
import akka.dispatch.OnSuccess;
|
||||
import akka.japi.JavaPartialFunction;
|
||||
import akka.japi.Pair;
|
||||
import akka.japi.function.*;
|
||||
import akka.stream.Graph;
|
||||
import akka.stream.OverflowStrategy;
|
||||
import akka.stream.StreamTest;
|
||||
import akka.stream.UniformFanInShape;
|
||||
import akka.stream.stage.*;
|
||||
import akka.japi.function.*;
|
||||
import akka.stream.testkit.AkkaSpec;
|
||||
import akka.stream.testkit.TestPublisher;
|
||||
import akka.testkit.JavaTestKit;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import scala.concurrent.Await;
|
||||
|
|
@ -26,11 +27,13 @@ import scala.concurrent.duration.Duration;
|
|||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import scala.util.Try;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static akka.stream.testkit.StreamTestKit.PublisherProbeSubscription;
|
||||
import static akka.stream.testkit.TestPublisher.ManualProbe;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SourceTest extends StreamTest {
|
||||
|
|
@ -548,7 +551,6 @@ public class SourceTest extends StreamTest {
|
|||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
}), materializer);
|
||||
|
||||
final PublisherProbeSubscription<Integer> s = publisherProbe.expectSubscription();
|
||||
s.sendNext(0);
|
||||
probe.expectMsgEquals(0);
|
||||
|
|
@ -558,4 +560,28 @@ public class SourceTest extends StreamTest {
|
|||
Await.ready(future, Duration.apply(200, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustBeAbleToCombine() throws Exception {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
final Source<Integer, ?> source1 = Source.from(Arrays.asList(0, 1));
|
||||
final Source<Integer, ?> source2 = Source.from(Arrays.asList(2, 3));
|
||||
|
||||
final Source<Integer, ?> source = Source.combine(source1, source2, new ArrayList(),
|
||||
new Function<Integer, Graph<UniformFanInShape<Integer, Integer>, BoxedUnit>>() {
|
||||
public Graph<UniformFanInShape<Integer, Integer>, BoxedUnit> apply(Integer elem) {
|
||||
return Merge.create(elem);
|
||||
}
|
||||
});
|
||||
|
||||
final Future<BoxedUnit> future = source.runWith(Sink.foreach(new Procedure<Integer>() { // Scala Future
|
||||
public void apply(Integer elem) {
|
||||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
}), materializer);
|
||||
|
||||
probe.expectMsgAllOf(0, 1, 2, 3);
|
||||
|
||||
Await.ready(future, Duration.apply(200, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue