Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Cloud Storage: Retry when any 500 level server error is… #2082

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ import scala.util.control.NonFatal
// We use mapConcat with an empty output here instead of throwing an exception to restart
// the Source, as an exception causes stack traces to be logged
.mapConcat {
case resp @ HttpResponse(StatusCodes.InternalServerError, _, responseEntity, _) =>
case resp @ HttpResponse(StatusCodes.ServerError(_), _, responseEntity, _) =>
if (remainingAttempts.getAndDecrement() > 0) {
responseEntity.discardBytes()
List()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,27 @@ class GCStorageSourceSpec
result.futureValue.mkString shouldBe fileContent
}

// retry for all akka-http standard server errors (5XX) https://github.com/akka/alpakka/issues/2057
"automatically retry when file downloads fail with a non-500 server error" in {
val bucketName = "alpakka"
val fileName = "file1.txt"
val fileContent = "This is the file content"

mockFileDownloadFailureThenSuccess(503, "Backend Error", fileContent)

val downloadSource = GCStorage.download(bucketName, fileName)

val data: Future[Option[Source[ByteString, NotUsed]]] =
downloadSource.runWith(Sink.head)

import system.dispatcher

val result: Future[Seq[String]] = data
.flatMap(_.getOrElse(Source.empty).map(_.utf8String).runWith(Sink.seq[String]))

result.futureValue.mkString shouldBe fileContent
}

"upload small file" in {
val fileContent = "chunk1"
val contentType = ContentTypes.`application/octet-stream`
Expand Down