-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
420 - improve readFile Stream finalization (#421)
- Loading branch information
1 parent
b19ce44
commit 4892c58
Showing
11 changed files
with
127 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.8.2 | ||
sbt.version = 1.10.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.1") | ||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") | ||
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") | ||
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.7.0") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.5.0") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29") | ||
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.5") | ||
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.10") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
zio-ftp/src/test/scala/zio/ftp/UnsecureDownloadFinalizeSpec.scala
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
zio-ftp/src/test/scala/zio/ftp/UnsecureFtpReadFileSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package zio.ftp | ||
|
||
import org.apache.commons.net.ftp.FTPClient | ||
import zio.test.Assertion._ | ||
import zio.test._ | ||
|
||
import java.io.{ IOException, InputStream } | ||
import scala.util.Random | ||
|
||
object UnsecureFtpReadFileSpec extends ZIOSpecDefault { | ||
|
||
private def createFtpclient(errorOrsuccess: Either[Exception, Boolean]) = | ||
UnsecureFtp.unsafe(new FTPClient { | ||
|
||
override def retrieveFileStream(remote: String): InputStream = { | ||
val it = Random.alphanumeric.take(5000).map(_.toByte).iterator | ||
() => if (it.hasNext) it.next().toInt else -1 | ||
} | ||
|
||
override def completePendingCommand(): Boolean = | ||
errorOrsuccess match { | ||
case Left(err) => throw err | ||
case Right(flag) => flag | ||
} | ||
}) | ||
|
||
private def hasIncompleteMsg(a: Assertion[String]) = | ||
hasField("file transfer incomplete message", (e: Exception) => e.getMessage, a) | ||
|
||
override def spec = | ||
suite("UnsecureFtp - ReadFile complete pending")( | ||
test("succeed") { | ||
val ftpClient = createFtpclient(Right(true)) | ||
for { | ||
bytes <- ftpClient.readFile("/a/b/c.txt").runCollect | ||
} yield assert(bytes)(hasSize(equalTo(5000))) | ||
}, | ||
test("fail to complete") { | ||
val ftpClient = createFtpclient(Right(false)) | ||
for { | ||
exit <- ftpClient.readFile("/a/b/c.txt").runCollect.exit | ||
} yield assert(exit)( | ||
fails( | ||
isSubtype[FileTransferIncompleteError]( | ||
hasIncompleteMsg(startsWithString("Cannot finalize the file transfer") && containsString("/a/b/c.txt")) | ||
) | ||
) | ||
) | ||
}, | ||
test("error occur") { | ||
val ftpClient = createFtpclient(Left(new IOException("Boom"))) | ||
for { | ||
exit <- ftpClient.readFile("/a/b/c.txt").runCollect.exit | ||
} yield assert(exit)( | ||
fails( | ||
isSubtype[FileTransferIncompleteError]( | ||
hasIncompleteMsg(startsWithString("Cannot finalize the file transfer") && containsString("/a/b/c.txt")) | ||
) | ||
) | ||
) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters