From 421af06f6f8d06a4e7818d12e493a5f727c9908e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Renoux?= Date: Sun, 19 Jun 2022 12:57:22 +0200 Subject: [PATCH] Upgrades to ZIO 2.0.0-RC6 (#40) --- build.sbt | 4 +- .../tranzactio/ConnectionSource.scala | 47 ++++++++++--------- .../tranzactio/DatabaseModuleBase.scala | 16 +++---- .../gaelrenoux/tranzactio/DatabaseOps.scala | 28 +++++------ .../tranzactio/DatabaseServiceBase.scala | 8 ++-- .../gaelrenoux/tranzactio/Wrapper.scala | 4 +- .../gaelrenoux/tranzactio/anorm/package.scala | 10 ++-- .../tranzactio/doobie/package.scala | 12 ++--- .../tranzactio/errorStrategies.scala | 24 +++++----- .../test/DatabaseModuleTestOps.scala | 10 ++-- src/samples/scala/samples/SamplesSpec.scala | 13 +++-- .../scala/samples/anorm/test/SomeTest.scala | 11 ++--- .../samples/doobie/LayeredAppStreaming.scala | 2 +- .../scala/samples/doobie/test/SomeTest.scala | 8 ++-- .../SingleConnectionSourceTest.scala | 11 ++--- .../tranzactio/integration/AnormIT.scala | 20 ++++---- .../tranzactio/integration/DoobieIT.scala | 22 ++++----- .../tranzactio/integration/ITSpec.scala | 2 +- 18 files changed, 125 insertions(+), 127 deletions(-) diff --git a/build.sbt b/build.sbt index b514275..fbe896b 100644 --- a/build.sbt +++ b/build.sbt @@ -106,8 +106,8 @@ scalacOptions ++= allVersionsOption ++ { } -val ZioVersion = "2.0.0-RC5" -val ZioCatsVersion = "3.3.0-RC5" +val ZioVersion = "2.0.0-RC6" +val ZioCatsVersion = "3.3.0-RC7" val DoobieVersion = "1.0.0-RC2" val AnormVersion = "2.6.10" val H2Version = "1.4.200" diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/ConnectionSource.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/ConnectionSource.scala index 9f104b5..4a8cf56 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/ConnectionSource.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/ConnectionSource.scala @@ -12,10 +12,10 @@ object ConnectionSource { trait Service { def runTransaction[R, E, A](task: Connection => ZIO[R, E, A], commitOnFailure: => Boolean = false) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] def runAutoCommit[R, E, A](task: Connection => ZIO[R, E, A]) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] } /** ConnectionSource with standard behavior. Children class need to implement `getConnection`. */ @@ -24,11 +24,11 @@ object ConnectionSource { ) extends ConnectionSource.Service { /** Main function: how to obtain a connection. Needs to be provided. */ - protected def getConnection(implicit trace: ZTraceElement): Task[Connection] + protected def getConnection(implicit trace: Trace): Task[Connection] def runTransaction[R, E, A](task: Connection => ZIO[R, E, A], commitOnFailure: => Boolean = false) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = - openConnection.mapError(Left(_)).acquireReleaseWith(closeConnection(_).orDie) { c: Connection => + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = { + ZIO.acquireReleaseWith(openConnection.mapError(Left(_)))(closeConnection(_).orDie) { c: Connection => setAutoCommit(c, autoCommit = false) .mapError(Left(_)) .zipRight(task(c).mapError(Right(_))) @@ -37,10 +37,11 @@ object ConnectionSource { _ => commitConnection(c).mapError(Left(_)) ) } + } def runAutoCommit[R, E, A](task: Connection => ZIO[R, E, A]) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = - openConnection.mapError(Left(_)).acquireReleaseWith(closeConnection(_).orDie) { c: Connection => + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = + ZIO.acquireReleaseWith(openConnection.mapError(Left(_)))(closeConnection(_).orDie) { c: Connection => setAutoCommit(c, autoCommit = true) .mapError(Left(_)) .zipRight { @@ -53,34 +54,34 @@ object ConnectionSource { private def bottomErrorStrategy(implicit errorStrategies: ErrorStrategiesRef) = errorStrategies.orElse(defaultErrorStrategies).orElseDefault - def openConnection(implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[Any, DbException, Connection] = + def openConnection(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[Any, DbException, Connection] = wrap(bottomErrorStrategy.openConnection) { getConnection.mapError(e => DbException.Wrapped(e)) } def setAutoCommit(c: => Connection, autoCommit: => Boolean) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[Any, DbException, Unit] = + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[Any, DbException, Unit] = wrap(bottomErrorStrategy.setAutoCommit) { attemptBlocking(c.setAutoCommit(autoCommit)) } - def commitConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[Any, DbException, Unit] = + def commitConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[Any, DbException, Unit] = wrap(bottomErrorStrategy.commitConnection) { attemptBlocking(c.commit()) } - def rollbackConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[Any, DbException, Unit] = + def rollbackConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[Any, DbException, Unit] = wrap(bottomErrorStrategy.rollbackConnection) { attemptBlocking(c.rollback()) } /** Cannot fail */ - def closeConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[Any, DbException, Unit] = + def closeConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[Any, DbException, Unit] = wrap(bottomErrorStrategy.closeConnection) { attemptBlocking(c.close()) } - private def wrap[R, A](es: ErrorStrategy)(z: => ZIO[Any, Throwable, A])(implicit trace: ZTraceElement) = es { + private def wrap[R, A](es: ErrorStrategy)(z: => ZIO[Any, Throwable, A])(implicit trace: Trace) = es { z.mapError(e => DbException.Wrapped(e)) } @@ -92,7 +93,7 @@ object ConnectionSource { defaultErrorStrategies: ErrorStrategiesRef ) extends ServiceBase(defaultErrorStrategies) { - override def getConnection(implicit trace: ZTraceElement): RIO[Any, Connection] = attemptBlocking { + override def getConnection(implicit trace: Trace): RIO[Any, Connection] = attemptBlocking { dataSource.getConnection() } } @@ -105,18 +106,18 @@ object ConnectionSource { defaultErrorStrategies: ErrorStrategiesRef ) extends ServiceBase(defaultErrorStrategies) { - override def getConnection(implicit trace: ZTraceElement): UIO[Connection] = UIO.succeed(connection) + override def getConnection(implicit trace: Trace): UIO[Connection] = ZIO.succeed(connection) - override def closeConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[Any, Nothing, Unit] = ZIO.unit + override def closeConnection(c: => Connection)(implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[Any, Nothing, Unit] = ZIO.unit override def runTransaction[R, E, A](task: Connection => ZIO[R, E, A], commitOnFailure: => Boolean) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = semaphore.withPermit { super.runTransaction(task, commitOnFailure) } override def runAutoCommit[R, E, A](task: Connection => ZIO[R, E, A]) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = semaphore.withPermit { super.runAutoCommit(task) } @@ -126,14 +127,14 @@ object ConnectionSource { * * When a Database method is called with no available implicit ErrorStrategiesRef, the default ErrorStrategiesRef will * be used. */ - def fromDatasource(implicit trace: ZTraceElement): ZLayer[DataSource, Nothing, ConnectionSource] = + def fromDatasource(implicit trace: Trace): ZLayer[DataSource, Nothing, ConnectionSource] = fromDatasource(ErrorStrategies.Parent) /** As `fromDatasource`, but provides a default ErrorStrategiesRef. * * When a Database method is called with no available implicit ErrorStrategiesRef, the ErrorStrategiesRef in argument * will be used. */ - def fromDatasource(errorStrategies: ErrorStrategiesRef)(implicit trace: ZTraceElement): ZLayer[DataSource, Nothing, ConnectionSource] = { + def fromDatasource(errorStrategies: ErrorStrategiesRef)(implicit trace: Trace): ZLayer[DataSource, Nothing, ConnectionSource] = { ZLayer { for { source <- ZIO.service[DataSource] @@ -142,7 +143,7 @@ object ConnectionSource { } /** As `fromDatasource(ErrorStrategiesRef)`, but an `ErrorStrategies` is provided through a layer instead of as a parameter. */ - def fromDatasourceAndErrorStrategies(implicit trace: ZTraceElement): ZLayer[DataSource with ErrorStrategies, Nothing, ConnectionSource] = { + def fromDatasourceAndErrorStrategies(implicit trace: Trace): ZLayer[DataSource with ErrorStrategies, Nothing, ConnectionSource] = { ZLayer { for { source <- ZIO.service[DataSource] @@ -156,14 +157,14 @@ object ConnectionSource { * * When a Database method is called with no available implicit ErrorStrategiesRef, the default ErrorStrategiesRef will * be used. */ - def fromConnection(implicit trace: ZTraceElement): ZLayer[Connection, Nothing, ConnectionSource] = + def fromConnection(implicit trace: Trace): ZLayer[Connection, Nothing, ConnectionSource] = fromConnection(ErrorStrategies.Parent) /** As `fromConnection`, but provides a default ErrorStrategiesRef. * * When a Database method is called with no available implicit ErrorStrategiesRef, the ErrorStrategiesRef in argument * will be used. */ - def fromConnection(errorStrategiesRef: ErrorStrategiesRef)(implicit trace: ZTraceElement): ZLayer[Connection, Nothing, ConnectionSource] = { + def fromConnection(errorStrategiesRef: ErrorStrategiesRef)(implicit trace: Trace): ZLayer[Connection, Nothing, ConnectionSource] = { ZLayer { for { connection <- ZIO.service[Connection] diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseModuleBase.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseModuleBase.scala index 8a0082c..0db71a2 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseModuleBase.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseModuleBase.scala @@ -1,7 +1,7 @@ package io.github.gaelrenoux.tranzactio -import zio.{Tag, ZIO, ZLayer, ZTraceElement} +import zio.{Tag, ZIO, ZLayer, Trace} import java.sql.{Connection => JdbcConnection} import javax.sql.DataSource @@ -15,7 +15,7 @@ abstract class DatabaseModuleBase[Connection, Database <: DatabaseOps.ServiceOps override def transaction[R, E, A]( zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[Database with R, Either[DbException, E], A] = { + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[Database with R, Either[DbException, E], A] = { ZIO.serviceWithZIO { db: Database => db.transaction[R, E, A](zio, commitOnFailure) } @@ -23,33 +23,33 @@ abstract class DatabaseModuleBase[Connection, Database <: DatabaseOps.ServiceOps override def autoCommit[R, E, A]( zio: => ZIO[Connection with R, E, A] - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[Database with R, Either[DbException, E], A] = { + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[Database with R, Either[DbException, E], A] = { ZIO.serviceWithZIO { db: Database => db.autoCommit[R, E, A](zio) } } /** Creates a Database Layer which requires an existing ConnectionSource. */ - def fromConnectionSource(implicit trace: ZTraceElement): ZLayer[ConnectionSource, Nothing, Database] + def fromConnectionSource(implicit trace: Trace): ZLayer[ConnectionSource, Nothing, Database] /** Creates a Tranzactio Connection, given a JDBC connection and a Blocking. Useful for some utilities. */ - def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: ZTraceElement): ZIO[Any, Nothing, Connection] + def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: Trace): ZIO[Any, Nothing, Connection] /** Commodity method: creates a Database Layer which includes its own ConnectionSource based on a DataSource. Most * connection pool implementations should be able to provide you a DataSource. * * When no implicit ErrorStrategies is available, the default ErrorStrategies will be used. */ - final def fromDatasource(implicit trace: ZTraceElement): ZLayer[DataSource, Nothing, Database] = + final def fromDatasource(implicit trace: Trace): ZLayer[DataSource, Nothing, Database] = ConnectionSource.fromDatasource >>> fromConnectionSource /** As `fromDatasource`, but provides a default ErrorStrategiesRef. When a method is called with no available implicit * ErrorStrategiesRef, the ErrorStrategiesRef in argument will be used. */ - final def fromDatasource(errorStrategies: ErrorStrategiesRef)(implicit trace: ZTraceElement): ZLayer[DataSource, Nothing, Database] = + final def fromDatasource(errorStrategies: ErrorStrategiesRef)(implicit trace: Trace): ZLayer[DataSource, Nothing, Database] = ConnectionSource.fromDatasource(errorStrategies) >>> fromConnectionSource /** As `fromDatasource(ErrorStrategiesRef)`, but an `ErrorStrategies` is provided through a layer instead of as a parameter. */ - final def fromDatasourceAndErrorStrategies(implicit trace: ZTraceElement): ZLayer[DataSource with ErrorStrategies, Nothing, Database] = + final def fromDatasourceAndErrorStrategies(implicit trace: Trace): ZLayer[DataSource with ErrorStrategies, Nothing, Database] = ConnectionSource.fromDatasourceAndErrorStrategies >>> fromConnectionSource } diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseOps.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseOps.scala index cf0d72a..168fe31 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseOps.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseOps.scala @@ -1,6 +1,6 @@ package io.github.gaelrenoux.tranzactio -import zio.{UIO, ZIO, ZTraceElement} +import zio.{UIO, ZIO, Trace} /** Operations for a Database, based on a few atomic operations. Can be used both by the actual DB service, or by the DB * component where a Database is required in the resulting ZIO. @@ -20,13 +20,13 @@ trait DatabaseOps[Connection, R0] { def transaction[R <: Any, E, A]( zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, Either[DbException, E], A] + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, Either[DbException, E], A] @deprecated("Use transaction instead.", since = "0.4.0") final def transactionR[R, E, A]( zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, Either[DbException, E], A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, Either[DbException, E], A] = transaction[R, E, A](zio, commitOnFailure) /** As `transaction`, but exceptions are simply widened to a common failure type. The resulting failure type is a @@ -34,28 +34,28 @@ trait DatabaseOps[Connection, R0] { final def transactionOrWiden[R, E >: DbException, A]( zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = transaction[R, E, A](zio, commitOnFailure).mapError(_.fold(identity, identity)) @deprecated("Use transactionOrWiden instead.", since = "4.0.0") final def transactionOrWidenR[R, E >: DbException, A]( zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = transactionOrWiden[R, E, A](zio, commitOnFailure) /** As `transaction`, but errors when handling the connections are treated as defects instead of failures. */ final def transactionOrDie[R, E, A]( zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = transaction[R, E, A](zio, commitOnFailure).flatMapError(dieOnLeft) @deprecated("Use transactionOrDie instead.", since = "4.0.0") final def transactionOrDieR[R, E, A]( zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = transactionOrDie[R, E, A](zio, commitOnFailure) /** Provides that ZIO with a Connection. All DB action in the ZIO will be auto-committed. Failures in the initial @@ -66,37 +66,37 @@ trait DatabaseOps[Connection, R0] { */ def autoCommit[R, E, A]( zio: => ZIO[Connection with R, E, A] - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, Either[DbException, E], A] + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, Either[DbException, E], A] @deprecated("Use autoCommit instead.", since = "4.0.0") final def autoCommitR[R, E, A]( zio: => ZIO[Connection with R, E, A] - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, Either[DbException, E], A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, Either[DbException, E], A] = autoCommit[R, E, A](zio) /** As `autoCommit`, but exceptions are simply widened to a common failure type. The resulting failure type is a * superclass of both DbException and the error type of the inital ZIO. */ final def autoCommitOrWiden[R, E >: DbException, A]( zio: => ZIO[Connection with R, E, A] - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = autoCommit[R, E, A](zio).mapError(_.fold(identity, identity)) @deprecated("Use autoCommitOrWiden instead.", since = "4.0.0") final def autoCommitOrWidenR[R, E >: DbException, A]( zio: => ZIO[Connection with R, E, A] - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = autoCommitOrWiden[R, E, A](zio) /** As `autoCommit`, but errors when handling the connections are treated as defects instead of failures. */ final def autoCommitOrDie[R, E, A]( zio: => ZIO[Connection with R, E, A] - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = autoCommit[R, E, A](zio).flatMapError(dieOnLeft) @deprecated("Use autoCommitOrDie instead.", since = "4.0.0") final def autoCommitOrDieR[R, E, A]( zio: => ZIO[Connection with R, E, A] - )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: ZTraceElement): ZIO[R with R0, E, A] = + )(implicit errorStrategies: ErrorStrategiesRef = ErrorStrategies.Parent, trace: Trace): ZIO[R with R0, E, A] = autoCommitOrDie[R, E, A](zio) } @@ -109,7 +109,7 @@ object DatabaseOps { /** API for commodity methods needing a Database. */ trait ModuleOps[Connection, Database <: ServiceOps[Connection]] extends DatabaseOps[Connection, Database] - private def dieOnLeft[E](e: Either[DbException, E])(implicit trace: ZTraceElement): UIO[E] = e match { + private def dieOnLeft[E](e: Either[DbException, E])(implicit trace: Trace): UIO[E] = e match { case Right(appError) => ZIO.succeed(appError) case Left(dbError) => ZIO.die(dbError) } diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseServiceBase.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseServiceBase.scala index f4084ef..fbae40b 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseServiceBase.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/DatabaseServiceBase.scala @@ -1,6 +1,6 @@ package io.github.gaelrenoux.tranzactio -import zio.{Tag, ZEnvironment, ZIO, ZTraceElement} +import zio.{Tag, ZEnvironment, ZIO, Trace} import java.sql.{Connection => JdbcConnection} @@ -11,10 +11,10 @@ abstract class DatabaseServiceBase[Connection: Tag](connectionSource: Connection import connectionSource._ - def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: ZTraceElement): ZIO[Any, Nothing, Connection] + def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: Trace): ZIO[Any, Nothing, Connection] override def transaction[R, E, A](zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean = false) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = ZIO.environmentWithZIO[R] { r => runTransaction({ c: JdbcConnection => connectionFromJdbc(c) @@ -24,7 +24,7 @@ abstract class DatabaseServiceBase[Connection: Tag](connectionSource: Connection } override def autoCommit[R, E, A](zio: => ZIO[Connection with R, E, A]) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = ZIO.environmentWithZIO[R] { r => runAutoCommit { c: JdbcConnection => connectionFromJdbc(c) diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/Wrapper.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/Wrapper.scala index f21f325..e59e464 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/Wrapper.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/Wrapper.scala @@ -1,6 +1,6 @@ package io.github.gaelrenoux.tranzactio -import zio.ZTraceElement +import zio.Trace /** A specific wrapper package for one specific library (e.g. Doobie). */ @@ -26,6 +26,6 @@ trait Wrapper { type TranzactIO[A] /** Wraps a library-specific query into a TranzactIO. */ - def tzio[A](q: => Query[A])(implicit trace: ZTraceElement): TranzactIO[A] + def tzio[A](q: => Query[A])(implicit trace: Trace): TranzactIO[A] } diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/anorm/package.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/anorm/package.scala index c0c3ca5..3a266d0 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/anorm/package.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/anorm/package.scala @@ -2,7 +2,7 @@ package io.github.gaelrenoux.tranzactio import io.github.gaelrenoux.tranzactio.test.DatabaseModuleTestOps import zio.ZIO.attemptBlocking -import zio.{Tag, ZIO, ZLayer, ZTraceElement} +import zio.{Tag, ZIO, ZLayer, Trace} import java.sql.{Connection => JdbcConnection} @@ -16,7 +16,7 @@ package object anorm extends Wrapper { private[tranzactio] val connectionTag = implicitly[Tag[Connection]] - override final def tzio[A](q: => Query[A])(implicit trace: ZTraceElement): TranzactIO[A] = + override final def tzio[A](q: => Query[A])(implicit trace: Trace): TranzactIO[A] = ZIO.serviceWithZIO[Connection] { c => attemptBlocking(q(c)) }.mapError(DbException.Wrapped) @@ -30,15 +30,15 @@ package object anorm extends Wrapper { private[tranzactio] override implicit val connectionTag: Tag[Connection] = anorm.connectionTag /** How to provide a Connection for the module, given a JDBC connection and some environment. */ - override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: ZTraceElement): ZIO[Any, Nothing, Connection] = { + override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: Trace): ZIO[Any, Nothing, Connection] = { ZIO.succeed(connection) } /** Creates a Database Layer which requires an existing ConnectionSource. */ - override final def fromConnectionSource(implicit trace: ZTraceElement): ZLayer[ConnectionSource, Nothing, Database] = + override final def fromConnectionSource(implicit trace: Trace): ZLayer[ConnectionSource, Nothing, Database] = ZLayer.fromFunction { cs: ConnectionSource => new DatabaseServiceBase[Connection](cs) { - override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: ZTraceElement): ZIO[Any, Nothing, Connection] = + override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: Trace): ZIO[Any, Nothing, Connection] = self.connectionFromJdbc(connection) } } diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/doobie/package.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/doobie/package.scala index 62fd19a..22aaaa8 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/doobie/package.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/doobie/package.scala @@ -7,7 +7,7 @@ import io.github.gaelrenoux.tranzactio.test.DatabaseModuleTestOps import zio.interop.catz._ import zio.stream.ZStream import zio.stream.interop.fs2z._ -import zio.{Tag, Task, ZIO, ZLayer, ZTraceElement} +import zio.{Tag, Task, ZIO, ZLayer, Trace} import java.sql.{Connection => JdbcConnection} @@ -24,13 +24,13 @@ package object doobie extends Wrapper { /** Default queue size when converting from FS2 streams. Same default value as in FS2RIOStreamSyntax.toZStream. */ final val DefaultStreamQueueSize = 16 - override final def tzio[A](q: => Query[A])(implicit trace: ZTraceElement): TranzactIO[A] = + override final def tzio[A](q: => Query[A])(implicit trace: Trace): TranzactIO[A] = ZIO.serviceWithZIO[Connection] { c => c.trans.apply(q) }.mapError(DbException.Wrapped) /** Converts a Doobie stream to a ZStream. Note that you can provide a queue size, default value is the same as in ZIO. */ - final def tzioStream[A](q: => fs2.Stream[Query, A], queueSize: => Int = DefaultStreamQueueSize)(implicit trace: ZTraceElement): TranzactIOStream[A] = + final def tzioStream[A](q: => fs2.Stream[Query, A], queueSize: => Int = DefaultStreamQueueSize)(implicit trace: Trace): TranzactIOStream[A] = ZStream.serviceWithStream[Connection] { c => c.transP.apply(q).toZStream(queueSize) }.mapError(DbException.Wrapped) @@ -44,7 +44,7 @@ package object doobie extends Wrapper { private[tranzactio] override implicit val connectionTag: Tag[Connection] = doobie.connectionTag /** How to provide a Connection for the module, given a JDBC connection and some environment. */ - override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: ZTraceElement): ZIO[Any, Nothing, Connection] = { + override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: Trace): ZIO[Any, Nothing, Connection] = { ZIO.succeed { val connect = (c: JdbcConnection) => Resource.pure[Task, JdbcConnection](c) val interp = KleisliInterpreter[Task].ConnectionInterpreter @@ -54,10 +54,10 @@ package object doobie extends Wrapper { } /** Creates a Database Layer which requires an existing ConnectionSource. */ - override final def fromConnectionSource(implicit trace: ZTraceElement): ZLayer[ConnectionSource, Nothing, Database] = + override final def fromConnectionSource(implicit trace: Trace): ZLayer[ConnectionSource, Nothing, Database] = ZLayer.fromFunction { cs: ConnectionSource => new DatabaseServiceBase[Connection](cs) { - override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: ZTraceElement): ZIO[Any, Nothing, Connection] = + override final def connectionFromJdbc(connection: => JdbcConnection)(implicit trace: Trace): ZIO[Any, Nothing, Connection] = self.connectionFromJdbc(connection) } } diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/errorStrategies.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/errorStrategies.scala index a578886..ecb2a0e 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/errorStrategies.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/errorStrategies.scala @@ -59,17 +59,17 @@ case class ErrorStrategies( all(_.retry(schedule)) def retryCountExponential(count: Int, delay: Duration, factor: Double = 2.0, maxDelay: Duration = Duration.Infinity) - (implicit trace: ZTraceElement): ErrorStrategies = + (implicit trace: Trace): ErrorStrategies = all(_.retryCountExponential(count, delay, factor, maxDelay)) - def retryCountFixed(count: Int, delay: Duration)(implicit trace: ZTraceElement): ErrorStrategies = + def retryCountFixed(count: Int, delay: Duration)(implicit trace: Trace): ErrorStrategies = all(_.retryCountFixed(count, delay)) def retryForeverExponential(delay: Duration, factor: Double = 2.0, maxDelay: Duration = Duration.Infinity) - (implicit trace: ZTraceElement): ErrorStrategies = + (implicit trace: Trace): ErrorStrategies = all(_.retryForeverExponential(delay, factor, maxDelay)) - def retryForeverFixed(delay: Duration)(implicit trace: ZTraceElement): ErrorStrategies = + def retryForeverFixed(delay: Duration)(implicit trace: Trace): ErrorStrategies = all(_.retryForeverFixed(delay)) } @@ -98,38 +98,38 @@ trait ErrorStrategy { self => /** How this ErrorStrategy transforms a DB operation. */ - def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: ZTraceElement): ZIO[R, DbException, A] + def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: Trace): ZIO[R, DbException, A] /** Adds a timeout to the current ErrorStrategy. Note that if a retry has already been defined, the timeout is applied * '''after''' the retry. */ def timeout(d: Duration): ErrorStrategy = new ErrorStrategy { - override def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: ZTraceElement): ZIO[R, DbException, A] = + override def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: Trace): ZIO[R, DbException, A] = self(z).timeoutFail(DbException.Timeout(d))(d) } /** Adds a retry to the current ErrorStrategy. */ def retry(schedule: Schedule[Any, Any, Any]): ErrorStrategy = new ErrorStrategy { - def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: ZTraceElement): ZIO[R, DbException, A] = + def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: Trace): ZIO[R, DbException, A] = self(z).retry(schedule) } def retryCountExponential(count: Int, delay: Duration, factor: Double = 2.0, maxDelay: Duration = Duration.Infinity) - (implicit trace: ZTraceElement): ErrorStrategy = { + (implicit trace: Trace): ErrorStrategy = { if (maxDelay == Duration.Infinity) retry(Schedule.recurs(count) && Schedule.exponential(delay, factor)) else retry(Schedule.recurs(count) && (Schedule.exponential(delay, factor) || Schedule.spaced(maxDelay))) } - def retryCountFixed(count: Int, delay: Duration)(implicit trace: ZTraceElement): ErrorStrategy = { + def retryCountFixed(count: Int, delay: Duration)(implicit trace: Trace): ErrorStrategy = { retry(Schedule.recurs(count) && Schedule.spaced(delay)) } def retryForeverExponential(delay: Duration, factor: Double = 2.0, maxDelay: Duration = Duration.Infinity) - (implicit trace: ZTraceElement): ErrorStrategy = { + (implicit trace: Trace): ErrorStrategy = { if (maxDelay == Duration.Infinity) retry(Schedule.exponential(delay, factor)) else retry(Schedule.exponential(delay, factor) || Schedule.spaced(maxDelay)) } - def retryForeverFixed(delay: Duration)(implicit trace: ZTraceElement): ErrorStrategy = { + def retryForeverFixed(delay: Duration)(implicit trace: Trace): ErrorStrategy = { retry(Schedule.spaced(delay)) } } @@ -138,7 +138,7 @@ trait ErrorStrategy { * empty strategy (no timeout and no retry). */ object ErrorStrategy extends ErrorStrategy { - override def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: ZTraceElement): ZIO[R, DbException, A] = z + override def apply[R, A](z: => ZIO[R, DbException, A])(implicit trace: Trace): ZIO[R, DbException, A] = z /** Alias for the ErrorStrategy companion object. Can be used for clarity, to mark when you actually want no retry and no timeout. */ val Nothing: ErrorStrategy = this diff --git a/src/main/scala/io/github/gaelrenoux/tranzactio/test/DatabaseModuleTestOps.scala b/src/main/scala/io/github/gaelrenoux/tranzactio/test/DatabaseModuleTestOps.scala index 680c1c5..ed3d008 100644 --- a/src/main/scala/io/github/gaelrenoux/tranzactio/test/DatabaseModuleTestOps.scala +++ b/src/main/scala/io/github/gaelrenoux/tranzactio/test/DatabaseModuleTestOps.scala @@ -1,7 +1,7 @@ package io.github.gaelrenoux.tranzactio.test import io.github.gaelrenoux.tranzactio._ -import zio.{Tag, ZEnvironment, ZIO, ZLayer, ZTraceElement} +import zio.{Tag, ZEnvironment, ZIO, ZLayer, Trace} /** Testing utilities on the Database module. */ trait DatabaseModuleTestOps[Connection] extends DatabaseModuleBase[Connection, DatabaseOps.ServiceOps[Connection]] { @@ -12,11 +12,11 @@ trait DatabaseModuleTestOps[Connection] extends DatabaseModuleBase[Connection, D /** A Connection which is incapable of running anything, to use when unit testing (and the queries are actually stubbed, * so they do not need a Database). Trying to run actual queries against it will fail. */ - def noConnection(implicit trace: ZTraceElement): ZIO[Any, Nothing, Connection] = connectionFromJdbc(NoopJdbcConnection) + def noConnection(implicit trace: Trace): ZIO[Any, Nothing, Connection] = connectionFromJdbc(NoopJdbcConnection) /** A Database which is incapable of running anything, to use when unit testing (and the queries are actually stubbed, * so they do not need a Database). Trying to run actual queries against it will fail. */ - def none(implicit trace: ZTraceElement): ZLayer[Any, Nothing, AnyDatabase] = + def none(implicit trace: Trace): ZLayer[Any, Nothing, AnyDatabase] = ZLayer.succeed { /* Can't extract this into a static class, both Service and Connection are local to the trait */ new Service { @@ -25,7 +25,7 @@ trait DatabaseModuleTestOps[Connection] extends DatabaseModuleBase[Connection, D * @param errorStrategies Unused. */ override def transaction[R, E, A](zio: => ZIO[Connection with R, E, A], commitOnFailure: => Boolean) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = noConnection.flatMap { c => ZIO.environmentWith[R](_ ++ ZEnvironment(c)) .flatMap(zio.provideEnvironment(_)) @@ -33,7 +33,7 @@ trait DatabaseModuleTestOps[Connection] extends DatabaseModuleBase[Connection, D } override def autoCommit[R, E, A](zio: => ZIO[Connection with R, E, A]) - (implicit errorStrategies: ErrorStrategiesRef, trace: ZTraceElement): ZIO[R, Either[DbException, E], A] = + (implicit errorStrategies: ErrorStrategiesRef, trace: Trace): ZIO[R, Either[DbException, E], A] = noConnection.flatMap { c => ZIO.environmentWith[R](_ ++ ZEnvironment(c)) .flatMap(zio.provideEnvironment(_)) diff --git a/src/samples/scala/samples/SamplesSpec.scala b/src/samples/scala/samples/SamplesSpec.scala index 9756f5f..5c4480a 100644 --- a/src/samples/scala/samples/SamplesSpec.scala +++ b/src/samples/scala/samples/SamplesSpec.scala @@ -1,35 +1,34 @@ package samples -import zio.test.Assertion._ -import zio.test.{ZSpec, _} +import zio.test.{Spec, _} import zio.{Chunk, Scope, ULayer, ZIOAppArgs, ZIOAppDefault, ZLayer} /** Run all samples as ZIO tests */ object SamplesSpec extends ZIOSpecDefault { - type Spec = ZSpec[TestEnvironment, Any] + type MySpec = Spec[TestEnvironment, Any] private val ignoredAppArgs: ULayer[ZIOAppArgs] = ZLayer.succeed(ZIOAppArgs.apply(Chunk.empty)) - override def spec: Spec = + override def spec: MySpec = suite("SamplesSpec")( testApp("Doobie", doobie.LayeredApp), testApp("Doobie-Streaming", doobie.LayeredAppStreaming), testApp("Anorm", anorm.LayeredApp) ) - private def testApp(name: String, app: ZIOAppDefault): Spec = + private def testApp(name: String, app: ZIOAppDefault): MySpec = test(s"$name LayeredApp prints its progress then the trio") { for { _ <- app.run.provide(ignoredAppArgs ++ Scope.default) output <- TestConsole.output - } yield assert(output)(equalTo(Vector( + } yield assertTrue(output == Vector( "Starting the app\n", "Creating the table\n", "Inserting the trio\n", "Reading the trio\n", "Buffy Summers, Willow Rosenberg, Alexander Harris\n" - ))) + )) } } diff --git a/src/samples/scala/samples/anorm/test/SomeTest.scala b/src/samples/scala/samples/anorm/test/SomeTest.scala index 3815f73..794ec02 100644 --- a/src/samples/scala/samples/anorm/test/SomeTest.scala +++ b/src/samples/scala/samples/anorm/test/SomeTest.scala @@ -2,7 +2,6 @@ package samples.anorm.test import io.github.gaelrenoux.tranzactio.anorm._ import samples.anorm.PersonQueries -import zio.test.Assertion._ import zio.test._ import zio.{Scope, ZLayer} @@ -10,20 +9,20 @@ import zio.{Scope, ZLayer} /** This is a test where you check you business methods, using stub queries. */ object SomeTest extends ZIOSpec[TestEnvironment with Database with PersonQueries] { type Env = TestEnvironment with Database with PersonQueries - type Spec = ZSpec[Env, Any] + type MySpec = Spec[Env, Any] /** Using a 'none' Database, because we're not actually using it */ - override def layer: ZLayer[Scope, Any, Env] = testEnvironment ++ PersonQueries.test ++ Database.none + override def bootstrap: ZLayer[Scope, Any, Env] = testEnvironment ++ PersonQueries.test ++ Database.none - override def spec: Spec = suite("My tests with Anorm")( + override def spec: MySpec = suite("My tests with Anorm")( myTest ) - val myTest: Spec = test("some test on a method")( + val myTest: MySpec = test("some test on a method")( for { h <- Database.transaction(PersonQueries.list) // do something with that result - } yield assert(h)(equalTo(Nil)) + } yield assertTrue(h == Nil) ) } diff --git a/src/samples/scala/samples/doobie/LayeredAppStreaming.scala b/src/samples/scala/samples/doobie/LayeredAppStreaming.scala index b42bded..e4d4c56 100644 --- a/src/samples/scala/samples/doobie/LayeredAppStreaming.scala +++ b/src/samples/scala/samples/doobie/LayeredAppStreaming.scala @@ -40,7 +40,7 @@ object LayeredAppStreaming extends zio.ZIOAppDefault { _ <- Console.printLine("Reading the trio").orDie trio <- { val stream: ZStream[PersonQueries with Connection, DbException, Person] = PersonQueries.listStream.take(3) - stream.run(Sink.foldLeft(List[Person]()) { (ps, p) => p :: ps }) + stream.run(ZSink.foldLeft(List[Person]()) { (ps, p) => p :: ps }) } } yield trio.reverse diff --git a/src/samples/scala/samples/doobie/test/SomeTest.scala b/src/samples/scala/samples/doobie/test/SomeTest.scala index 8e214f6..0bc9ca9 100644 --- a/src/samples/scala/samples/doobie/test/SomeTest.scala +++ b/src/samples/scala/samples/doobie/test/SomeTest.scala @@ -10,16 +10,16 @@ import zio.{Scope, ZLayer} /** This is a test where you check you business methods, using stub queries. */ object SomeTest extends ZIOSpec[TestEnvironment with Database with PersonQueries] { type Env = TestEnvironment with Database with PersonQueries - type Spec = ZSpec[Env, Any] + type MySpec = Spec[Env, Any] /** Using a 'none' Database, because we're not actually using it */ - override def layer: ZLayer[Scope, Any, Env] = testEnvironment ++ PersonQueries.test ++ Database.none + override def bootstrap: ZLayer[Scope, Any, Env] = testEnvironment ++ PersonQueries.test ++ Database.none - override def spec: Spec = suite("My tests with Doobie")( + override def spec: MySpec = suite("My tests with Doobie")( myTest ) - val myTest: Spec = test("some test on a method")( + val myTest: MySpec = test("some test on a method")( for { h <- Database.transaction(PersonQueries.list) // do something with that result diff --git a/src/test/scala/io/github/gaelrenoux/tranzactio/SingleConnectionSourceTest.scala b/src/test/scala/io/github/gaelrenoux/tranzactio/SingleConnectionSourceTest.scala index ced2835..b1ca6e0 100644 --- a/src/test/scala/io/github/gaelrenoux/tranzactio/SingleConnectionSourceTest.scala +++ b/src/test/scala/io/github/gaelrenoux/tranzactio/SingleConnectionSourceTest.scala @@ -1,30 +1,29 @@ package io.github.gaelrenoux.tranzactio import zio.Fiber.Status -import zio.test.Assertion._ import zio.test._ import zio.{test => _, _} object SingleConnectionSourceTest extends ZIOSpec[TestEnvironment with ConnectionSource] { type Env = TestEnvironment with ConnectionSource - type Spec = ZSpec[Env, Any] + type MySpec = Spec[Env, Any] implicit private val errorStrategies: ErrorStrategies = ErrorStrategies.Nothing // TODO add aspect to timeout tests to 5 seconds - override def layer: ZLayer[Scope, Any, Env] = csLayer ++ testEnvironment + override def bootstrap: ZLayer[Scope, Any, Env] = csLayer ++ testEnvironment lazy val csLayer: ZLayer[Scope, Nothing, ConnectionSource] = (JdbcLayers.connectionU ++ testEnvironment) >>> ConnectionSource.fromConnection val connectionCountSql = "select count(*) from information_schema.sessions" - def spec: Spec = suite("Single connection ConnectionSource Tests")( + def spec: MySpec = suite("Single connection ConnectionSource Tests")( testDisallowConcurrentTasks ) - private val testDisallowConcurrentTasks: ZSpec[ConnectionSource, Nothing] = test("disallow concurrent tasks") { + private val testDisallowConcurrentTasks: Spec[ConnectionSource, Nothing] = test("disallow concurrent tasks") { def query(trace: Ref[List[String]]) = { trace.update("start" :: _) *> ZIO.sleep(5.second) *> trace.update("end" :: _) } @@ -45,6 +44,6 @@ object SingleConnectionSourceTest extends ZIOSpec[TestEnvironment with Connectio _ <- TestClock.adjust(1.second).repeatWhileZIO(_ => forked.status.map(_ != Status.Done)) _ <- forked.join result <- trace.get - } yield assert(result)(equalTo("end" :: "start" :: "end" :: "start" :: Nil)) + } yield assertTrue(result == "end" :: "start" :: "end" :: "start" :: Nil) } } diff --git a/src/test/scala/io/github/gaelrenoux/tranzactio/integration/AnormIT.scala b/src/test/scala/io/github/gaelrenoux/tranzactio/integration/AnormIT.scala index 7ab965a..439dea5 100644 --- a/src/test/scala/io/github/gaelrenoux/tranzactio/integration/AnormIT.scala +++ b/src/test/scala/io/github/gaelrenoux/tranzactio/integration/AnormIT.scala @@ -23,7 +23,7 @@ object AnormIT extends ITSpec { private def wrap[E, A](z: ZIO[Database with PersonQueries, E, A]): ZIO[Scope, E, A] = z.provideSome(myLayer) - def spec: Spec = suite("Anorm Integration Tests")( + def spec: MySpec = suite("Anorm Integration Tests")( testDataCommittedOnTransactionSuccess, testConnectionClosedOnTransactionSuccess, testDataRollbackedOnTransactionFailure, @@ -35,7 +35,7 @@ object AnormIT extends ITSpec { testConnectionClosedOnAutoCommitFailure ) - private val testDataCommittedOnTransactionSuccess: Spec = test("data committed on transaction success") { + private val testDataCommittedOnTransactionSuccess: MySpec = test("data committed on transaction success") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -45,7 +45,7 @@ object AnormIT extends ITSpec { } } - private val testConnectionClosedOnTransactionSuccess: Spec = test("connection closed on transaction success") { + private val testConnectionClosedOnTransactionSuccess: MySpec = test("connection closed on transaction success") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -55,7 +55,7 @@ object AnormIT extends ITSpec { } } - private val testDataRollbackedOnTransactionFailure: Spec = test("data rollbacked on transaction failure if commitOnFailure=false") { + private val testDataRollbackedOnTransactionFailure: MySpec = test("data rollbacked on transaction failure if commitOnFailure=false") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -65,7 +65,7 @@ object AnormIT extends ITSpec { } } - private val testDataCommittedOnTransactionFailure: Spec = test("data committed on transaction failure if commitOnFailure=true") { + private val testDataCommittedOnTransactionFailure: MySpec = test("data committed on transaction failure if commitOnFailure=true") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -75,7 +75,7 @@ object AnormIT extends ITSpec { } } - private val testConnectionClosedOnTransactionFailure: Spec = test("connection closed on transaction failure") { + private val testConnectionClosedOnTransactionFailure: MySpec = test("connection closed on transaction failure") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -85,7 +85,7 @@ object AnormIT extends ITSpec { } // only the current connection } - private val testDataCommittedOnAutoCommitSuccess: Spec = test("data committed on autoCommit success") { + private val testDataCommittedOnAutoCommitSuccess: MySpec = test("data committed on autoCommit success") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) @@ -95,7 +95,7 @@ object AnormIT extends ITSpec { } } - private val testConnectionClosedOnAutoCommitSuccess: Spec = test("connection closed on autoCommit success") { + private val testConnectionClosedOnAutoCommitSuccess: MySpec = test("connection closed on autoCommit success") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) @@ -105,7 +105,7 @@ object AnormIT extends ITSpec { } // only the current connection } - private val testDataRollbackedOnAutoCommitFailure: Spec = test("data rollbacked on autoCommit failure") { + private val testDataRollbackedOnAutoCommitFailure: MySpec = test("data rollbacked on autoCommit failure") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) @@ -115,7 +115,7 @@ object AnormIT extends ITSpec { } } - private val testConnectionClosedOnAutoCommitFailure: Spec = test("connection closed on autoCommit failure") { + private val testConnectionClosedOnAutoCommitFailure: MySpec = test("connection closed on autoCommit failure") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) diff --git a/src/test/scala/io/github/gaelrenoux/tranzactio/integration/DoobieIT.scala b/src/test/scala/io/github/gaelrenoux/tranzactio/integration/DoobieIT.scala index e426004..0eb2405 100644 --- a/src/test/scala/io/github/gaelrenoux/tranzactio/integration/DoobieIT.scala +++ b/src/test/scala/io/github/gaelrenoux/tranzactio/integration/DoobieIT.scala @@ -26,7 +26,7 @@ object DoobieIT extends ITSpec { private def wrap[E, A](z: ZIO[Database with PersonQueries, E, A]): ZIO[Scope, E, A] = z.provideSome(myLayer) - def spec: Spec = suite("Doobie Integration Tests")( + def spec: MySpec = suite("Doobie Integration Tests")( testDataCommittedOnTransactionSuccess, testConnectionClosedOnTransactionSuccess, testDataRollbackedOnTransactionFailure, @@ -39,7 +39,7 @@ object DoobieIT extends ITSpec { testStreamDoesNotLoadAllValues ) - private val testDataCommittedOnTransactionSuccess: Spec = test("data committed on transaction success") { + private val testDataCommittedOnTransactionSuccess: MySpec = test("data committed on transaction success") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -49,7 +49,7 @@ object DoobieIT extends ITSpec { } } - private val testConnectionClosedOnTransactionSuccess: Spec = test("connection closed on transaction success") { + private val testConnectionClosedOnTransactionSuccess: MySpec = test("connection closed on transaction success") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -59,7 +59,7 @@ object DoobieIT extends ITSpec { } } - private val testDataRollbackedOnTransactionFailure: Spec = test("data rollbacked on transaction failure if commitOnFailure=false") { + private val testDataRollbackedOnTransactionFailure: MySpec = test("data rollbacked on transaction failure if commitOnFailure=false") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -69,7 +69,7 @@ object DoobieIT extends ITSpec { } } - private val testDataCommittedOnTransactionFailure: Spec = test("data committed on transaction failure if commitOnFailure=true") { + private val testDataCommittedOnTransactionFailure: MySpec = test("data committed on transaction failure if commitOnFailure=true") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -79,7 +79,7 @@ object DoobieIT extends ITSpec { } } - private val testConnectionClosedOnTransactionFailure: Spec = test("connection closed on transaction failure") { + private val testConnectionClosedOnTransactionFailure: MySpec = test("connection closed on transaction failure") { wrap { for { _ <- Database.transaction(PersonQueries.setup) @@ -89,7 +89,7 @@ object DoobieIT extends ITSpec { } // only the current connection } - private val testDataCommittedOnAutoCommitSuccess: Spec = test("data committed on autoCommit success") { + private val testDataCommittedOnAutoCommitSuccess: MySpec = test("data committed on autoCommit success") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) @@ -99,7 +99,7 @@ object DoobieIT extends ITSpec { } } - private val testConnectionClosedOnAutoCommitSuccess: Spec = test("connection closed on autoCommit success") { + private val testConnectionClosedOnAutoCommitSuccess: MySpec = test("connection closed on autoCommit success") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) @@ -109,7 +109,7 @@ object DoobieIT extends ITSpec { } // only the current connection } - private val testDataRollbackedOnAutoCommitFailure: Spec = test("data rollbacked on autoCommit failure") { + private val testDataRollbackedOnAutoCommitFailure: MySpec = test("data rollbacked on autoCommit failure") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) @@ -119,7 +119,7 @@ object DoobieIT extends ITSpec { } } - private val testConnectionClosedOnAutoCommitFailure: Spec = test("connection closed on autoCommit failure") { + private val testConnectionClosedOnAutoCommitFailure: MySpec = test("connection closed on autoCommit failure") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) @@ -129,7 +129,7 @@ object DoobieIT extends ITSpec { } } - private val testStreamDoesNotLoadAllValues: Spec = test("stream does not load all values") { + private val testStreamDoesNotLoadAllValues: MySpec = test("stream does not load all values") { wrap { for { _ <- Database.autoCommit(PersonQueries.setup) diff --git a/src/test/scala/io/github/gaelrenoux/tranzactio/integration/ITSpec.scala b/src/test/scala/io/github/gaelrenoux/tranzactio/integration/ITSpec.scala index 7a94717..86835e9 100644 --- a/src/test/scala/io/github/gaelrenoux/tranzactio/integration/ITSpec.scala +++ b/src/test/scala/io/github/gaelrenoux/tranzactio/integration/ITSpec.scala @@ -5,7 +5,7 @@ import zio._ import zio.test.{TestEnvironment, _} abstract class ITSpec extends ZIOSpecDefault { - type Spec = ZSpec[TestEnvironment with Scope, Any] + type MySpec = Spec[TestEnvironment with Scope, Any] implicit val errorStrategies: ErrorStrategies = ErrorStrategies.Nothing