Skip to content

Commit

Permalink
Support Scala3 #major (#301)
Browse files Browse the repository at this point in the history
* Support Scala3 #major

- Remove Scanamo module as it is blocking Scala3 support
- Made some deprecated classes private
- Fixed scalac warning
- Upgrade libs to latest

* Remove test that checks number of internal requests

Since retrieve no longer takes limit, it returns a `fs2.Stream` instead.
Limit is now set by caller by calling `.take(x)` on the stream.

* update to Scala v3.3.1

* Bump scala 2.13 to latest

* Bump to latest sbt

* Remove mentioning of `scanamo` from documentation is it has been removed
as project's dependencies.

* Clean up left over plugin during Scala 3 migration.

---------

Co-authored-by: marko asplund <[email protected]>
  • Loading branch information
d2a4u and marko-asplund authored Dec 11, 2023
1 parent 7ef33d7 commit 37cd88d
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 466 deletions.
4 changes: 2 additions & 2 deletions awssdk/src/it/scala/DeleteOpsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DeleteOpsSpec extends ITSpec {
behavior.of("delete operation")

it should "delete an item when using both keys" in forAll {
test: TestData =>
(test: TestData) =>
compositeKeysTable[IO].use {
case (client, table) =>
val put = client.put[TestData](table.tableName, test)
Expand All @@ -26,7 +26,7 @@ class DeleteOpsSpec extends ITSpec {
}

it should "delete an item when using partition key only (table doesn't have range key)" in forAll {
test: TestDataSimple =>
(test: TestDataSimple) =>
partitionKeyTable[IO].use {
case (client, table) =>
val put = client.put[TestDataSimple](table.tableName, test)
Expand Down
4 changes: 2 additions & 2 deletions awssdk/src/it/scala/GetOpsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GetOpsSpec extends ITSpec {
behavior.of("get operation")

it should "return inserted item using partition key and range key" in forAll {
test: TestData =>
(test: TestData) =>
compositeKeysTable[IO].use[Option[TestData]] {
case (client, table) =>
client.put[TestData](table.tableName, test) >>
Expand All @@ -23,7 +23,7 @@ class GetOpsSpec extends ITSpec {
}

it should "return inserted item using partition key only (table doesn't have range key)" in forAll {
test: TestDataSimple =>
(test: TestDataSimple) =>
partitionKeyTable[IO].use[Option[TestDataSimple]] {
case (client, table) =>
client.put[TestDataSimple](table.tableName, test) >>
Expand Down
14 changes: 7 additions & 7 deletions awssdk/src/it/scala/PutOpsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class PutOpsSpec extends ITSpec {
behavior.of("put operation")

it should "success inserting item with both keys" in forAll {
test: TestData =>
(test: TestData) =>
compositeKeysTable[IO].use {
case (client, table) =>
client.put[TestData](table.tableName, test)
}.unsafeToFuture().futureValue shouldBe an[Unit]
}

it should "return old value after successfully inserting item with both keys" in forAll {
old: TestData =>
(old: TestData) =>
val updated = old.copy(str = old.str + "-updated")
compositeKeysTable[IO].use {
case (client, table) =>
Expand All @@ -33,15 +33,15 @@ class PutOpsSpec extends ITSpec {
}

it should "return none if there isn't a previous record with the same keys" in forAll {
test: TestData =>
(test: TestData) =>
compositeKeysTable[IO].use {
case (client, table) =>
client.put[TestData, TestData](table.tableName, test)
}.unsafeToFuture().futureValue shouldEqual None
}

it should "success inserting item without sort key" in forAll {
test: TestDataSimple =>
(test: TestDataSimple) =>
val result = partitionKeyTable[IO].use {
case (client, table) =>
client.put[TestDataSimple](table.tableName, test)
Expand All @@ -50,7 +50,7 @@ class PutOpsSpec extends ITSpec {
}

it should "return old value after successfully inserting item without sort key" in forAll {
old: TestDataSimple =>
(old: TestDataSimple) =>
val updated = old.copy(data = old.data + "-updated")
partitionKeyTable[IO].use {
case (client, table) =>
Expand All @@ -62,7 +62,7 @@ class PutOpsSpec extends ITSpec {
}

it should "success inserting item if key(s) doesn't exist by using condition expression" in forAll {
test: TestData =>
(test: TestData) =>
compositeKeysTable[IO].use {
case (client, table) =>
client.put[TestData](
Expand All @@ -78,7 +78,7 @@ class PutOpsSpec extends ITSpec {
}

it should "fail inserting item if key(s) exists by using condition expression" in forAll {
test: TestData =>
(test: TestData) =>
val result = compositeKeysTable[IO].use {
case (client, table) =>
client.put[TestData](
Expand Down
44 changes: 9 additions & 35 deletions awssdk/src/it/scala/RetrieveOpsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RetrieveOpsSpec extends ITSpec {
behavior.of("retrieve operation")

it should "return multiple items of the same partition key" in forAll {
test: TestData =>
(test: TestData) =>
val partitionKey = Id("def")
val input =
List(
Expand All @@ -24,8 +24,7 @@ class RetrieveOpsSpec extends ITSpec {
val retrieval = client.retrieve[Id, TestData](
table,
partitionKey,
consistentRead = false,
Int.MaxValue
consistentRead = false
).compile.toList
input.traverse(i =>
client.put[TestData](table.tableName, i)
Expand All @@ -36,7 +35,7 @@ class RetrieveOpsSpec extends ITSpec {
}

it should "exact item by EqualTo key expression" in forAll {
test: TestData =>
(test: TestData) =>
val result = compositeKeysTable[IO].use[TestData] {
case (client, table) =>
val retrieval = client.retrieve[Id, Range, TestData](
Expand All @@ -45,16 +44,15 @@ class RetrieveOpsSpec extends ITSpec {
test.id,
SortKeyQuery.EqualTo(test.range)
),
consistentRead = false,
Int.MaxValue
consistentRead = false
).compile.lastOrError
client.put[TestData](table.tableName, test) >> retrieval
}.unsafeToFuture().futureValue
result shouldEqual test
}

it should "query secondary index" in forAll {
test: TestData =>
(test: TestData) =>
val input = test.copy(str = "test", int = 0)
val result =
compositeKeysWithSecondaryIndexTable[IO].use {
Expand All @@ -65,16 +63,15 @@ class RetrieveOpsSpec extends ITSpec {
input.str,
SortKeyQuery.EqualTo(input.int)
),
consistentRead = false,
Int.MaxValue
consistentRead = false
).compile.lastOrError
client.put[TestData](table.tableName, input) >> retrieval
}.unsafeToFuture().futureValue
result shouldEqual input
}

it should "filter results by given filter expression for PartitionKeyTable" in forAll {
test: TestData =>
(test: TestData) =>

partitionKeyTable[IO].use {
case (client, table) =>
Expand Down Expand Up @@ -109,7 +106,7 @@ class RetrieveOpsSpec extends ITSpec {
}

it should "filter results by given filter expression for CompositeKeysTable" in forAll {
test: List[TestData] =>
(test: List[TestData]) =>
val unique = test.map(t => (t.id, t.range) -> t).toMap.values.toList
val partitionKey = Id(Instant.now.toString)
val testUpdated = unique.map(t => t.copy(id = partitionKey))
Expand All @@ -131,34 +128,11 @@ class RetrieveOpsSpec extends ITSpec {
)
)
),
consistentRead = false,
Int.MaxValue
consistentRead = false
).compile.toList
testUpdated.traverse(i =>
client.put[TestData](table.tableName, i)
) >> Util.retryOf(retrieval)(_.size == input.length)
}.unsafeToFuture().futureValue should contain theSameElementsAs input
}

it should "limit internal requests" in forAll {
(test1: TestData, test2: TestData) =>
val partitionKey = Id("def")
val input =
List(test1.copy(id = partitionKey), test2.copy(id = partitionKey))
val result = compositeKeysTable[IO].use[List[fs2.Chunk[TestData]]] {
case (client, table) =>
val retrieval = client.retrieve[Id, Range, TestData](
table,
Query[Id, Range](partitionKey, SortKeyQuery.empty[Range]),
consistentRead = false,
1
).chunks.compile.toList
input.traverse(i =>
client.put[TestData](table.tableName, i)
) >> Util.retryOf(retrieval)(
_.size == input.length
)
}.unsafeToFuture().futureValue
result.forall(_.size == 1) shouldBe true
}
}
14 changes: 7 additions & 7 deletions awssdk/src/it/scala/UpdateOpsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class UpdateOpsSpec extends ITSpec {
behavior.of("update operation")

it should "return new value when condition is met" in forAll {
data: TestData =>
(test: TestData) =>
// condition is int > 0
val newInt = 2
val input = data.copy(int = 1)
val expected = data.copy(int = newInt)
val input = test.copy(int = 1)
val expected = test.copy(int = newInt)
val result = compositeKeysTable[IO].use {
case (client, table) =>
client.put[TestData](table.tableName, input) >>
Expand All @@ -41,10 +41,10 @@ class UpdateOpsSpec extends ITSpec {
}

it should "return old value when condition is met" in forAll {
data: TestData =>
(test: TestData) =>
// condition is int > 0
val newInt = 2
val input = data.copy(int = 1)
val input = test.copy(int = 1)
val result = compositeKeysTable[IO].use {
case (client, table) =>
client.put[TestData](table.tableName, input) >>
Expand All @@ -69,10 +69,10 @@ class UpdateOpsSpec extends ITSpec {
}

it should "raise error when condition is not met" in forAll {
data: TestData =>
(test: TestData) =>
// condition is int > 0
val newInt = 2
val input = data.copy(int = -1)
val input = test.copy(int = -1)
val result = compositeKeysTable[IO].use {
case (client, table) =>
client.put[TestData](table.tableName, input) >>
Expand Down
21 changes: 4 additions & 17 deletions awssdk/src/it/scala/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,18 @@ private[meteor] object Util {
def partitionKeyTable[F[_]: Async]
: Resource[F, (Client[F], PartitionKeyTable[Id])] =
internalSimpleResources[F].map {
case (c, t, _, _, _, _) => (c, t)
case (c, t, _, _, _) => (c, t)
}

def simpleTable[F[_]: Async]: Resource[F, SimpleTable[F, Id]] =
internalSimpleResources[F].map {
case (_, _, t, _, _, _) => t
}

def secondarySimpleIndex[F[_]: Async]
: Resource[F, (SimpleTable[F, Id], SecondarySimpleIndex[F, Range])] =
internalSimpleResources[F].map {
case (_, _, _, t, i, _) => (t, i)
case (_, _, t, _, _) => t
}

def globalSecondarySimpleIndex[F[_]: Async]
: Resource[F, (SimpleTable[F, Id], GlobalSecondarySimpleIndex[F, Range])] =
internalSimpleResources[F].map {
case (_, _, _, t, _, i) => (t, i)
case (_, _, _, t, i) => (t, i)
}

def compositeKeysTable[F[_]: Async]
Expand Down Expand Up @@ -120,7 +114,6 @@ private[meteor] object Util {
PartitionKeyTable[Id],
SimpleTable[F, Id],
SimpleTableWithGlobIndex[F, Id],
SecondarySimpleIndex[F, Range],
GlobalSecondarySimpleIndex[F, Range]
)
] = {
Expand All @@ -146,12 +139,6 @@ private[meteor] object Util {
hashKey1,
jClient
)
ssi = SecondarySimpleIndex[F, Range](
simpleRandomNameWithGlobIndex,
simpleRandomIndexName,
glob2ndHashKey,
jClient
)
gssi = GlobalSecondarySimpleIndex[F, Range](
simpleRandomNameWithGlobIndex,
simpleRandomIndexName,
Expand Down Expand Up @@ -186,7 +173,7 @@ private[meteor] object Util {
)
)
)(_ => client.deleteTable(simpleRandomNameWithGlobIndex))
} yield (client, pkt, st, stgi, ssi, gssi)
} yield (client, pkt, st, stgi, gssi)
}

private def internalCompositeResources[F[_]: Async]: Resource[
Expand Down
32 changes: 0 additions & 32 deletions awssdk/src/it/scala/api/hi/SimpleIndexSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,4 @@ class SimpleIndexSpec extends ITSpec {
fail()
}
}

"SecondarySimpleIndex" should "filter results by given filter expression" in {
def retrieval(index: SimpleIndex[IO, Range], cond: Boolean) =
index.retrieve[TestData](
Query(
data.range,
Expression(
"#b = :bool",
Map("#b" -> "bool"),
Map(
":bool" -> Encoder[Boolean].write(cond)
)
)
),
consistentRead = false
)

secondarySimpleIndex[IO].use {
case (table, index) =>
val read = for {
some <- retrieval(index, data.bool)
none <- retrieval(index, !data.bool)
} yield (some, none)
table.put[TestData](data) >> read
}.unsafeToFuture().futureValue match {
case (Some(d), None) =>
d shouldEqual data

case _ =>
fail()
}
}
}
Loading

0 comments on commit 37cd88d

Please sign in to comment.