mergify[bot] on master
Update mdoc-js, sbt-mdoc to 2.2… (compare)
adamgfraser on master
Fixes a weird spacing in the re… (compare)
adamgfraser on master
docs: Add Avast to adopters in … (compare)
adamgfraser on master
Add auto.ru to adopters in READ… (compare)
softinio on gh-pages
Deploy website Deploy website … (compare)
adamgfraser on master
address flaky tests (#4576) (compare)
DB
instance itself
unsafeRun
it and then pass it as a dependency to the other tests
ZLayer.fromFunction
might be what u need
Hello everyone in this fantastic community.
Currently, I am using ZIO as the main library for the development of an application using the Domain-Driven Design and Clean Architecture approach.
When trying to implement the ZIO module explained in https://zio.dev/docs/howto/howto_use_layers#our-first-zio-module and Chapter 18 "Advanced Dependency injection of ZIOnomicon" we realize that a trait is defined to establish the API of service, but at the same time in most of the examples and documentation available, the implementation is in the same place that trait Service that defines of contract or API, which for DDD represents two different layers, that is, the definition of the contract, interface, trait or API is declared in separate classes so that later its implementation is made for infrastructure layer in a specific technology.
Why the trait or API is together with implementación when coupling should be avoided?
So in your recommendation, it is a bit confusing because the contract, interface, the trait is together with the implementation, in DDD there are two different class, one to define API and other class to implementation?
On the other hand, when trying to use a trait to define a universal API and then extend it to define the Service class, the tag @accessible does not generate the accessors methods.
trait contractPartiesTypeServiceApi {
trait Api[-R] {
def getByContractPartiesTypeId(contractPartiesTypeId: Id): RIO[R, Option[ContractPartiesType]]
def getByDescription(description: Option[String]): RIO[R, List[ContractPartiesType]]
def getByName(name: String): RIO[R, Option[ContractPartiesType]]
def getByValue(value: Option[String]): RIO[R, Option[ContractPartiesType]]
def getAll: RIO[R, List[ContractPartiesType]]
def getAll(clientId: TableDirect): RIO[R, List[ContractPartiesType]]
}
}
package object contractPartiesTypeService extends contractPartiesTypeServiceApi {
type ContractPartiesTypeService = Has[ContractPartiesTypeService.Service]
@accessor
object ContractPartiesTypeService {
trait Service extends Api[ContractPartiesTypeService] {}
}
}
currently, this forces me to duplicate code to define trait Service and its methods for each implementation, when I should only define the trait or Api in one class, and then extend the API in each implementation
Do you have any recommendations?
Is it possible for @accessible to generate the methods even if the trait Service extends from another class that contains the API?
Hello guys.
I'm starting with ZIO and Dotty at the same time. And I can't figure out how to make cats interop work in Dotty. I tried to pass ExecutionContext explicitly in the BlazeServerBuilder.apply function and implicitly - it doesn't work. Does anyone know how to do this correctly in Dotty?
val server: ZManaged[Any, Throwable, Server[Task]] = ZIO.runtime[Any].toManaged_.flatMap { implicit runtime =>
import zio.interop.catz.implicits._
import scala.language.implicitConversions
implicit val ec: ExecutionContext = runtime.platform.executor.asEC
BlazeServerBuilder[Task]
.bindHttp(8080, "localhost")
.withHttpApp(httpApp)
.resource
.toManagedZIO }
I'm getting error:
Cannot find implicit value for ConcurrentEffect[zio.Task].
Building this implicit value might depend on having an implicit
s.c.ExecutionContext in scope, a Scheduler, a ContextShift[zio.Task]
or some equivalent type.
BlazeServerBuilder[Task]
zio1.race(zio2)
i can tell from the logs that zio2 finished but the zio1 was not interupted ... it all waited for the zio1 to finishuninterruptible
putStrLn
is the functional equivalent of println
, does println
throws any exception?
putStrLn
has no exception to worry about, which means it cannot fail
so it should be effectTotal
it cannot fail
res.toManaged
calls ZManaged.make
Hello,
I have an issue with mocks, and i don't understand my mistake :
My tests :
val riskStartedGameId = new ObjectId("000000000000000000000002");
val joinUserId = new ObjectId("000000000000000000000004")
val joiningUser = User(joinUserId, "joining@user.com", "Joining User")
testM("3 joining an existing game in created status should be successful") {
for {
joinResult <- GameService.join(riskCreatedGameId, joiningUser)
} yield assert(joinResult)(isUnit)
}.provideCustomLayer(findByIdRiskCreatedGame and joinCreatedPersistenceMock ++ GameService.live)
The implementation
object GameService {
type GameService = Has[GameService.Service]
trait Service {
def findById(_id : ObjectId): RIO[GamePersistence , Option[Game]]
def join(existingGame: ObjectId, joiningUser: User):ZIO[GameService with GamePersistence ,AppError, Unit]
}
val live = ZLayer.succeed(
new GameService.Service {
override def findById(_id: ObjectId): RIO[GamePersistence, Option[Game]] = GamePersistence.findById(_id)
override def join(existingGameId: ObjectId, joiningUser: User): ZIO[GameService with GamePersistence, AppError, Unit] = {
for {
gameOpt <- GamePersistence.findById(existingGameId).mapError(th => DatabaseAccessError(th.getMessage))
game <- ZIO.fromOption(gameOpt).mapError(s => DataValidationError("Game not found"))
_ <- GamePersistence.join(existingGameId, joiningUser._id)
.foldM(
e => ZIO.fail(DatabaseAccessError(e.getMessage)),
ZIO.succeed(_)
)
_ <- ZIO.fromEither(canJoin(game))
} yield ()
}
}
)
When i execute my unit tests, i got the following error :
[info] - GameServiceSpec
[info] - 3 joining an existing game in created status should be successful
[info] - could not find a matching expectation
[info] - invalid call to .mocks.GamePersistenceMock.FindById
[info] expected .mocks.GamePersistenceMock.Join with arguments equalTo((000000000000000000000001,000000000000000000000004))
I tried to make my mocks more tolerant (according to this documentation) : https://github.com/zio/zio/blob/master/docs/howto/mock_services.md,
using :
findByIdRiskCreatedGame ++ joinCreatedPersistenceMock ++ GameService.live
orfindByIdRiskCreatedGame and joinCreatedPersistenceMock ++ GameService.live
Same result :=(
Has[A]
defect, oh joy!./bazel run //experimental:slack
will demonstrate this (need to either have Bazel 3+ or Nix installed)
java.lang.Error: Defect in zio.Has: Could not find SttpBackend[=λ %1:0 → ZIO[-Any,+Throwable,+1:0],-Nothing,-λ %1:0 → WebSocketHandler[=1:0]] inside Map(AccessToken -> AccessToken(),
SttpBackend[=λ %1:0 → ZIO[-Any,+Throwable,+1:0],-ZStream[-Any,+Throwable,+Byte],-λ %1:0 → WebSocketHandler[=1:0]] -> sttp.client.FollowRedirectsBackend@7be6c8a,