pekko/akka-stream-tests-tck/src/test/scala/akka/stream/tck/GroupByTest.scala

31 lines
819 B
Scala

/**
* Copyright (C) 2015-2016 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.stream.tck
import scala.concurrent.Await
import scala.concurrent.duration._
import akka.stream.impl.EmptyPublisher
import akka.stream.scaladsl.Sink
import akka.stream.scaladsl.Source
import org.reactivestreams.Publisher
class GroupByTest extends AkkaPublisherVerification[Int] {
def createPublisher(elements: Long): Publisher[Int] =
if (elements == 0) EmptyPublisher[Int]
else {
val futureGroupSource =
Source(iterable(elements))
.groupBy(1, elem "all")
.prefixAndTail(0)
.map(_._2)
.concatSubstreams
.runWith(Sink.head)
val groupSource = Await.result(futureGroupSource, 3.seconds)
groupSource.runWith(Sink.asPublisher(false))
}
}