-
Notifications
You must be signed in to change notification settings - Fork 3
Upgrade to ZIO 2 #48
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
base: master
Are you sure you want to change the base?
Upgrade to ZIO 2 #48
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| package io.km8.core.kafka | ||
|
|
||
| import zio.* | ||
| import zio.blocking.Blocking | ||
| import zio.clock.Clock | ||
| import zio.duration.* | ||
| import zio.kafka.consumer.* | ||
|
|
@@ -16,19 +15,19 @@ import org.apache.kafka.clients.consumer.OffsetResetStrategy | |
|
|
||
| object KafkaProducerSpec extends DefaultRunnableSpec: | ||
|
|
||
| private val consumerLayer: ZLayer[Has[KafkaContainer], Nothing, Has[KafkaConsumer]] = | ||
| Clock.live ++ Blocking.live ++ itlayers.clusterConfig(clusterId = "cluster_id") >>> KafkaConsumer.liveLayer | ||
| private val consumerLayer: ZLayer[KafkaContainer, Nothing, KafkaConsumer] = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comment here: should we try automatic layer creation without operators?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure why would that be necessary, if possible I would use operators to speed up compile time |
||
| Clock.live ++ itlayers.clusterConfig(clusterId = "cluster_id") >>> KafkaConsumer.liveLayer | ||
|
|
||
| private val producerLayer: ZLayer[Has[KafkaContainer], Nothing, KafkaProducer] = | ||
| Blocking.live ++ itlayers.clusterConfig(clusterId = "cluster_id") >>> KafkaProducer.liveLayer | ||
| private val producerLayer: ZLayer[KafkaContainer, Nothing, KafkaProducer] = | ||
| itlayers.clusterConfig(clusterId = "cluster_id") >>> KafkaProducer.liveLayer | ||
|
|
||
| val specLayer: ZLayer[Has[KafkaContainer], Nothing, Has[KafkaConsumer] & KafkaProducer] = | ||
| val specLayer: ZLayer[KafkaContainer, Nothing, KafkaConsumer & KafkaProducer] = | ||
| consumerLayer ++ producerLayer | ||
|
|
||
| override def spec: ZSpec[_root_.zio.test.environment.TestEnvironment, Any] = | ||
| mainSpec | ||
| .provideSomeLayer[environment.TestEnvironment & Has[KafkaContainer]](specLayer ++ Clock.live) | ||
| .provideCustomLayerShared(Blocking.live >>> itlayers.kafkaContainer) | ||
| .provideSomeLayer[environment.TestEnvironment & KafkaContainer](specLayer ++ Clock.live) | ||
| .provideCustomLayerShared(itlayers.kafkaContainer) | ||
|
|
||
| private val mainSpec = | ||
| suite("Kafka services")( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ package io.km8.core.kafka | |
| import com.dimafeng.testcontainers.KafkaContainer | ||
| import zio.* | ||
| import zio.clock.Clock | ||
| import zio.blocking.* | ||
| import zio.kafka.consumer.Consumer | ||
| import zio.kafka.consumer.Consumer.{AutoOffsetStrategy, OffsetRetrieval} | ||
| import zio.kafka.consumer.ConsumerSettings | ||
|
|
@@ -12,7 +11,7 @@ import io.km8.core.config.{ClusterConfig, ClusterProperties, ClusterSettings} | |
|
|
||
| object itlayers: | ||
|
|
||
| val kafkaContainer: ZLayer[Blocking, Nothing, Has[KafkaContainer]] = | ||
| val kafkaContainer: ZLayer[Any, Nothing, KafkaContainer] = | ||
| ZManaged.make { | ||
| effectBlocking { | ||
| val container = new KafkaContainer() | ||
|
|
@@ -21,7 +20,7 @@ object itlayers: | |
| }.orDie | ||
| }(container => effectBlocking(container.stop()).orDie).toLayer | ||
|
|
||
| def consumerSettings(cg: String): ZManaged[Has[KafkaContainer], Nothing, ConsumerSettings] = | ||
| def consumerSettings(cg: String): ZManaged[KafkaContainer, Nothing, ConsumerSettings] = | ||
| ZIO | ||
| .service[KafkaContainer] | ||
| .map(c => | ||
|
|
@@ -31,10 +30,10 @@ object itlayers: | |
| ) | ||
| .toManaged_ | ||
|
|
||
| def consumerLayer(cgroup: String): ZLayer[Has[KafkaContainer] with Clock with Blocking, Nothing, Has[Consumer]] = | ||
| def consumerLayer(cgroup: String): ZLayer[KafkaContainer with Clock , Nothing, Consumer] = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we write |
||
| consumerSettings(cgroup).flatMap(Consumer.make(_)).orDie.toLayer | ||
|
|
||
| def clusterConfig(clusterId: String): ZLayer[Has[KafkaContainer], Nothing, Has[ClusterConfig]] = | ||
| def clusterConfig(clusterId: String): ZLayer[KafkaContainer, Nothing, ClusterConfig] = | ||
| ZIO | ||
| .service[KafkaContainer] | ||
| .map(kafkaContainer => | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we skip over composing layers live this and use the
ZLayer.makewith automatic injection?