Skip to content

Commit

Permalink
ZIO 2.0.0-RC5
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Apr 9, 2022
1 parent b135d37 commit afc25f9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ val scala213 = "2.13.8"
val scala3 = "3.1.1"

val zioVersion = "1.0.13"
val zio2Version = "2.0.0-RC2"
val zio2Version = "2.0.0-RC5"

val scalacOptions212 = Seq("-Ypartial-unification", "-deprecation", "-target:jvm-1.8")
val scalacOptions213 = Seq("-deprecation", "-target:jvm-1.8")
Expand Down Expand Up @@ -125,7 +125,7 @@ lazy val proxZStream2 = Project("prox-zstream-2", file("prox-zstream-2")).settin
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zio2Version,
"dev.zio" %% "zio-streams" % zio2Version,
"dev.zio" %% "zio-prelude" % "1.0.0-RC10",
"dev.zio" %% "zio-prelude" % "1.0.0-RC13",

"dev.zio" %% "zio-test" % zio2Version % "test",
"dev.zio" %% "zio-test-sbt" % zio2Version % "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait ProxZStream extends Prox {
override type ProxExitCode = zio.ExitCode
override type ProxFiber[A] = zio.Fiber[ProxError, A]
override type ProxIO[A] = ZIO[Any, ProxError, A]
override type ProxResource[A] = ZManaged[Any, ProxError, A]
override type ProxResource[A] = ZIO[Scope, ProxError, A]
override type ProxStream[A] = ZStream[Any, ProxError, A]
override type ProxPipe[A, B] = ProxStream[A] => ProxStream[B]
override type ProxSink[A] = TransformAndSink[A, _]
Expand Down Expand Up @@ -75,10 +75,10 @@ trait ProxZStream extends Prox {
}

protected override final def makeResource[A](acquire: ProxIO[A], release: A => ProxIO[Unit]): ProxResource[A] =
ZManaged.acquireReleaseWith(acquire)(x => release(x).mapError(_.toThrowable).orDie)
ZIO.acquireRelease(acquire)(x => release(x).mapError(_.toThrowable).orDie)

protected override final def useResource[A, B](r: ProxResource[A], f: A => ProxIO[B]): ProxIO[B] =
r.use(f)
ZIO.scoped(r.flatMap(f))

protected override final def joinFiber[A](f: ProxFiber[A]): ProxIO[A] =
f.join
Expand Down Expand Up @@ -108,19 +108,19 @@ trait ProxZStream extends Prox {
ZStream.fromInputStream(input, chunkSize).mapError(FailedToReadProcessOutput.apply)

protected override final def drainToJavaOutputStream(stream: ProxStream[Byte], output: io.OutputStream, flushChunks: Boolean): ProxIO[Unit] = {
val managedOutput = ZManaged.acquireReleaseWith(ZIO.succeed(output))(s => ZIO.attempt(s.close()).orDie)
val managedOutput = ZIO.acquireRelease(ZIO.succeed(output))(s => ZIO.attempt(s.close()).orDie)
if (flushChunks) {
stream.run(flushingOutputStreamSink(managedOutput).mapError(FailedToWriteProcessInput.apply)).unit
} else {
stream
.run(ZSink
.fromOutputStreamManaged(managedOutput)
.fromOutputStreamScoped(managedOutput)
.mapError(FailedToWriteProcessInput.apply)).unit
}
}

private final def flushingOutputStreamSink(managedOutput: ZManaged[Any, Nothing, io.OutputStream]): ZSink[Any, IOException, Byte, Byte, Long] =
ZSink.unwrapManaged {
private final def flushingOutputStreamSink(managedOutput: ZIO[Scope, Nothing, io.OutputStream]): ZSink[Any, IOException, Byte, Byte, Long] =
ZSink.unwrapScoped {
managedOutput.map { os =>
ZSink.foldLeftChunksZIO(0L) { (bytesWritten, byteChunk: Chunk[Byte]) =>
ZIO.attemptBlockingInterrupt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import zio.test._
import java.nio.charset.StandardCharsets
import java.nio.file.Files

object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
object ProcessGroupSpecs extends ZIOSpecDefault with ProxSpecHelpers {
implicit val processRunner: ProcessRunner[JVMProcessInfo] = new JVMProcessRunner

override val spec =
Expand Down Expand Up @@ -78,7 +78,7 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
val processGroup =
Process("perl", List("-e", """$SIG{TERM} = sub { exit 1 }; sleep 30; exit 0""")) |
Process("sort")
val program = processGroup.start().use { fiber => fiber.interrupt.unit }
val program = ZIO.scoped { processGroup.start().flatMap { fiber => fiber.interrupt.unit } }

assertM(program)(equalTo(()))
} @@ TestAspect.timeout(5.seconds),
Expand All @@ -95,8 +95,8 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
result <- runningProcesses.terminate()
} yield result.exitCodes.toList

assertM(program.provideLayer(Clock.live))(contains[(Process[Unit, Unit], ProxExitCode)](p1 -> ExitCode(1)))
},
assertM(program)(contains[(Process[Unit, Unit], ProxExitCode)](p1 -> ExitCode(1)))
} @@ withLiveClock,

test("can be killed") {

Expand All @@ -112,10 +112,10 @@ object ProcessGroupSpecs extends DefaultRunnableSpec with ProxSpecHelpers {

// Note: we can't assert on the second process' exit code because there is a race condition
// between killing it directly and being stopped because of the upstream process got killed.
assertM(program.provideLayer(Clock.live))(
assertM(program)(
contains(p1 -> ExitCode(137)
))
}
} @@ withLiveClock
),

suite("Input redirection")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import zio.test.TestAspect._
import zio.test._
import zio.{ExitCode, ZIO}

object ProcessSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
object ProcessSpecs extends ZIOSpecDefault with ProxSpecHelpers {
implicit val processRunner: ProcessRunner[JVMProcessInfo] = new JVMProcessRunner

override val spec =
Expand Down Expand Up @@ -268,7 +268,7 @@ object ProcessSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
suite("Termination")(
test("can be terminated with cancellation") {
val process = Process("perl", List("-e", """$SIG{TERM} = sub { exit 1 }; sleep 30; exit 0"""))
val program = process.start().use { fiber => fiber.interrupt.unit }
val program = ZIO.scoped { process.start().flatMap { fiber => fiber.interrupt.unit } }

assertM(program)(equalTo(()))
} @@ TestAspect.timeout(5.seconds),
Expand All @@ -281,19 +281,19 @@ object ProcessSpecs extends DefaultRunnableSpec with ProxSpecHelpers {
result <- runningProcess.terminate()
} yield result.exitCode

assertM(program.provideLayer(Clock.live))(equalTo(ExitCode(1)))
},
assertM(program)(equalTo(ExitCode(1)))
} @@ withLiveClock,

test("can be killed") {
val process = Process("perl", List("-e", """$SIG{TERM} = 'IGNORE'; sleep 30; exit 2"""))
val program = for {
runningProcess <- process.startProcess()
_ <- ZIO(Thread.sleep(250))
_ <- ZIO.sleep(250.millis)
result <- runningProcess.kill()
} yield result.exitCode

assertM(program.provideLayer(Clock.live))(equalTo(ExitCode(137)))
},
assertM(program)(equalTo(ExitCode(137)))
} @@ withLiveClock,

test("can be checked if is alive") {
val process = Process("sleep", List("10"))
Expand Down

0 comments on commit afc25f9

Please sign in to comment.