Example for Source.fromIterator #25468 (#28582)

* add example for Source.fromIterator #25468

* scala fmt code style fix

* don't use test as a sample for docs
This commit is contained in:
Evgeny Sidorov 2020-02-11 16:58:00 +03:00 committed by GitHub
parent 6120b73918
commit dcdaa5a0dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 0 deletions

View file

@ -22,6 +22,7 @@ import akka.stream.stage.*;
import akka.testkit.AkkaSpec;
import akka.stream.testkit.TestPublisher;
import akka.testkit.javadsl.TestKit;
import com.google.common.collect.Iterables;
import org.junit.ClassRule;
import org.junit.Test;
import scala.concurrent.duration.FiniteDuration;
@ -1157,4 +1158,16 @@ public class SourceTest extends StreamTest {
akka.stream.scaladsl.Source.empty();
Source<Integer, NotUsed> javaSource = scalaSource.asJava();
}
@Test
public void mustProperlyIterate() throws Exception {
final Creator<Iterator<Boolean>> input = () -> Iterables.cycle(false, true).iterator();
final CompletableFuture<List<Boolean>> future =
Source.fromIterator(input).grouped(10).runWith(Sink.head(), system).toCompletableFuture();
assertArrayEquals(
new Boolean[] {false, true, false, true, false, true, false, true, false, true},
future.get(1, TimeUnit.SECONDS).toArray());
}
}