Skip to content

Commit

Permalink
Upgrade To ZIO 2.0.0-RC4 (#234)
Browse files Browse the repository at this point in the history
* upgrade zio version

* remove unused import
  • Loading branch information
adamgfraser authored Apr 4, 2022
1 parent 54ad98f commit 8dae057
Show file tree
Hide file tree
Showing 30 changed files with 275 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import zio.{BootstrapRuntime, Chunk}
import zio.internal.{Platform, Tracing}
import zio.schema.{DeriveSchema, Schema}

import scala.util.Random

object CodecBenchmarks {

val TracedRuntime: BootstrapRuntime = new BootstrapRuntime {
Expand Down
6 changes: 3 additions & 3 deletions docs/overview/first_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object JsonSample extends zio.App {
import ManualConstruction._
import zio.stream.ZStream

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = for {
override def run(args: List[String]): UIO[ExitCode] = for {
_ <- ZIO.unit
person = Person("Michelle", 32)
personToJsonTransducer = JsonCodec.encoder[Person](schemaPerson)
Expand All @@ -139,7 +139,7 @@ object ProtobufExample extends zio.App {
import ManualConstruction._
import zio.stream.ZStream

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = for {
override def run(args: List[String]): UIO[ExitCode] = for {
_ <- ZIO.unit
_ <- ZIO.debug("protobuf roundtrip")
person = Person("Michelle", 32)
Expand Down Expand Up @@ -172,7 +172,7 @@ object CombiningExample extends zio.App {
import ManualConstruction._
import zio.stream.ZStream

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = for {
override def run(args: List[String]): UIO[ExitCode] = for {
_ <- ZIO.unit
_ <- ZIO.debug("combining roundtrip")
person = Person("Michelle", 32)
Expand Down
8 changes: 4 additions & 4 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ object BuildHelper {
val Scala213: String = versions("2.13")
val ScalaDotty: String = "3.1.0" //versions.getOrElse("3.0", versions("3.1"))

val zioVersion = "2.0.0-RC3"
val zioJsonVersion = "0.3.0-RC4"
val zioPreludeVersion = "1.0.0-RC10"
val zioOpticsVersion = "0.2.0-RC2"
val zioVersion = "2.0.0-RC4"
val zioJsonVersion = "0.3.0-RC5"
val zioPreludeVersion = "1.0.0-RC12"
val zioOpticsVersion = "0.2.0-RC3"
val silencerVersion = "1.7.8"

private val testDeps = Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zio.schema.Schema._
import zio.schema.SchemaGen.Json.schema
import zio.test._

object AccessorBuilderSpec extends DefaultRunnableSpec {
object AccessorBuilderSpec extends ZIOSpecDefault {
import TestAccessorBuilder._
import Assertion._

Expand Down
4 changes: 2 additions & 2 deletions tests/shared/src/test/scala/zio/schema/DefaultValueSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import zio.Chunk
import zio.schema.CaseSet.caseOf
import zio.schema.Schema.{ Lazy, Primitive }
import zio.test.Assertion._
import zio.test.{ DefaultRunnableSpec, ZSpec, assert }
import zio.test.{ ZIOSpecDefault, ZSpec, assert }

object DefaultValueSpec extends DefaultRunnableSpec {
object DefaultValueSpec extends ZIOSpecDefault {
// Record Tests
sealed case class UserId(id: String)
sealed case class User(id: UserId, name: String, age: Int)
Expand Down
12 changes: 6 additions & 6 deletions tests/shared/src/test/scala/zio/schema/DiffSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import zio.schema.types.Arities._
import zio.schema.types.{ Arities, Recursive }
import zio.test.Assertion._
import zio.test._
import zio.{ Chunk, Random, URIO, ZIO }
import zio.{ Chunk, URIO, ZIO }

object DiffSpec extends DefaultRunnableSpec with DefaultJavaTimeSchemas {
object DiffSpec extends ZIOSpecDefault with DefaultJavaTimeSchemas {

def spec: ZSpec[Environment, Failure] = suite("DiffSpec")(
suite("identity law")(
Expand Down Expand Up @@ -179,13 +179,13 @@ object DiffSpec extends DefaultRunnableSpec with DefaultJavaTimeSchemas {
)
)

private def diffIdentityLaw[A](implicit schema: Schema[A]): URIO[Random with Sized with TestConfig, TestResult] =
private def diffIdentityLaw[A](implicit schema: Schema[A]): URIO[Sized with TestConfig, TestResult] =
check(DeriveGen.gen[A]) { a =>
assertTrue(schema.diff(a, a).isIdentical)
}

private def semiDynamicDiffLaw[A](
implicit checkConstructor: CheckConstructor[Random with Sized with TestConfig, TestResult],
implicit checkConstructor: CheckConstructor[Sized with TestConfig, TestResult],
schema: Schema[A]
): ZIO[checkConstructor.OutEnvironment, checkConstructor.OutError, TestResult] = {
val semiDynamicSchema = schema.toSemiDynamic
Expand All @@ -204,7 +204,7 @@ object DiffSpec extends DefaultRunnableSpec with DefaultJavaTimeSchemas {
}

private def diffLaw[A](
implicit checkConstructor: CheckConstructor[Random with Sized with TestConfig, TestResult],
implicit checkConstructor: CheckConstructor[Sized with TestConfig, TestResult],
schema: Schema[A]
): ZIO[checkConstructor.OutEnvironment, checkConstructor.OutError, TestResult] = {
val gen = DeriveGen.gen[A]
Expand All @@ -223,7 +223,7 @@ object DiffSpec extends DefaultRunnableSpec with DefaultJavaTimeSchemas {

private def notComparable[A](leftFilter: A => Boolean, rightFilter: A => Boolean)(
assertion: Either[String, A] => Boolean
)(implicit schema: Schema[A]): URIO[Random with Sized with TestConfig, TestResult] = {
)(implicit schema: Schema[A]): URIO[Sized with TestConfig, TestResult] = {
val gen = DeriveGen.gen[A]

check(gen.withFilter(leftFilter) <*> gen.withFilter(rightFilter)) {
Expand Down
22 changes: 11 additions & 11 deletions tests/shared/src/test/scala/zio/schema/DynamicValueGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package zio.schema

import scala.collection.immutable.ListMap

import zio.Chunk
import zio.test._
import zio.{ Chunk, _ }

object DynamicValueGen {

def anyPrimitiveDynamicValue[A](
standardType: StandardType[A]
): Gen[Random with Sized, DynamicValue.Primitive[A]] = {
def gen[A1](typ: StandardType[A1], gen: Gen[Random with Sized, A1]) =
): Gen[Sized, DynamicValue.Primitive[A]] = {
def gen[A1](typ: StandardType[A1], gen: Gen[Sized, A1]) =
gen.map(DynamicValue.Primitive(_, typ))

standardType match {
Expand Down Expand Up @@ -47,7 +47,7 @@ object DynamicValueGen {
}

//scalafmt: { maxColumn = 400 }
def anyDynamicValueOfSchema[A](schema: Schema[A]): Gen[Random with Sized, DynamicValue] =
def anyDynamicValueOfSchema[A](schema: Schema[A]): Gen[Sized, DynamicValue] =
schema match {
case Schema.Primitive(standardType, _) => anyPrimitiveDynamicValue(standardType)
case s: Schema.Record[A] => anyDynamicValueWithStructure(s.structure)
Expand Down Expand Up @@ -90,42 +90,42 @@ object DynamicValueGen {
}
//scalafmt: { maxColumn = 120 }

def anyDynamicLeftValueOfSchema[A](schema: Schema[A]): Gen[Random with Sized, DynamicValue.LeftValue] =
def anyDynamicLeftValueOfSchema[A](schema: Schema[A]): Gen[Sized, DynamicValue.LeftValue] =
anyDynamicValueOfSchema(schema).map(DynamicValue.LeftValue(_))

def anyDynamicRightValueOfSchema[A](schema: Schema[A]): Gen[Random with Sized, DynamicValue.RightValue] =
def anyDynamicRightValueOfSchema[A](schema: Schema[A]): Gen[Sized, DynamicValue.RightValue] =
anyDynamicValueOfSchema(schema).map(DynamicValue.RightValue(_))

def anyDynamicSomeValueOfSchema[A](schema: Schema[A]): Gen[Random with Sized, DynamicValue.SomeValue] =
def anyDynamicSomeValueOfSchema[A](schema: Schema[A]): Gen[Sized, DynamicValue.SomeValue] =
anyDynamicValueOfSchema(schema).map(DynamicValue.SomeValue(_))

def anyDynamicTupleValue[A, B](
left: Schema[A],
right: Schema[B]
): Gen[Random with Sized, DynamicValue.Tuple] =
): Gen[Sized, DynamicValue.Tuple] =
anyDynamicValueOfSchema(left).zip(anyDynamicValueOfSchema(right)).map {
case (l, r) => DynamicValue.Tuple(l, r)
}

def anyDynamicValueOfEnumeration(
structure: ListMap[String, Schema[_]]
): Gen[Random with Sized, DynamicValue.Enumeration] =
): Gen[Sized, DynamicValue.Enumeration] =
for {
index <- Gen.int(0, structure.size - 1)
value <- anyDynamicValueOfSchema(structure.values.toSeq(index))
} yield DynamicValue.Enumeration(structure.keys.toSeq(index) -> value)

def anyDynamicValueOfEnum[A](
cases: Chunk[Schema.Case[_, A]]
): Gen[Random with Sized, DynamicValue.Enumeration] =
): Gen[Sized, DynamicValue.Enumeration] =
for {
index <- Gen.int(0, cases.size - 1)
value <- anyDynamicValueOfSchema(cases(index).codec)
} yield DynamicValue.Enumeration(cases(index).id -> value)

def anyDynamicValueWithStructure(
structure: Chunk[Schema.Field[_]]
): Gen[Random with Sized, DynamicValue.Record] =
): Gen[Sized, DynamicValue.Record] =
Gen
.collectAll(
structure
Expand Down
6 changes: 3 additions & 3 deletions tests/shared/src/test/scala/zio/schema/DynamicValueSpec.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package zio.schema

import zio._
import zio.schema.Schema.Primitive
import zio.schema.SchemaGen._
import zio.test.Assertion._
import zio.test.{ Sized, TestConfig, _ }
import zio.{ Random, _ }

object DynamicValueSpec extends DefaultRunnableSpec {
object DynamicValueSpec extends ZIOSpecDefault {

def spec: ZSpec[Environment, Failure] =
suite("DynamicValueSpec")(
Expand Down Expand Up @@ -85,7 +85,7 @@ object DynamicValueSpec extends DefaultRunnableSpec {
}
)

val primitiveTests: List[ZSpec[Sized with Random with TestConfig, Nothing]] = schemasAndGens.map {
val primitiveTests: List[ZSpec[Sized with TestConfig, Nothing]] = schemasAndGens.map {
case SchemaTest(name, standardType, gen) =>
test(s"round-trips $name") {
dynamicValueLaw(gen, Primitive(standardType, Chunk.empty))
Expand Down
44 changes: 21 additions & 23 deletions tests/shared/src/test/scala/zio/schema/JavaTimeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package zio.schema
import java.time._
import java.time.temporal.ChronoField

import zio.Random
import zio.test.Gen

object JavaTimeGen {

val anyDayOfWeek: Gen[Random, DayOfWeek] = Gen.oneOf(
val anyDayOfWeek: Gen[Any, DayOfWeek] = Gen.oneOf(
Gen.const(DayOfWeek.MONDAY),
Gen.const(DayOfWeek.TUESDAY),
Gen.const(DayOfWeek.WEDNESDAY),
Expand All @@ -18,7 +17,7 @@ object JavaTimeGen {
Gen.const(DayOfWeek.SUNDAY)
)

val anyMonth: Gen[Random, Month] = Gen.oneOf(
val anyMonth: Gen[Any, Month] = Gen.oneOf(
Gen.const(Month.JANUARY),
Gen.const(Month.FEBRUARY),
Gen.const(Month.MARCH),
Expand All @@ -33,24 +32,24 @@ object JavaTimeGen {
Gen.const(Month.DECEMBER)
)

val anyNanoOfDay: Gen[Random, Long] = chronoFieldValue(ChronoField.NANO_OF_DAY)
val anyNanoOfDay: Gen[Any, Long] = chronoFieldValue(ChronoField.NANO_OF_DAY)

val anyEpochDay: Gen[Random, Long] = Gen.long(LocalDate.MIN.toEpochDay, LocalDate.MAX.toEpochDay)
val anyEpochDay: Gen[Any, Long] = Gen.long(LocalDate.MIN.toEpochDay, LocalDate.MAX.toEpochDay)

val anyMonthOfYear: Gen[Random, Int] = chronoFieldValue(ChronoField.MONTH_OF_YEAR).map(_.toInt)
val anyMonthOfYear: Gen[Any, Int] = chronoFieldValue(ChronoField.MONTH_OF_YEAR).map(_.toInt)

val anyMonthDay: Gen[Random, MonthDay] =
val anyMonthDay: Gen[Any, MonthDay] =
for {
month <- anyMonth
dayOfMonth <- Gen.int(1, month.maxLength)
} yield MonthDay.of(month, dayOfMonth)

//Needs to be an ISO-8601 year between 0000 and 9999
val anyIntYear: Gen[Random, Int] = Gen.int(0, 9999)
val anyIntYear: Gen[Any, Int] = Gen.int(0, 9999)

val anyYear: Gen[Random, Year] = anyIntYear.map(Year.of)
val anyYear: Gen[Any, Year] = anyIntYear.map(Year.of)

val anyYearMonth: Gen[Random, YearMonth] =
val anyYearMonth: Gen[Any, YearMonth] =
anyIntYear.zipWith(anyMonthOfYear) { (year, month) =>
YearMonth.of(year, month)
}
Expand All @@ -62,34 +61,34 @@ object JavaTimeGen {

//FIXME There is a bug in JDK Duration parsing that caused issues in zio-json (https://github.com/zio/zio-json/issues/214).
// Do not generate Durations with - seconds.Once that is addressed can remove filter condition
val anyDuration: Gen[Random, Duration] = Gen
val anyDuration: Gen[Any, Duration] = Gen
.long(0, 999999999L)
.zipWith(Gen.long(0, 999999999L)) { (seconds, nanos) =>
Duration.ofSeconds(seconds, nanos)
}

val anyPeriod: Gen[Random, Period] =
val anyPeriod: Gen[Any, Period] =
for {
years <- Gen.int(-99999, 99999)
months <- Gen.int
days <- Gen.int
} yield Period.of(years, months, days)

val anyInstant: Gen[Random, Instant] = Gen
val anyInstant: Gen[Any, Instant] = Gen
.long(Instant.MIN.getEpochSecond, Instant.MAX.getEpochSecond)
.zipWith(Gen.int(Instant.MIN.getNano, Instant.MAX.getNano)) { (seconds, nanos) =>
Instant.ofEpochSecond(seconds, nanos.toLong)
}

val anyLocalDate: Gen[Random, LocalDate] = anyEpochDay.map(LocalDate.ofEpochDay)
val anyLocalDate: Gen[Any, LocalDate] = anyEpochDay.map(LocalDate.ofEpochDay)

val anyLocalTime: Gen[Random, LocalTime] = anyNanoOfDay.map(LocalTime.ofNanoOfDay)
val anyLocalTime: Gen[Any, LocalTime] = anyNanoOfDay.map(LocalTime.ofNanoOfDay)

val anyLocalDateTime: Gen[Random, LocalDateTime] = anyLocalDate.zipWith(anyLocalTime) { (date, time) =>
val anyLocalDateTime: Gen[Any, LocalDateTime] = anyLocalDate.zipWith(anyLocalTime) { (date, time) =>
LocalDateTime.of(date, time)
}

val anyZoneOffset: Gen[Random, ZoneOffset] =
val anyZoneOffset: Gen[Any, ZoneOffset] =
Gen.int(ZoneOffset.MIN.getTotalSeconds, ZoneOffset.MAX.getTotalSeconds).map(ZoneOffset.ofTotalSeconds)

// This uses ZoneRulesProvider which has an effectful static initializer.
Expand All @@ -106,12 +105,11 @@ object JavaTimeGen {
// for {
// ids <- regionZoneIds
// all = ids ++ zoneOffsets
// random <- ZIO.service[Random.Service]
// shuffled <- random.shuffle(all.toList)
// shuffled <- Random.shuffle(all.toList)
// } yield shuffled

//FIXME Sampling causes some sort of pathological performance issue.
val anyZoneId: Gen[Random, ZoneId] = Gen.const(ZoneId.systemDefault())
val anyZoneId: Gen[Any, ZoneId] = Gen.const(ZoneId.systemDefault())
// Gen(ZStream.fromIterableM(zoneIds).map {
// case offset: ZoneOffset => Sample.noShrink(offset)
// // FIXME: This is really slow even when it isn't shrinking.
Expand All @@ -123,15 +121,15 @@ object JavaTimeGen {

// TODO: This needs to be double checked. I have encountered problems generating these in the past.
// See https://github.com/BotTech/scala-hedgehog-spines/blob/master/core/src/main/scala/com/lightbend/hedgehog/generators/time/TimeGenerators.scala
val anyZonedDateTime: Gen[Random, ZonedDateTime] = anyLocalDateTime.zipWith(anyZoneId) { (dateTime, zone) =>
val anyZonedDateTime: Gen[Any, ZonedDateTime] = anyLocalDateTime.zipWith(anyZoneId) { (dateTime, zone) =>
ZonedDateTime.of(dateTime, zone)
}

val anyOffsetTime: Gen[Random, OffsetTime] = anyLocalTime.zipWith(anyZoneOffset) { (time, offset) =>
val anyOffsetTime: Gen[Any, OffsetTime] = anyLocalTime.zipWith(anyZoneOffset) { (time, offset) =>
OffsetTime.of(time, offset)
}

val anyOffsetDateTime: Gen[Random, OffsetDateTime] = anyLocalDateTime.zipWith(anyZoneOffset) { (dateTime, offset) =>
val anyOffsetDateTime: Gen[Any, OffsetDateTime] = anyLocalDateTime.zipWith(anyZoneOffset) { (dateTime, offset) =>
OffsetDateTime.of(dateTime, offset)
}
}
2 changes: 1 addition & 1 deletion tests/shared/src/test/scala/zio/schema/MigrationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import zio.schema.syntax._
import zio.test.AssertionM.Render.param
import zio.test._

object MigrationSpec extends DefaultRunnableSpec {
object MigrationSpec extends ZIOSpecDefault {

override def spec: ZSpec[Environment, Failure] = suite("Migration Spec")(
suite("Derivation")(
Expand Down
Loading

0 comments on commit 8dae057

Please sign in to comment.