Skip to content

Commit

Permalink
upgrade zio version (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgfraser authored Apr 3, 2022
1 parent 2d303cc commit 757c875
Show file tree
Hide file tree
Showing 23 changed files with 546 additions and 580 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ lazy val root = project
unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library")
)

val zioVersion = "2.0.0-RC3"
val zioVersion = "2.0.0-RC4"
val catsVersion = "2.6.1"
val catsEffectVersion = "3.2.9"
val catsMtlVersion = "1.2.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import zio.stream.interop.catz.core.*
import zio.stream.{ Stream, ZStream }
import zio.test.*

object CoreSummonSpec extends DefaultRunnableSpec {
object CoreSummonSpec extends ZIOSpecDefault {
override def spec =
suite("summons from catz.core work with only a cats-core dependency")(
test("ZIO instances") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zio.internal.stacktracer
import zio.test._
import zio.ZTraceElement

object InteropTracerSpec extends DefaultRunnableSpec {
object InteropTracerSpec extends ZIOSpecDefault {

private val myLambda: () => Any = () => ()
override def spec =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
def man(x: Int): ZManaged[Any, Throwable, Unit] =
ZManaged.acquireReleaseWith(ZIO.succeed(effects += x).unit)(_ => ZIO.succeed(effects += x + 1))

val testCase = man(1).toResource[RIO[ZEnv, _]].use(_ => ZIO.unit)
val testCase = man(1).toResource[Task].use(_ => ZIO.unit)
for {
_ <- testCase
effects <- ZIO.succeed(effects.toList)
Expand All @@ -262,7 +262,7 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
ZIO.unit
}

val testCase = man(1).toResource[RIO[ZEnv, _]].use(_ => ZIO.fail(new RuntimeException()).unit)
val testCase = man(1).toResource[Task].use(_ => ZIO.fail(new RuntimeException()).unit)
for {
_ <- testCase.orElse(ZIO.unit)
effects <- ZIO.succeed(effects.toList)
Expand All @@ -278,7 +278,7 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
ZIO.unit
}

val testCase = man(1).toResource[RIO[ZEnv, _]].use(_ => ZIO.interrupt)
val testCase = man(1).toResource[Task].use(_ => ZIO.interrupt)
for {
_ <- testCase.orElse(ZIO.unit)
effects <- ZIO.succeed(effects.toList)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package zio.interop

import cats.effect.kernel.Async
import cats.effect.std.Dispatcher
import cats.effect.IO as CIO
import cats.implicits.*
import zio.test.Assertion.*
Expand All @@ -10,7 +9,7 @@ import zio.test.interop.catz.test.*

object catzQueueSpec extends CatsRunnableSpec {

def boundedQueueTest[F[+_]: Async: Dispatcher]: F[TestResult] =
def boundedQueueTest[F[+_]: Async]: F[TestResult] =
for {
q <- Queue.bounded[F, Int](1)
_ <- q.offer(1)
Expand All @@ -19,54 +18,32 @@ object catzQueueSpec extends CatsRunnableSpec {
r2 <- q.takeAll
} yield assert(r1)(equalTo(List(1))) && assert(r2)(equalTo(List(2)))

def droppingQueueTest[F[+_]: Async: Dispatcher]: F[TestResult] =
def droppingQueueTest[F[+_]: Async]: F[TestResult] =
for {
q <- Queue.dropping[F, Int](2)
_ <- q.offerAll(List(1, 2, 3))
r <- q.takeAll
} yield assert(r)(equalTo(List(1, 2)))

def slidingQueueTest[F[+_]: Async: Dispatcher]: F[TestResult] =
def slidingQueueTest[F[+_]: Async]: F[TestResult] =
for {
q <- Queue.sliding[F, Int](2)
_ <- q.offerAll(List(1, 2, 3, 4))
r <- q.takeAll
} yield assert(r)(equalTo(List(3, 4)))

def unboundedQueueTest[F[+_]: Async: Dispatcher]: F[TestResult] =
def unboundedQueueTest[F[+_]: Async]: F[TestResult] =
for {
q <- Queue.unbounded[F, Int]
expected = Range.inclusive(0, 100)
_ <- q.offerAll(expected)
actual <- q.takeAll
} yield assert(actual)(equalTo(expected.toList))

def contramapQueueTest[F[+_]: Async: Dispatcher]: F[TestResult] =
for {
q <- Queue.unbounded[F, String]
q1 = q.contramap((i: Int) => i.toString)
data = Range.inclusive(0, 100)
_ <- q1.offerAll(data)
actual <- q1.takeAll
expected = data.map(_.toString)
} yield assert(actual)(equalTo(expected.toList))

def mapMQueueTest[F[+_]: Async: Dispatcher]: F[TestResult] =
for {
q <- Queue.unbounded[F, Int]
q1 = q.mapM(_.toString.pure[F])
data = Range.inclusive(0, 100)
_ <- q1.offerAll(data)
actual <- q1.takeAll
expected = data.map(_.toString)
} yield assert(actual)(equalTo(expected.toList))

def spec = suite("catzQueueSpec")(
testF("can use a bounded queue from Cats Effect IO")(boundedQueueTest[CIO]),
testF("can use a dropping queue from Cats Effect IO")(droppingQueueTest[CIO]),
testF("can use a sliding queue from Cats Effect IO")(slidingQueueTest[CIO]),
testF("can use an unbounded queue from Cats Effect IO")(unboundedQueueTest[CIO]),
testF("can contramap a queue from Cats Effect IO")(contramapQueueTest[CIO]),
testF("can mapM a queue from Cats Effect IO")(mapMQueueTest[CIO])
testF("can use an unbounded queue from Cats Effect IO")(unboundedQueueTest[CIO])
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package zio.interop

import fs2.Stream
import zio.{ Chunk, Clock, RIO, Ref, Task }
import zio.{ Chunk, Ref, Task }
import zio.stream.ZStream
import zio.test.Assertion.{ equalTo, fails }
import zio.test.*
import zio.interop.catz.*
import zio.Random.nextIntBetween

object fs2StreamSpec extends DefaultRunnableSpec {
object fs2StreamSpec extends ZIOSpecDefault {
import zio.stream.interop.fs2z.*

val exception: Throwable = new Exception("Failed")
Expand Down Expand Up @@ -88,7 +88,7 @@ object fs2StreamSpec extends DefaultRunnableSpec {
for {
queueSize <- nextIntBetween(2, 128)
result <- assertEqual(
fs2StreamFromChunk(chunk).covary[RIO[Clock, _]].toZStream(queueSize),
fs2StreamFromChunk(chunk).covary[Task].toZStream(queueSize),
ZStream.fromChunk(chunk)
)
} yield result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,13 @@ import scala.concurrent.duration._
class CatsSpec extends ZioSpecBase {

// ZIO tests
checkAllAsync(
"Async[RIO[Clock, _]]",
implicit tc => AsyncTests[RIO[Clock, _]].async[Int, Int, Int](100.millis)
)
checkAllAsync(
"Async[Task]",
{ implicit tc =>
implicit val runtime: Runtime[Clock] = Runtime(environment, platform)
AsyncTests[Task].async[Int, Int, Int](100.millis)
}
)
checkAllAsync(
"Temporal[RIO[Clock, _]]",
implicit tc => GenTemporalTests[RIO[Clock, _], Throwable].temporal[Int, Int, Int](100.millis)
implicit tc => AsyncTests[Task].async[Int, Int, Int](100.millis)
)
checkAllAsync(
"Temporal[Task]",
{ implicit tc =>
implicit val runtime: Runtime[Clock] = Runtime(environment, platform)
GenTemporalTests[Task, Throwable].temporal[Int, Int, Int](100.millis)
}
implicit tc => GenTemporalTests[Task, Throwable].temporal[Int, Int, Int](100.millis)
)
checkAllAsync("GenSpawn[IO[Int, _], Int]", implicit tc => GenSpawnTests[IO[Int, _], Int].spawn[Int, Int, Int])
checkAllAsync("MonadError[IO[In t, _]]", implicit tc => MonadErrorTests[IO[Int, _], Int].monadError[Int, Int, Int])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,39 @@ private[zio] trait CatsSpecBase
blockingExecutor = Executor.fromExecutionContext(1024)(ticker.ctx)
)

def environment(implicit ticker: Ticker): ZEnvironment[ZEnv] = {

val testClock = new Clock {

def instant(implicit trace: ZTraceElement): UIO[Instant] =
???
def localDateTime(implicit trace: ZTraceElement): UIO[LocalDateTime] =
???
def currentTime(unit: => TimeUnit)(implicit trace: ZTraceElement): UIO[Long] =
ZIO.succeed(ticker.ctx.now().toUnit(unit).toLong)

def currentDateTime(implicit trace: ZTraceElement): UIO[OffsetDateTime] =
ZIO.succeed(OffsetDateTime.ofInstant(Instant.ofEpochMilli(ticker.ctx.now().toMillis), ZoneOffset.UTC))

def nanoTime(implicit trace: ZTraceElement): UIO[Long] =
ZIO.succeed(ticker.ctx.now().toNanos)

def sleep(duration: => Duration)(implicit trace: ZTraceElement): UIO[Unit] = duration.asScala match {
case finite: FiniteDuration =>
ZIO.asyncInterrupt { cb =>
val cancel = ticker.ctx.schedule(finite, () => cb(UIO.unit))
Left(UIO.succeed(cancel()))
}
case infinite: Infinite =>
ZIO.dieMessage(s"Unexpected infinite duration $infinite passed to Ticker")
}

def scheduler(implicit trace: ZTraceElement): UIO[Scheduler] =
???
val environment: ZEnvironment[Any] =
ZEnvironment(())

def testClock(implicit ticker: Ticker) = new Clock {

def instant(implicit trace: ZTraceElement): UIO[Instant] =
???
def localDateTime(implicit trace: ZTraceElement): UIO[LocalDateTime] =
???
def currentTime(unit: => TimeUnit)(implicit trace: ZTraceElement): UIO[Long] =
ZIO.succeed(ticker.ctx.now().toUnit(unit).toLong)

def currentDateTime(implicit trace: ZTraceElement): UIO[OffsetDateTime] =
ZIO.succeed(OffsetDateTime.ofInstant(Instant.ofEpochMilli(ticker.ctx.now().toMillis), ZoneOffset.UTC))

def javaClock(implicit trace: zio.ZTraceElement): zio.UIO[java.time.Clock] =
???

def nanoTime(implicit trace: ZTraceElement): UIO[Long] =
ZIO.succeed(ticker.ctx.now().toNanos)

def sleep(duration: => Duration)(implicit trace: ZTraceElement): UIO[Unit] = duration.asScala match {
case finite: FiniteDuration =>
ZIO.asyncInterrupt { cb =>
val cancel = ticker.ctx.schedule(finite, () => cb(UIO.unit))
Left(UIO.succeed(cancel()))
}
case infinite: Infinite =>
ZIO.dieMessage(s"Unexpected infinite duration $infinite passed to Ticker")
}

ZEnv.Services.live ++ ZEnvironment(testClock)
def scheduler(implicit trace: ZTraceElement): UIO[Scheduler] =
???
}

def unsafeRun[E, A](io: IO[E, A])(implicit ticker: Ticker): Exit[E, Option[A]] =
Expand All @@ -84,15 +85,18 @@ private[zio] trait CatsSpecBase
}

implicit def runtime(implicit ticker: Ticker): Runtime[Any] =
Runtime(ZEnvironment(()), platform)
Runtime(environment, platform)

implicit val arbitraryAny: Arbitrary[Any] =
Arbitrary(Gen.const(()))

implicit def arbitraryChunk[A: Arbitrary]: Arbitrary[Chunk[A]] =
Arbitrary(Gen.listOf(Arbitrary.arbitrary[A]).map(Chunk.fromIterable))

implicit val cogenForAny: Cogen[Any] =
Cogen(_.hashCode.toLong)

implicit def arbitraryEnvironment(implicit ticker: Ticker): Arbitrary[ZEnvironment[ZEnv]] =
implicit val arbitraryEnvironment: Arbitrary[ZEnvironment[Any]] =
Arbitrary(Gen.const(environment))

implicit val eqForNothing: Eq[Nothing] =
Expand Down Expand Up @@ -122,8 +126,8 @@ private[zio] trait CatsSpecBase
implicit def eqForURIO[R: Arbitrary: Tag, A: Eq](implicit ticker: Ticker): Eq[URIO[R, A]] =
eqForZIO[R, Nothing, A]

implicit def execRIO(rio: RIO[ZEnv, Boolean])(implicit ticker: Ticker): Prop =
rio.provideEnvironment(environment).toEffect[CIO]
implicit def execTask(task: Task[Boolean])(implicit ticker: Ticker): Prop =
ZEnv.services.locallyWith(_.add(testClock))(task).toEffect[CIO]

implicit def orderForUIOofFiniteDuration(implicit ticker: Ticker): Order[UIO[FiniteDuration]] =
Order.by(unsafeRun(_).toEither.toOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ private[interop] trait ZioSpecBase extends CatsSpecBase with ZioSpecBaseLowPrior

implicit def arbitraryURManaged[R: Cogen: Tag, A: Arbitrary]: Arbitrary[URManaged[R, A]] =
zManagedArbitrary[R, Nothing, A]

implicit def arbitraryClockAndBlocking(implicit ticker: Ticker): Arbitrary[Clock] =
Arbitrary(Arbitrary.arbitrary[ZEnvironment[ZEnv]].map(_.get[Clock]))
}

private[interop] trait ZioSpecBaseLowPriority { self: ZioSpecBase =>

implicit def arbitraryClock(implicit ticker: Ticker): Arbitrary[Clock] =
Arbitrary(Arbitrary.arbitrary[ZEnvironment[ZEnv]].map(_.get[Clock]))
Arbitrary(Gen.const(testClock))

implicit val cogenForClock: Cogen[Clock] =
Cogen(_.hashCode.toLong)
Expand Down
4 changes: 2 additions & 2 deletions zio-interop-cats/js/src/main/scala/zio/interop/ZioAsync.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package zio.interop

import cats.effect.kernel.{ Async, Cont, Sync, Unique }
import zio.{ Clock, Promise, RIO, ZIO }
import zio.{ Promise, RIO, ZIO }

import scala.concurrent.{ ExecutionContext, Future }

private class ZioAsync[R <: Clock] extends ZioTemporal[R, Throwable] with Async[RIO[R, _]] {
private class ZioAsync[R] extends ZioTemporal[R, Throwable] with Async[RIO[R, _]] {

override final def evalOn[A](fa: F[A], ec: ExecutionContext): F[A] =
fa.onExecutionContext(ec)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package zio.interop

import cats.effect.kernel.{ Async, Cont, Sync, Unique }
import zio.{ Clock, Promise, RIO, ZIO }
import zio.{ Promise, RIO, ZIO }

import scala.concurrent.{ ExecutionContext, Future }

private class ZioAsync[R <: Clock] extends ZioTemporal[R, Throwable] with Async[RIO[R, _]] {
private class ZioAsync[R] extends ZioTemporal[R, Throwable] with Async[RIO[R, _]] {

override final def evalOn[A](fa: F[A], ec: ExecutionContext): F[A] =
fa.onExecutionContext(ec)
Expand Down
Loading

0 comments on commit 757c875

Please sign in to comment.