Skip to content

Commit

Permalink
Update zio to 2.0.0, zio-aws to 5.17.224.4 (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
migiside authored Jul 5, 2022
1 parent 1509dc4 commit cbcc144
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 77 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ developers := List(

publishTo := sonatypePublishToBundle.value

val zioVersion = "2.0.0-RC3"
val zioAwsVersion = "5.17.162.1"
val zioVersion = "2.0.0"
val zioAwsVersion = "5.17.224.4"

libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/zio/sqs/producer/Producer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object Producer {
queueUrl: String,
serializer: Serializer[T],
settings: ProducerSettings = ProducerSettings()
): ZIO[R with Clock with Sqs with Scope, Throwable, Producer[T]] = {
): ZIO[R with Sqs with Scope, Throwable, Producer[T]] = {
val eventQueueSize = nextPower2(settings.batchSize * settings.parallelism)
for {
eventQueue <- ZIO.acquireRelease(Queue.bounded[SqsRequestEntry[T]](eventQueueSize))(_.shutdown)
Expand Down Expand Up @@ -199,7 +199,7 @@ object Producer {
*/
private[sqs] def runSendMessageBatchRequest[R, T](failedQueue: Queue[SqsRequestEntry[T]], retryDelay: Duration, retryMaxCount: Int)(
req: SqsRequest[T]
): RIO[R with Clock with Sqs, Unit] =
): RIO[R with Sqs, Unit] =
zio.aws.sqs.Sqs
.sendMessageBatch(req.inner)
.mapError(_.toThrowable)
Expand All @@ -212,7 +212,7 @@ object Producer {
val (successful, retryable, errors) = responseMapper.tupled(responsePartitioner(res))

for {
_ <- URIO.when(retryable.nonEmpty) {
_ <- ZIO.when(retryable.nonEmpty) {
failedQueue
.offerAll(retryable.map(it => it.copy(retryCount = it.retryCount + 1)))
.delay(retryDelay)
Expand Down
13 changes: 6 additions & 7 deletions src/test/scala/examples/PublishExample.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package examples

import zio.aws.sqs.Sqs
import zio.Clock
import zio.sqs._
import zio.sqs.producer._
import zio.sqs.serialization._
import zio.stream._
import zio.{ ExitCode, RIO, URIO, ZIO, ZLayer }
import zio.{ ExitCode, RIO, UIO, ZIO, ZLayer }

object PublishExample extends zio.ZIOAppDefault {

Expand All @@ -15,14 +14,14 @@ object PublishExample extends zio.ZIOAppDefault {
zio.aws.core.config.AwsConfig.default >>>
zio.aws.sqs.Sqs.live

val events = List("message1", "message2").map(ProducerEvent(_))
val queueName = "TestQueue"
val program: RIO[Clock with Sqs, Either[Throwable, Unit]] = for {
val events = List("message1", "message2").map(ProducerEvent(_))
val queueName = "TestQueue"
val program: RIO[Sqs, Either[Throwable, Unit]] = for {
queueUrl <- Utils.getQueueUrl(queueName)
producer = Producer.make(queueUrl, Serializer.serializeString)
errOrResult <- ZIO.scoped(producer.flatMap(p => p.sendStream(ZStream(events: _*)).runDrain.either))
} yield errOrResult

override def run: URIO[zio.ZEnv, ExitCode] =
program.provideCustomLayer(client).exitCode
override def run: UIO[ExitCode] =
program.provide(client).exitCode
}
7 changes: 3 additions & 4 deletions src/test/scala/examples/TestApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import zio.aws.core.config.CommonAwsConfig
import zio.aws.sqs.Sqs
import software.amazon.awssdk.auth.credentials.{ AwsBasicCredentials, StaticCredentialsProvider }
import software.amazon.awssdk.regions.Region
import zio.Clock
import zio.sqs.producer.{ Producer, ProducerEvent }
import zio.sqs.serialization.Serializer
import zio.sqs.{ SqsStream, SqsStreamSettings, Utils }
Expand All @@ -26,7 +25,7 @@ object TestApp extends zio.ZIOAppDefault {
zio.aws.core.config.AwsConfig.configured() >>>
zio.aws.sqs.Sqs.live

val program: RIO[Sqs with Clock, Unit] = for {
val program: RIO[Sqs, Unit] = for {
_ <- Utils.createQueue(queueName)
queueUrl <- Utils.getQueueUrl(queueName)
producer = Producer.make(queueUrl, Serializer.serializeString)
Expand All @@ -41,6 +40,6 @@ object TestApp extends zio.ZIOAppDefault {
).foreach(msg => ZIO.succeed(println(msg.body)))
} yield ()

override def run: URIO[zio.ZEnv, ExitCode] =
program.provideCustomLayer(client).exitCode
override def run: UIO[ExitCode] =
program.provide(client).exitCode
}
3 changes: 1 addition & 2 deletions src/test/scala/zio/sqs/Util.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package zio.sqs

import zio.Chunk
import zio.Random
import zio.test.{ Gen, Sized }

object Util {

def chunkOfStringsN(n: Int): Gen[Random with Sized, Chunk[String]] = Gen.chunkOfN(n)(Gen.string(Gen.printableChar))
def chunkOfStringsN(n: Int): Gen[Sized, Chunk[String]] = Gen.chunkOfN(n)(Gen.string(Gen.printableChar))

}
4 changes: 2 additions & 2 deletions src/test/scala/zio/sqs/ZioSqsMockServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import zio.aws.sqs.Sqs
import org.elasticmq.rest.sqs.{ SQSRestServer, SQSRestServerBuilder }
import software.amazon.awssdk.auth.credentials.{ AwsBasicCredentials, StaticCredentialsProvider }
import software.amazon.awssdk.regions.Region
import zio.{ Scope, UIO, ZIO, ZLayer }
import zio.{ Scope, ZIO, ZLayer }

object ZioSqsMockServer {
private val staticCredentialsProvider: StaticCredentialsProvider =
Expand All @@ -18,7 +18,7 @@ object ZioSqsMockServer {
val serverResource: ZIO[Any with Scope, Throwable, SQSRestServer] =
ZIO.acquireRelease(
ZIO.attempt(SQSRestServerBuilder.start())
)(server => UIO.succeed(server.stopAndWait()))
)(server => ZIO.succeed(server.stopAndWait()))

val clientResource: ZLayer[AwsConfig, Throwable, Sqs] =
zio.aws.sqs.Sqs.customized(
Expand Down
18 changes: 8 additions & 10 deletions src/test/scala/zio/sqs/ZioSqsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ package zio.sqs
import zio.aws.sqs.Sqs
import zio.aws.sqs.model.Message
import zio._
import zio.Clock
import zio.durationInt
import zio.Random
import zio.sqs.ZioSqsMockServer._
import zio.sqs.producer.{ Producer, ProducerEvent }
import zio.sqs.serialization.Serializer
import zio.test.Assertion._
import zio.test._
import zio.test.{ Live, TestClock, TestEnvironment }

object ZioSqsSpec extends DefaultRunnableSpec {
object ZioSqsSpec extends ZIOSpecDefault {

def spec: ZSpec[TestEnvironment, Any] =
def spec: Spec[TestEnvironment, Any] =
suite("ZioSqsSpec")(
test("send messages") {
val settings: SqsStreamSettings = SqsStreamSettings(stopWhenQueueEmpty = true)
Expand Down Expand Up @@ -60,17 +58,17 @@ object ZioSqsSpec extends DefaultRunnableSpec {
}
).provideCustomLayerShared((zio.aws.netty.NettyHttpClient.default >>> zio.aws.core.config.AwsConfig.default >>> clientResource).orDie)

override def aspects: List[TestAspect[Nothing, TestEnvironment, Nothing, Any]] =
List(TestAspect.executionStrategy(ExecutionStrategy.Sequential))
override def aspects: Chunk[TestAspect[Nothing, TestEnvironment, Nothing, Any]] =
Chunk(TestAspect.executionStrategy(ExecutionStrategy.Sequential))

private val queueName = "TestQueue"

val gen: Gen[Random with Sized, Chunk[String]] = Util.chunkOfStringsN(10)
val gen: Gen[Sized, Chunk[String]] = Util.chunkOfStringsN(10)

def withFastClock: ZIO[TestClock with Live, Nothing, Long] =
Live.withLive(TestClock.adjust(1.seconds))(_.repeat[ZEnv, Long](Schedule.spaced(10.millis)))
def withFastClock: ZIO[Live, Nothing, Long] =
Live.withLive(TestClock.adjust(1.seconds))(_.repeat[Live, Long](Schedule.spaced(10.millis)))

def sendAndGet(messages: Seq[String], settings: SqsStreamSettings): ZIO[TestClock with Live with Clock with Sqs, Throwable, Chunk[Message.ReadOnly]] =
def sendAndGet(messages: Seq[String], settings: SqsStreamSettings): ZIO[Live with Sqs, Throwable, Chunk[Message.ReadOnly]] =
for {
_ <- withFastClock.fork
_ <- Utils.createQueue(queueName)
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/zio/sqs/producer/ProducerErrorSpec.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package zio.sqs.producer

import zio.aws.sqs.model.BatchResultErrorEntry
import zio.ExecutionStrategy
import zio.{ Chunk, ExecutionStrategy }
import zio.test.Assertion._
import zio.test._
import zio.test.TestEnvironment

object ProducerErrorSpec extends DefaultRunnableSpec {
object ProducerErrorSpec extends ZIOSpecDefault {

override def spec: ZSpec[TestEnvironment, Any] =
override def spec: Spec[TestEnvironment, Any] =
suite("ProducerError")(
test("it can be created from BatchResultErrorEntry") {
val event = ProducerEvent("e1")
Expand All @@ -34,6 +34,6 @@ object ProducerErrorSpec extends DefaultRunnableSpec {
}
)

override def aspects: List[TestAspect[Nothing, TestEnvironment, Nothing, Any]] =
List(TestAspect.executionStrategy(ExecutionStrategy.Sequential))
override def aspects: Chunk[TestAspect[Nothing, TestEnvironment, Nothing, Any]] =
Chunk(TestAspect.executionStrategy(ExecutionStrategy.Sequential))
}
11 changes: 5 additions & 6 deletions src/test/scala/zio/sqs/producer/ProducerEventSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package zio.sqs.producer
import java.util.concurrent.TimeUnit

import zio.aws.sqs.model.MessageAttributeValue
import zio.ExecutionStrategy
import zio.Duration
import zio.{ Chunk, Duration, ExecutionStrategy }
import zio.test.Assertion._
import zio.test._
import zio.test.TestEnvironment

object ProducerEventSpec extends DefaultRunnableSpec {
object ProducerEventSpec extends ZIOSpecDefault {

override def spec: ZSpec[TestEnvironment, Any] =
override def spec: Spec[TestEnvironment, Any] =
suite("ProducerEvent")(
test("it can be created") {
val attr = MessageAttributeValue(Some("Jane"), dataType = "String")
Expand Down Expand Up @@ -42,6 +41,6 @@ object ProducerEventSpec extends DefaultRunnableSpec {
}
)

override def aspects: List[TestAspect[Nothing, TestEnvironment, Nothing, Any]] =
List(TestAspect.executionStrategy(ExecutionStrategy.Sequential))
override def aspects: Chunk[TestAspect[Nothing, TestEnvironment, Nothing, Any]] =
Chunk(TestAspect.executionStrategy(ExecutionStrategy.Sequential))
}
Loading

0 comments on commit cbcc144

Please sign in to comment.