2014-10-30 16:23:43 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.stream.javadsl;
|
|
|
|
|
|
2014-11-07 15:00:50 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import akka.stream.StreamTest;
|
2014-10-30 19:47:14 +01:00
|
|
|
import akka.stream.javadsl.japi.Function2;
|
2014-11-03 15:29:02 +01:00
|
|
|
import akka.stream.testkit.AkkaSpec;
|
2014-10-30 16:23:43 +01:00
|
|
|
import org.junit.ClassRule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.reactivestreams.Publisher;
|
|
|
|
|
import scala.concurrent.Await;
|
|
|
|
|
import scala.concurrent.Future;
|
|
|
|
|
import scala.concurrent.duration.Duration;
|
2014-11-03 15:29:02 +01:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
2014-10-30 16:23:43 +01:00
|
|
|
|
2014-11-07 15:00:50 +01:00
|
|
|
public class SinkTest extends StreamTest {
|
|
|
|
|
public SinkTest() {
|
|
|
|
|
super(actorSystemResource);
|
|
|
|
|
}
|
2014-10-30 16:23:43 +01:00
|
|
|
|
|
|
|
|
@ClassRule
|
|
|
|
|
public static AkkaJUnitActorSystemResource actorSystemResource = new AkkaJUnitActorSystemResource("FlowTest",
|
|
|
|
|
AkkaSpec.testConf());
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mustBeAbleToUseFanoutPublisher() throws Exception {
|
2014-10-30 19:43:37 +01:00
|
|
|
final KeyedSink<Object, Publisher<Object>> pubSink = Sink.fanoutPublisher(2, 2);
|
|
|
|
|
final Publisher<Object> publisher = Source.from(new ArrayList<Object>()).runWith(pubSink, materializer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void mustBeAbleToUseFuture() throws Exception {
|
2014-11-06 18:13:06 +01:00
|
|
|
final KeyedSink<Integer, Future<Integer>> futSink = Sink.head();
|
2014-10-30 19:43:37 +01:00
|
|
|
final List<Integer> list = new ArrayList<Integer>();
|
|
|
|
|
list.add(1);
|
|
|
|
|
final Future<Integer> future = Source.from(list).runWith(futSink, materializer);
|
|
|
|
|
assert Await.result(future, Duration.create("1 second")).equals(1);
|
2014-10-30 16:23:43 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-30 19:47:14 +01:00
|
|
|
@Test
|
|
|
|
|
public void mustBeAbleToUseFold() throws Exception {
|
|
|
|
|
KeyedSink<Integer, Future<Integer>> foldSink = Sink.fold(0, new Function2<Integer, Integer, Integer>() {
|
|
|
|
|
@Override public Integer apply(Integer arg1, Integer arg2) throws Exception {
|
|
|
|
|
return arg1 + arg2;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Future<Integer> integerFuture = Source.from(new ArrayList<Integer>()).runWith(foldSink, materializer);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-30 16:23:43 +01:00
|
|
|
}
|