=str: Don't use "remaining", check proper localized TCP messages
This commit is contained in:
parent
0c8d9cb522
commit
2a2f2f075e
4 changed files with 42 additions and 11 deletions
|
|
@ -11,6 +11,7 @@ import akka.stream.scaladsl._
|
||||||
import akka.stream.testkit.AkkaSpec
|
import akka.stream.testkit.AkkaSpec
|
||||||
import akka.stream.OperationAttributes
|
import akka.stream.OperationAttributes
|
||||||
import akka.stream.ActorOperationAttributes
|
import akka.stream.ActorOperationAttributes
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
class FlowErrorDocSpec extends AkkaSpec {
|
class FlowErrorDocSpec extends AkkaSpec {
|
||||||
|
|
||||||
|
|
@ -24,7 +25,7 @@ class FlowErrorDocSpec extends AkkaSpec {
|
||||||
//#stop
|
//#stop
|
||||||
|
|
||||||
intercept[ArithmeticException] {
|
intercept[ArithmeticException] {
|
||||||
Await.result(result, remaining)
|
Await.result(result, 3.seconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +43,7 @@ class FlowErrorDocSpec extends AkkaSpec {
|
||||||
// result here will be a Future completed with Success(228)
|
// result here will be a Future completed with Success(228)
|
||||||
//#resume
|
//#resume
|
||||||
|
|
||||||
Await.result(result, remaining) should be(228)
|
Await.result(result, 3.seconds) should be(228)
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate resume section" in {
|
"demonstrate resume section" in {
|
||||||
|
|
@ -62,7 +63,7 @@ class FlowErrorDocSpec extends AkkaSpec {
|
||||||
// result here will be a Future completed with Success(150)
|
// result here will be a Future completed with Success(150)
|
||||||
//#resume-section
|
//#resume-section
|
||||||
|
|
||||||
Await.result(result, remaining) should be(150)
|
Await.result(result, 3.seconds) should be(150)
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate restart section" in {
|
"demonstrate restart section" in {
|
||||||
|
|
@ -85,7 +86,7 @@ class FlowErrorDocSpec extends AkkaSpec {
|
||||||
// result here will be a Future completed with Success(Vector(0, 1, 4, 0, 5, 12))
|
// result here will be a Future completed with Success(Vector(0, 1, 4, 0, 5, 12))
|
||||||
//#restart-section
|
//#restart-section
|
||||||
|
|
||||||
Await.result(result, remaining) should be(Vector(0, 1, 4, 0, 5, 12))
|
Await.result(result, 3.seconds) should be(Vector(0, 1, 4, 0, 5, 12))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,13 @@
|
||||||
|
|
||||||
package akka.http.impl.engine.client
|
package akka.http.impl.engine.client
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress
|
||||||
|
import java.nio.ByteBuffer
|
||||||
|
import java.nio.channels.{ SocketChannel, ServerSocketChannel }
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
import scala.concurrent.Await
|
import scala.concurrent.Await
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
|
import scala.util.control.NonFatal
|
||||||
import scala.util.{ Failure, Success, Try }
|
import scala.util.{ Failure, Success, Try }
|
||||||
import akka.util.ByteString
|
import akka.util.ByteString
|
||||||
import akka.http.scaladsl.{ TestUtils, Http }
|
import akka.http.scaladsl.{ TestUtils, Http }
|
||||||
|
|
@ -19,9 +23,33 @@ import akka.stream.scaladsl._
|
||||||
import akka.http.scaladsl.model.headers._
|
import akka.http.scaladsl.model.headers._
|
||||||
import akka.http.scaladsl.model._
|
import akka.http.scaladsl.model._
|
||||||
|
|
||||||
class ConnectionPoolSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF\n akka.io.tcp.trace-logging = off") {
|
class ConnectionPoolSpec extends AkkaSpec("""
|
||||||
|
akka.loggers = []
|
||||||
|
akka.loglevel = OFF
|
||||||
|
akka.io.tcp.trace-logging = off
|
||||||
|
akka.io.tcp.windows-connection-abort-workaround-enabled=auto""") {
|
||||||
implicit val materializer = ActorFlowMaterializer()
|
implicit val materializer = ActorFlowMaterializer()
|
||||||
|
|
||||||
|
// FIXME: Extract into proper util class to be reusable
|
||||||
|
lazy val ConnectionResetByPeerMessage: String = {
|
||||||
|
val serverSocket = ServerSocketChannel.open()
|
||||||
|
serverSocket.socket.bind(new InetSocketAddress("127.0.0.1", 0))
|
||||||
|
try {
|
||||||
|
val clientSocket = SocketChannel.open(new InetSocketAddress("127.0.0.1", serverSocket.socket().getLocalPort))
|
||||||
|
@volatile var serverSideChannel: SocketChannel = null
|
||||||
|
awaitCond {
|
||||||
|
serverSideChannel = serverSocket.accept()
|
||||||
|
serverSideChannel != null
|
||||||
|
}
|
||||||
|
serverSideChannel.socket.setSoLinger(true, 0)
|
||||||
|
serverSideChannel.close()
|
||||||
|
clientSocket.read(ByteBuffer.allocate(1))
|
||||||
|
null
|
||||||
|
} catch {
|
||||||
|
case NonFatal(e) ⇒ e.getMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"The host-level client infrastructure" should {
|
"The host-level client infrastructure" should {
|
||||||
|
|
||||||
"properly complete a simple request/response cycle" in new TestSetup {
|
"properly complete a simple request/response cycle" in new TestSetup {
|
||||||
|
|
@ -104,7 +132,7 @@ class ConnectionPoolSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = O
|
||||||
val responses = Seq(responseOut.expectNext(), responseOut.expectNext())
|
val responses = Seq(responseOut.expectNext(), responseOut.expectNext())
|
||||||
|
|
||||||
responses mustContainLike { case (Success(x), 42) ⇒ requestUri(x) should endWith("/a") }
|
responses mustContainLike { case (Success(x), 42) ⇒ requestUri(x) should endWith("/a") }
|
||||||
responses mustContainLike { case (Failure(x), 43) ⇒ x.getMessage should include("reset by peer") }
|
responses mustContainLike { case (Failure(x), 43) ⇒ x.getMessage should include(ConnectionResetByPeerMessage) }
|
||||||
}
|
}
|
||||||
|
|
||||||
"retry failed requests" in new TestSetup(autoAccept = true) {
|
"retry failed requests" in new TestSetup(autoAccept = true) {
|
||||||
|
|
@ -142,7 +170,7 @@ class ConnectionPoolSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = O
|
||||||
val responses = Seq(responseOut.expectNext(), responseOut.expectNext())
|
val responses = Seq(responseOut.expectNext(), responseOut.expectNext())
|
||||||
|
|
||||||
responses mustContainLike { case (Success(x), 42) ⇒ requestUri(x) should endWith("/a") }
|
responses mustContainLike { case (Success(x), 42) ⇒ requestUri(x) should endWith("/a") }
|
||||||
responses mustContainLike { case (Failure(x), 43) ⇒ x.getMessage should include("reset by peer") }
|
responses mustContainLike { case (Failure(x), 43) ⇒ x.getMessage should include(ConnectionResetByPeerMessage) }
|
||||||
remainingResponsesToKill.get() shouldEqual 0
|
remainingResponsesToKill.get() shouldEqual 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import scala.util.control.NoStackTrace
|
||||||
import akka.stream.{ OverflowStrategy, ActorFlowMaterializer }
|
import akka.stream.{ OverflowStrategy, ActorFlowMaterializer }
|
||||||
import akka.stream.testkit.AkkaSpec
|
import akka.stream.testkit.AkkaSpec
|
||||||
import akka.stream.testkit.Utils._
|
import akka.stream.testkit.Utils._
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
class FlowFoldSpec extends AkkaSpec {
|
class FlowFoldSpec extends AkkaSpec {
|
||||||
implicit val mat = ActorFlowMaterializer()
|
implicit val mat = ActorFlowMaterializer()
|
||||||
|
|
@ -19,19 +20,19 @@ class FlowFoldSpec extends AkkaSpec {
|
||||||
val input = 1 to 100
|
val input = 1 to 100
|
||||||
val future = Source(input).runFold(0)(_ + _)
|
val future = Source(input).runFold(0)(_ + _)
|
||||||
val expected = input.fold(0)(_ + _)
|
val expected = input.fold(0)(_ + _)
|
||||||
Await.result(future, remaining) should be(expected)
|
Await.result(future, 3.seconds) should be(expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
"propagate an error" in assertAllStagesStopped {
|
"propagate an error" in assertAllStagesStopped {
|
||||||
val error = new Exception with NoStackTrace
|
val error = new Exception with NoStackTrace
|
||||||
val future = Source[Unit](() ⇒ throw error).runFold(())((_, _) ⇒ ())
|
val future = Source[Unit](() ⇒ throw error).runFold(())((_, _) ⇒ ())
|
||||||
the[Exception] thrownBy Await.result(future, remaining) should be(error)
|
the[Exception] thrownBy Await.result(future, 3.seconds) should be(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
"complete future with failure when function throws" in assertAllStagesStopped {
|
"complete future with failure when function throws" in assertAllStagesStopped {
|
||||||
val error = new Exception with NoStackTrace
|
val error = new Exception with NoStackTrace
|
||||||
val future = Source.single(1).runFold(0)((_, _) ⇒ throw error)
|
val future = Source.single(1).runFold(0)((_, _) ⇒ throw error)
|
||||||
the[Exception] thrownBy Await.result(future, remaining) should be(error)
|
the[Exception] thrownBy Await.result(future, 3.seconds) should be(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import akka.stream.ActorFlowMaterializer
|
||||||
import akka.stream.testkit._
|
import akka.stream.testkit._
|
||||||
import akka.stream.testkit.Utils._
|
import akka.stream.testkit.Utils._
|
||||||
import scala.concurrent.Await
|
import scala.concurrent.Await
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
class FlowForeachSpec extends AkkaSpec {
|
class FlowForeachSpec extends AkkaSpec {
|
||||||
|
|
||||||
|
|
@ -48,7 +49,7 @@ class FlowForeachSpec extends AkkaSpec {
|
||||||
"complete future with failure when function throws" in assertAllStagesStopped {
|
"complete future with failure when function throws" in assertAllStagesStopped {
|
||||||
val error = new Exception with NoStackTrace
|
val error = new Exception with NoStackTrace
|
||||||
val future = Source.single(1).runForeach(_ ⇒ throw error)
|
val future = Source.single(1).runForeach(_ ⇒ throw error)
|
||||||
the[Exception] thrownBy Await.result(future, remaining) should be(error)
|
the[Exception] thrownBy Await.result(future, 3.seconds) should be(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue