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

Upgrade to ZIO 2.0.0-RC6 #537

Merged
merged 1 commit into from
May 3, 2022
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
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-RC5"
val zioVersion = "2.0.0-RC6"
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
@@ -1,7 +1,7 @@
package zio.internal.stacktracer

import zio.test._
import zio.ZTraceElement
import zio.Trace

object InteropTracerSpec extends ZIOSpecDefault {

Expand All @@ -12,18 +12,18 @@ object InteropTracerSpec extends ZIOSpecDefault {

val result = InteropTracer.newTrace(myLambda)

assertTrue(result == "myLambda(InteropTracerSpec.scala:8:0)".asInstanceOf[ZTraceElement])
assertTrue(result == "myLambda(InteropTracerSpec.scala:8:0)".asInstanceOf[Trace])
},
test("tracing 'by name' parameter") {

def check[A](f: => A): ZTraceElement = {
def check[A](f: => A): Trace = {
val byName: () => A = () => f
InteropTracer.newTrace(byName)
}

val result = check(42)

assertTrue(result == "spec(InteropTracerSpec.scala:24:0)".asInstanceOf[ZTraceElement])
assertTrue(result == "spec(InteropTracerSpec.scala:24:0)".asInstanceOf[Trace])
}
).@@(TestAspect.exceptScala3)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import cats.effect.{ IO as CIO, LiftIO }
import cats.effect.kernel.{ Concurrent, Resource }
import zio.interop.catz.*
import zio.test.*
import zio.{ Promise, Task }
import zio.{ Promise, Task, ZIO }

object CatsInteropSpec extends CatsRunnableSpec {
def spec = suite("Cats interop")(
test("cats fiber wrapped in Resource can be canceled") {
for {
promise <- Promise.make[Nothing, Int]
resource = Resource.make(Concurrent[Task].start(promise.succeed(1) *> Task.never))(_.cancel)
resource = Resource.make(Concurrent[Task].start(promise.succeed(1) *> ZIO.never))(_.cancel)
_ <- resource.use(_ => promise.await)
} yield assertCompletes
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
test("calls finalizers correctly when use is interrupted") {
val effects = new mutable.ListBuffer[Int]
def res(x: Int): Resource[Task, Unit] =
Resource.makeCase(Task.attempt(effects += x).unit) {
Resource.makeCase(ZIO.attempt(effects += x).unit) {
case (_, Resource.ExitCase.Canceled) =>
Task.attempt(effects += x + 1).unit
case _ => Task.unit
ZIO.attempt(effects += x + 1).unit
case _ => ZIO.unit
}

val testCase = {
Expand All @@ -150,11 +150,11 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
test("calls finalizers correctly when use has failed") {
val effects = new mutable.ListBuffer[Int]
def res(x: Int): Resource[Task, Unit] =
Resource.makeCase(Task.attempt(effects += x).unit) {
Resource.makeCase(ZIO.attempt(effects += x).unit) {
case (_, Resource.ExitCase.Errored(_)) =>
Task.attempt(effects += x + 1).unit
ZIO.attempt(effects += x + 1).unit
case _ =>
Task.unit
ZIO.unit
}

val testCase = {
Expand All @@ -170,11 +170,11 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
test("calls finalizers correctly when use has died") {
val effects = new mutable.ListBuffer[Int]
def res(x: Int): Resource[Task, Unit] =
Resource.makeCase(Task.attempt(effects += x).unit) {
Resource.makeCase(ZIO.attempt(effects += x).unit) {
case (_, Resource.ExitCase.Errored(_)) =>
Task.attempt(effects += x + 1).unit
ZIO.attempt(effects += x + 1).unit
case _ =>
Task.unit
ZIO.unit
}

val testCase = {
Expand All @@ -190,8 +190,8 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
test("calls finalizers should not run if exception is thrown in acquisition") {
val effects = new mutable.ListBuffer[Int]
def res(x: Int): Resource[Task, Unit] =
Resource.make(Task.attempt(effects += x) *> Task.attempt(throw new RuntimeException()).unit)(_ =>
Task.attempt(effects += x + 1).unit
Resource.make(ZIO.attempt(effects += x) *> ZIO.attempt(throw new RuntimeException()).unit)(_ =>
ZIO.attempt(effects += x + 1).unit
)

val testCase = {
Expand All @@ -207,7 +207,7 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {
test("calls finalizers correctly when using the resource") {
val effects = new mutable.ListBuffer[Int]
def res(x: Int): Resource[Task, Unit] =
Resource.make(Task.attempt(effects += x).unit)(_ => Task.attempt(effects += x).unit)
Resource.make(ZIO.attempt(effects += x).unit)(_ => ZIO.attempt(effects += x).unit)

val testCase = {
val managed: ZManaged[Any, Throwable, Unit] = res(1).toManagedZIO
Expand All @@ -223,7 +223,7 @@ object CatsZManagedSyntaxSpec extends CatsRunnableSpec {

val effects = new mutable.ListBuffer[Int]
def res(x: Int): Resource[Task, Unit] =
Resource.make(Task.attempt(effects += x).unit)(_ => Task.attempt(effects += x).unit)
Resource.make(ZIO.attempt(effects += x).unit)(_ => ZIO.attempt(effects += x).unit)

def man(x: Int): ZManaged[Any, Throwable, Unit] =
ZManaged.acquireReleaseWith(ZIO.succeed(effects += x).unit)(_ => ZIO.succeed(effects += x))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object Fs2ZioSpec extends CatsRunnableSpec {
fail <- Promise.make[Nothing, Unit]
_ <- Stream
.bracket(started.succeed(()).unit)(_ => released.succeed(()).unit)
.evalMap[Task, Unit](_ => fail.await *> IO.fail(new Exception()))
.evalMap[Task, Unit](_ => fail.await *> ZIO.fail(new Exception()))
.compile[Task, Task, Unit]
.drain
.fork
Expand All @@ -60,7 +60,7 @@ object Fs2ZioSpec extends CatsRunnableSpec {
terminate <- Promise.make[Nothing, Unit]
_ <- Stream
.bracket(started.succeed(()).unit)(_ => released.succeed(()).unit)
.evalMap[Task, Unit](_ => terminate.await *> IO.die(new Exception()))
.evalMap[Task, Unit](_ => terminate.await *> ZIO.die(new Exception()))
.compile[Task, Task, Unit]
.drain
.fork
Expand All @@ -74,8 +74,8 @@ object Fs2ZioSpec extends CatsRunnableSpec {
started <- Promise.make[Nothing, Unit]
released <- Promise.make[Nothing, Unit]
f <- Stream
.bracket(IO.unit)(_ => released.succeed(()).unit)
.evalMap[Task, Unit](_ => started.succeed(()) *> IO.never)
.bracket(ZIO.unit)(_ => released.succeed(()).unit)
.evalMap[Task, Unit](_ => started.succeed(()) *> ZIO.never)
.compile[Task, Task, Unit]
.drain
.fork
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object fs2StreamSpec extends ZIOSpecDefault {
}),
test("error propagation") {
val result = ZStream.fail(exception).toFs2Stream.compile.drain.exit
assertM(result)(fails(equalTo(exception)))
assertZIO(result)(fails(equalTo(exception)))
}
),
suite("test toZStream conversion")(
Expand All @@ -56,7 +56,7 @@ object fs2StreamSpec extends ZIOSpecDefault {
}),
test("error propagation") {
val result = Stream.raiseError[Task](exception).toZStream().runDrain.exit
assertM(result)(fails(equalTo(exception)))
assertZIO(result)(fails(equalTo(exception)))
},
test("releases all resources by the time the failover stream has started") {
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,38 @@ private[zio] trait CatsSpecBase
def checkAllAsync(name: String, f: Ticker => Laws#RuleSet): Unit =
checkAll(name, f(Ticker()))

def platform(implicit ticker: Ticker): RuntimeConfig =
RuntimeConfig
.fromExecutor(Executor.fromExecutionContext(1024)(ticker.ctx))
.copy(
blockingExecutor = Executor.fromExecutionContext(1024)(ticker.ctx)
)

val environment: ZEnvironment[Any] =
ZEnvironment(())

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

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

def currentDateTime(implicit trace: ZTraceElement): UIO[OffsetDateTime] =
def currentDateTime(implicit trace: Trace): 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 javaClock(implicit trace: zio.Trace): zio.UIO[java.time.Clock] =
???

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

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

def scheduler(implicit trace: ZTraceElement): UIO[Scheduler] =
def scheduler(implicit trace: Trace): UIO[Scheduler] =
???
}

Expand All @@ -84,8 +77,18 @@ private[zio] trait CatsSpecBase
throw error
}

implicit def runtime(implicit ticker: Ticker): Runtime[Any] =
Runtime(environment, platform)
implicit def runtime(implicit ticker: Ticker): Runtime[Any] = {
val executor = Executor.fromExecutionContext(1024)(ticker.ctx)
val blockingExecutor = Executor.fromExecutionContext(1024)(ticker.ctx)
val fiberId = FiberId.unsafeMake(Trace.empty)
val fiberRefs = FiberRefs(
Map(
FiberRef.currentExecutor -> ::(fiberId -> executor, Nil),
FiberRef.currentBlockingExecutor -> ::(fiberId -> blockingExecutor, Nil)
)
)
Runtime(ZEnvironment.empty, fiberRefs)
}

implicit val arbitraryAny: Arbitrary[Any] =
Arbitrary(Gen.const(()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ trait GenIOInteropCats {
/**
* Given a generator for `A`, produces a generator for `IO[E, A]` using the `IO.point` constructor.
*/
def genSyncSuccess[E, A: Arbitrary]: Gen[IO[E, A]] = Arbitrary.arbitrary[A].map(IO.succeed[A](_))
def genSyncSuccess[E, A: Arbitrary]: Gen[IO[E, A]] = Arbitrary.arbitrary[A].map(ZIO.succeed[A](_))

/**
* Given a generator for `A`, produces a generator for `IO[E, A]` using the `IO.async` constructor.
*/
def genAsyncSuccess[E, A: Arbitrary]: Gen[IO[E, A]] =
Arbitrary.arbitrary[A].map(a => IO.async[Any, E, A](k => k(IO.succeed(a))))
Arbitrary.arbitrary[A].map(a => ZIO.async[Any, E, A](k => k(ZIO.succeed(a))))

/**
* Randomly uses either `genSyncSuccess` or `genAsyncSuccess` with equal probability.
Expand Down Expand Up @@ -95,7 +95,7 @@ trait GenIOInteropCats {
gen.map(nextIO => io.flatMap(_ => nextIO))

private def genOfIdentityFlatMaps[E, A](io: IO[E, A]): Gen[IO[E, A]] =
Gen.const(io.flatMap(a => IO.succeed(a)))
Gen.const(io.flatMap(a => ZIO.succeed(a)))

private def genOfRace[E, A](io: IO[E, A]): Gen[IO[E, A]] =
Gen.const(io.raceFirst(ZIO.never.interruptible))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ trait GenStreamInteropCats {
/**
* Given a generator for `List[A]`, produces a generator for `Stream[E, A]` using the `Stream.fromIterable` constructor.
*/
def genSuccess[E, A: Arbitrary]: Gen[Stream[E, A]] = Arbitrary.arbitrary[A].map(Stream.succeed(_))
def genSuccess[E, A: Arbitrary]: Gen[Stream[E, A]] = Arbitrary.arbitrary[A].map(ZStream.succeed(_))

/**
* Given a generator for `E`, produces a generator for `Stream[E, A]` using the `Stream.fail` constructor.
*/
def genFailure[E: Arbitrary, A]: Gen[Stream[E, A]] = Arbitrary.arbitrary[E].map(Stream.fail[E](_))
def genFailure[E: Arbitrary, A]: Gen[Stream[E, A]] = Arbitrary.arbitrary[E].map(ZStream.fail[E](_))

/**
* Randomly uses either `genSuccess` or `genFailure` with equal probability.
Expand Down Expand Up @@ -80,6 +80,6 @@ trait GenStreamInteropCats {
gen.map(nextIO => stream.flatMap(_ => nextIO))

private def genOfIdentityFlatMaps[E, A](stream: Stream[E, A]): Gen[Stream[E, A]] =
Gen.const(stream.flatMap(a => Stream.succeed(a)))
Gen.const(stream.flatMap(a => ZStream.succeed(a)))

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package zio.internal.stacktracer

import zio.ZTraceElement
import zio.Trace

import scala.annotation.nowarn

object InteropTracer {
@nowarn("cat=unused")
final def newTrace(f: Any): ZTraceElement = "noop".asInstanceOf[ZTraceElement]
final def newTrace(f: Any): Trace = "noop".asInstanceOf[Trace]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@
*/
package zio.internal.stacktracer

import zio.ZTraceElement
import zio.Trace

import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap
import scala.util.matching.Regex

object InteropTracer {
final def newTrace(f: AnyRef): ZTraceElement = {
final def newTrace(f: AnyRef): Trace = {
val clazz = f.getClass()
val cachedTrace = cache.get(clazz)
if (cachedTrace == null) {
val computedTrace = AkkaLineNumbers(f) match {
case AkkaLineNumbers.NoSourceInfo => ZTraceElement.empty
case AkkaLineNumbers.NoSourceInfo => Trace.empty

case AkkaLineNumbers.UnknownSourceFormat(_) => ZTraceElement.empty
case AkkaLineNumbers.UnknownSourceFormat(_) => Trace.empty

case AkkaLineNumbers.SourceFile(filename) =>
createTrace("<unknown>", filename.intern(), 0, 0).asInstanceOf[ZTraceElement]
createTrace("<unknown>", filename.intern(), 0, 0).asInstanceOf[Trace]

case AkkaLineNumbers.SourceFileLines(filename, from, _, _, methodAnonfun) =>
val methodName = lambdaNamePattern
.findFirstMatchIn(methodAnonfun)
.flatMap(Option apply _.group(1))
.getOrElse(methodAnonfun)

createTrace(methodName.intern(), filename.intern(), from, 0).asInstanceOf[ZTraceElement]
createTrace(methodName.intern(), filename.intern(), from, 0).asInstanceOf[Trace]
}
cache.put(clazz, computedTrace)
computedTrace
} else cachedTrace
}

private val cache: ConcurrentMap[Class[?], ZTraceElement] = new ConcurrentHashMap[Class[?], ZTraceElement]()
private val cache: ConcurrentMap[Class[?], Trace] = new ConcurrentHashMap[Class[?], Trace]()

private def createTrace(location: String, file: String, line: Int, column: Int): String =
s"$location($file:$line:$column)".intern
Expand Down
Loading