!str #16557 Rename Source.singleton to Source.single
This commit is contained in:
parent
9c47f35459
commit
5bf2ab43bd
13 changed files with 19 additions and 19 deletions
|
|
@ -66,7 +66,7 @@ private[http] object BodyPartRenderer {
|
|||
override def onUpstreamFinish(ctx: Context[Source[ChunkStreamPart]]): TerminationDirective = ctx.absorbTermination()
|
||||
|
||||
private def chunkStream(byteString: ByteString): Source[ChunkStreamPart] =
|
||||
Source.singleton(Chunk(byteString))
|
||||
Source.single(Chunk(byteString))
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,11 +106,11 @@ private[http] class HttpRequestRendererFactory(userAgentHeader: Option[headers.`
|
|||
entity match {
|
||||
case x if x.isKnownEmpty ⇒
|
||||
renderContentLength(0) ~~ CrLf
|
||||
Source.singleton(r.get)
|
||||
Source.single(r.get)
|
||||
|
||||
case HttpEntity.Strict(_, data) ⇒
|
||||
renderContentLength(data.length) ~~ CrLf
|
||||
Source.singleton(r.get ++ data)
|
||||
Source.single(r.get ++ data)
|
||||
|
||||
case HttpEntity.Default(_, contentLength, data) ⇒
|
||||
renderContentLength(contentLength) ~~ CrLf
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ private[http] class HttpResponseRendererFactory(serverHeader: Option[headers.Ser
|
|||
renderEntityContentType(r, entity)
|
||||
renderContentLengthHeader(data.length) ~~ CrLf
|
||||
val entityBytes = if (noEntity) ByteString.empty else data
|
||||
Source.singleton(r.get ++ entityBytes)
|
||||
Source.single(r.get ++ entityBytes)
|
||||
|
||||
case HttpEntity.Default(_, contentLength, data) ⇒
|
||||
renderHeaders(headers.toList)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ private object RenderSupport {
|
|||
|
||||
def renderByteStrings(r: ByteStringRendering, entityBytes: ⇒ Source[ByteString],
|
||||
skipEntity: Boolean = false): Source[ByteString] = {
|
||||
val messageStart = Source.singleton(r.get)
|
||||
val messageStart = Source.single(r.get)
|
||||
val messageBytes =
|
||||
if (!skipEntity) messageStart ++ entityBytes
|
||||
else CancelSecond(messageStart, entityBytes)
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ object HttpEntity {
|
|||
case Success(Some(newData)) ⇒
|
||||
copy(data = newData)
|
||||
case Success(None) ⇒
|
||||
Chunked.fromData(contentType, Source.singleton(data).via(transformer))
|
||||
Chunked.fromData(contentType, Source.single(data).via(transformer))
|
||||
case Failure(ex) ⇒
|
||||
Chunked(contentType, Source.failed(ex))
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ object HttpEntity {
|
|||
throw new IllegalStateException(s"Transformer didn't produce as much bytes (${newData.length}:'${newData.utf8String}') as claimed ($newContentLength)")
|
||||
copy(data = newData)
|
||||
case Success(None) ⇒
|
||||
Default(contentType, newContentLength, Source.singleton(data).via(transformer))
|
||||
Default(contentType, newContentLength, Source.single(data).via(transformer))
|
||||
case Failure(ex) ⇒
|
||||
Default(contentType, newContentLength, Source.failed(ex))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ object TestClient extends App {
|
|||
println(s"Fetching HTTP server version of host `$host` ...")
|
||||
|
||||
val connection = Http().outgoingConnection(host)
|
||||
val result = Source.singleton(HttpRequest()).via(connection.flow).runWith(Sink.head)
|
||||
val result = Source.single(HttpRequest()).via(connection.flow).runWith(Sink.head)
|
||||
|
||||
result.map(_.header[headers.Server]) onComplete {
|
||||
case Success(res) ⇒ println(s"$host is running ${res mkString ", "}")
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ class RequestRendererSpec extends FreeSpec with Matchers with BeforeAndAfterAll
|
|||
def renderTo(expected: String): Matcher[HttpRequest] =
|
||||
equal(expected.stripMarginWithNewline("\r\n")).matcher[String] compose { request ⇒
|
||||
val renderer = newRenderer
|
||||
val byteStringSource = Await.result(Source.singleton(RequestRenderingContext(request, serverAddress)).
|
||||
val byteStringSource = Await.result(Source.single(RequestRenderingContext(request, serverAddress)).
|
||||
section(name("renderer"))(_.transform(() ⇒ renderer)).
|
||||
runWith(Sink.head), 1.second)
|
||||
val future = byteStringSource.grouped(1000).runWith(Sink.head).map(_.reduceLeft(_ ++ _).utf8String)
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ class ResponseRendererSpec extends FreeSpec with Matchers with BeforeAndAfterAll
|
|||
def renderTo(expected: String, close: Boolean): Matcher[ResponseRenderingContext] =
|
||||
equal(expected.stripMarginWithNewline("\r\n") -> close).matcher[(String, Boolean)] compose { ctx ⇒
|
||||
val renderer = newRenderer
|
||||
val byteStringSource = Await.result(Source.singleton(ctx).
|
||||
val byteStringSource = Await.result(Source.single(ctx).
|
||||
section(name("renderer"))(_.transform(() ⇒ renderer)).
|
||||
runWith(Sink.head), 1.second)
|
||||
val future = byteStringSource.grouped(1000).runWith(Sink.head).map(_.reduceLeft(_ ++ _).utf8String)
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class RangeDirectivesSpec extends RoutingSpec with Inspectors with Inside {
|
|||
|
||||
"return a 'multipart/byteranges' for a ranged request with multiple ranges if entity data source isn't reusable" in {
|
||||
val content = "Some random and not super short entity."
|
||||
def entityData() = StreamUtils.oneTimeSource(Source.singleton(ByteString(content)))
|
||||
def entityData() = StreamUtils.oneTimeSource(Source.single(ByteString(content)))
|
||||
|
||||
Get() ~> addHeader(Range(ByteRange(5, 10), ByteRange(0, 1), ByteRange(1, 2))) ~> {
|
||||
wrs { complete(HttpEntity.Default(MediaTypes.`text/plain`, content.length, entityData())) }
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class FlowSectionSpec extends AkkaSpec(FlowSectionSpec.config) {
|
|||
"have an op with a different dispatcher" in {
|
||||
val flow = Flow[Int].section(dispatcher("my-dispatcher"))(_.map(sendThreadNameTo(testActor)))
|
||||
|
||||
Source.singleton(1).via(flow).to(Sink.ignore).run()
|
||||
Source.single(1).via(flow).to(Sink.ignore).run()
|
||||
|
||||
receiveN(1).foreach {
|
||||
case s: String ⇒ s should include("my-dispatcher")
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class SourceSpec extends AkkaSpec {
|
|||
|
||||
"Singleton Source" must {
|
||||
"produce element" in {
|
||||
val p = Source.singleton(1).runWith(Sink.publisher)
|
||||
val p = Source.single(1).runWith(Sink.publisher)
|
||||
val c = StreamTestKit.SubscriberProbe[Int]()
|
||||
p.subscribe(c)
|
||||
val sub = c.expectSubscription()
|
||||
|
|
@ -26,7 +26,7 @@ class SourceSpec extends AkkaSpec {
|
|||
}
|
||||
|
||||
"produce elements to later subscriber" in {
|
||||
val p = Source.singleton(1).runWith(Sink.publisher)
|
||||
val p = Source.single(1).runWith(Sink.publisher)
|
||||
val c1 = StreamTestKit.SubscriberProbe[Int]()
|
||||
val c2 = StreamTestKit.SubscriberProbe[Int]()
|
||||
p.subscribe(c1)
|
||||
|
|
@ -85,7 +85,7 @@ class SourceSpec extends AkkaSpec {
|
|||
val s = mm.get(ks)
|
||||
mm.get(mk1) should be(s.toString)
|
||||
mm.get(mk2) should be(s.toString.toUpperCase)
|
||||
val p = Source.singleton(1).runWith(Sink.publisher)
|
||||
val p = Source.single(1).runWith(Sink.publisher)
|
||||
p.subscribe(s)
|
||||
val sub = sp.expectSubscription()
|
||||
sub.request(1)
|
||||
|
|
@ -112,7 +112,7 @@ class SourceSpec extends AkkaSpec {
|
|||
val s = mm.get(ks)
|
||||
mm.get(mk1) should be(s.toString)
|
||||
mm.get(mk2) should be(s.toString.toUpperCase)
|
||||
val p = Source.singleton(1).runWith(Sink.publisher)
|
||||
val p = Source.single(1).runWith(Sink.publisher)
|
||||
p.subscribe(s)
|
||||
val sub = sp.expectSubscription()
|
||||
sub.request(1)
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ object Source {
|
|||
* Create a `Source` with one element.
|
||||
* Every connected `Sink` of this stream will see an individual stream consisting of one element.
|
||||
*/
|
||||
def singleton[T](element: T): Source[T] =
|
||||
new Source(scaladsl.Source.singleton(element))
|
||||
def single[T](element: T): Source[T] =
|
||||
new Source(scaladsl.Source.single(element))
|
||||
|
||||
/**
|
||||
* Create a `Source` that immediately ends the stream with the `cause` error to every connected `Sink`.
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ object Source {
|
|||
* Create a `Source` with one element.
|
||||
* Every connected `Sink` of this stream will see an individual stream consisting of one element.
|
||||
*/
|
||||
def singleton[T](element: T): Source[T] = apply(SynchronousIterablePublisher(List(element), "singleton")) // FIXME optimize
|
||||
def single[T](element: T): Source[T] = apply(SynchronousIterablePublisher(List(element), "single")) // FIXME optimize
|
||||
|
||||
/**
|
||||
* A `Source` with no elements, i.e. an empty stream that is completed immediately for every connected `Sink`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue