Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 06:28
    hmemcpy commented #4560
  • 05:35
    adamgfraser commented #4549
  • 05:18
    adamgfraser commented #4560
  • 05:08
    adamgfraser commented #4561
  • 02:16
    scala-steward synchronize #4567
  • 01:50

    mergify[bot] on master

    Update mdoc-js, sbt-mdoc to 2.2… (compare)

  • 01:50
    mergify[bot] closed #4569
  • 01:42

    adamgfraser on master

    Fixes a weird spacing in the re… (compare)

  • 01:42
    adamgfraser closed #4575
  • 01:41

    adamgfraser on master

    docs: Add Avast to adopters in … (compare)

  • 01:41
    adamgfraser closed #4574
  • 01:08

    adamgfraser on master

    Add auto.ru to adopters in READ… (compare)

  • 01:08
    adamgfraser closed #4577
  • 00:41

    softinio on gh-pages

    Deploy website Deploy website … (compare)

  • 00:35
    adamgfraser opened #4578
  • Jan 20 20:40
    poslegm opened #4577
  • Jan 20 20:30

    adamgfraser on master

    address flaky tests (#4576) (compare)

  • Jan 20 20:30
    adamgfraser closed #4576
  • Jan 20 19:56
    virusdave commented #4391
  • Jan 20 19:55
    virusdave commented #4391
Tomasz Sosiński
@esthomw
@toxicafunk I will, thanks. Meanwhile, if anybody has any ideas, I will gladly validate them
toxicafunk
@toxicafunk
would need to see some code... but generally speaking, you have to remember ZIOs are only the description of the program, the recipe
so it sounds like you execute the recipe once but not in the same context as the other tests
the specific solution depends on your actual code
but..
one possible way to fix it is to have your tests receive the DB instance itself
so u would excute your migration once, unsafeRun it and then pass it as a dependency to the other tests
since your're using ZLayers them ZLayer.fromFunction might be what u need
maybe it helps @esthomw
Tomasz Sosiński
@esthomw
@toxicafunk thank you for the idea, I will try it out. If I fail I will come with some code samples over github gists
toxicafunk
@toxicafunk
:thumbsup:
e-Evolution
@e-Evolution

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?

Thank you very much for any contribution or feedback
Andreas Gies
@atooni
@e-Evolution Most of the core contributors and ZIO gurus are on discord : https://discord.gg/2ccFBr4 - perhaps it makes sense to repost yor question there
Andreas Gies
@atooni
As for your question, here is an example I have recently implemented in one of my libs. A KeepAliveMonitor is defined in a trait and a default implementation is within an object. https://github.com/blended-zio/blended-zio-streams/blob/main/blended-zio-streams/jvm/src/main/scala/blended/zio/streams/KeepAliveMonitor.scala, it is used at https://github.com/blended-zio/blended-zio-streams/blob/main/blended-zio-streams/jvm/src/main/scala/blended/zio/streams/jms/JmsKeepAliveMonitor.scala to implement a JMS Keep Alive. There are blog posts around the design of the library : http://blended-scala.org/tags/streams/ - Hopefully that gives some hints and ideas
Disclaimer - I am just starting with ZIO
e-Evolution
@e-Evolution
@atooni , thank you your recomendation , I wil send my question in discord
e-Evolution
@e-Evolution
about your implement, I saw not use the module pattern and ZIO Layer
e-Evolution
@e-Evolution
here my issue zio/zio#4495
Serhii Dashko
@sergeda

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]

toxicafunk
@toxicafunk
@sergeda better ask in Discord, see invitation link on the channel's topic
Serhii Dashko
@sergeda
Thank you @toxicafunk
Michal Lacko
@visox
hi all, i am having 2 calls to my db (doobie -> postgres) and i have the 2 calls in zio, now i wanted to race them so
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 finish
any obvious solution, or what i am doing wrong ?
toxicafunk
@toxicafunk
@visox best to ask in discord
even so, you'd need to show some code for us to answer
possible causes are that they're running on separate executors or that one or both of them are running as uninterruptible
without any actual code as to how u build them there's little else anyone can help u with
Yisrael Union
@yisraelU
I noticed putStrLn uses ZIO.effectTotal even though it could fail at runtime with an IO exception . why doesnt it use ZIO.effect
toxicafunk
@toxicafunk
First of all, best to ask in Discord @yisraelU
Technically, everything can fail, but there's something to be said about the difference between errors and defects
For instance, putStrLn is the functional equivalent of println, does println throws any exception?
Yisrael Union
@yisraelU
@toxicafunk I see println call the java class PrintStream, newLine method which handles the exception locally
toxicafunk
@toxicafunk:matrix.org
[m]
exactly, its taken care of upstream so putStrLn has no exception to worry about, which means it cannot fail so it should be effectTotal
of course, your JVM may crash or your pc may break, etc. but within "reason" it cannot fail
Vladimir Ivanovskiy
@vi-p4f
Hi! Why do we need zio runtime in order to convert Resource[Task, HikariTransactor[Task]] into Managed[Throwable, HikariTransactor[Task]]? I thought Resource and Manage are very similar. Here is link for an example: https://github.com/wix-incubator/zorechka-bot/blob/8275d73a2efbe51810d6cfb1d61e5c25ab2c4603/core/src/main/scala/com/wix/zorechka/repos/DbTransactor.scala#L13
toxicafunk
@toxicafunk:matrix.org
[m]
@vi-p4f: you should ask instead in discord
res.toManaged calls ZManaged.make
I would follow that trail or... ask in discord :-)
GOUYETTE Damien
@dgouyette

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
or
findByIdRiskCreatedGame and joinCreatedPersistenceMock ++ GameService.live

Same result :=(

Edmondo Porcu
@edmondo1984
Hello my effectul friends. I have a problem in combining expectations, i.e. in reducing a List[Option[Expectation[A]] into an Expectation[A], where I am "anding" expectations
basically I need to reduce a potentially empty list of expectations into a single expectation, which will always be met if the list is empty
toxicafunk
@toxicafunk:matrix.org
[m]
soudns like u want collect
also, best t ask on discord
Dave Nicponski
@virusdave
Has[A] defect, oh joy!
https://github.com/virusdave/maxinebot/tree/scratch/zio-has-defect
./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:0WebSocketHandler[=1:0]] inside Map(AccessToken -> AccessToken(),
SttpBackend[=λ %1:0 → ZIO[-Any,+Throwable,+1:0],-ZStream[-Any,+Throwable,+Byte],-λ %1:0WebSocketHandler[=1:0]] -> sttp.client.FollowRedirectsBackend@7be6c8a,
Dave Nicponski
@virusdave
Hmm, looks like maybe i hit this: zio/zio#4391
Not sure how to work around it. Setting the system property doesn't seem to have helped.
Dave Nicponski
@virusdave
indeed, this looks more like a problem with the macro than with the equals implementation
toxicafunk
@toxicafunk:matrix.org
[m]
@virusdave: please report on discord