-
Notifications
You must be signed in to change notification settings - Fork 17
/
GetRecordsTests.scala
153 lines (147 loc) · 4.79 KB
/
GetRecordsTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package kinesis.mock
import scala.jdk.CollectionConverters._
import cats.effect.IO
import cats.syntax.all._
import software.amazon.awssdk.core.SdkBytes
import software.amazon.awssdk.services.kinesis.model._
import kinesis.mock.instances.arbitrary._
import kinesis.mock.syntax.id._
import kinesis.mock.syntax.javaFuture._
import kinesis.mock.syntax.scalacheck._
class GetRecordsTests extends AwsFunctionalTests {
fixture.test("It should get records") { resources =>
for {
recordRequests <- IO(
putRecordRequestArb.arbitrary
.take(5)
.toVector
.map(
_.copy(streamName = Some(resources.streamName), streamArn = None)
)
.map(x =>
PutRecordRequest
.builder()
.partitionKey(x.partitionKey)
.streamName(resources.streamName.streamName)
.data(SdkBytes.fromByteArray(x.data))
.maybeTransform(x.explicitHashKey)(_.explicitHashKey(_))
.maybeTransform(x.sequenceNumberForOrdering)((req, sequenceNum) =>
req.sequenceNumberForOrdering(sequenceNum.value)
)
.build()
)
)
_ <- recordRequests.traverse(x =>
resources.kinesisClient.putRecord(x).toIO
)
shards <- resources.kinesisClient
.listShards(
ListShardsRequest
.builder()
.streamName(resources.streamName.streamName)
.build()
)
.toIO
.map(_.shards().asScala.toVector)
shardIterators <- shards.traverse(shard =>
resources.kinesisClient
.getShardIterator(
GetShardIteratorRequest
.builder()
.shardId(shard.shardId())
.streamName(resources.streamName.streamName)
.shardIteratorType(ShardIteratorType.TRIM_HORIZON)
.build()
)
.toIO
.map(_.shardIterator())
)
gets <- shardIterators.traverse(shardIterator =>
resources.kinesisClient
.getRecords(
GetRecordsRequest.builder().shardIterator(shardIterator).build()
)
.toIO
)
res = gets.flatMap(_.records().asScala.toVector)
} yield assert(
res.length == 5 && res.forall(rec =>
recordRequests.exists(req =>
req.data.asByteArray.sameElements(rec.data.asByteArray)
&& req.partitionKey == rec.partitionKey
)
),
s"$res\n$recordRequests"
)
}
fixture.test("It should get records with quotes around shard iterator") {
resources =>
for {
recordRequests <- IO(
putRecordRequestArb.arbitrary
.take(1)
.toVector
.map(
_.copy(streamName = Some(resources.streamName), streamArn = None)
)
.map(x =>
PutRecordRequest
.builder()
.partitionKey(x.partitionKey)
.streamName(resources.streamName.streamName)
.data(SdkBytes.fromByteArray(x.data))
.maybeTransform(x.explicitHashKey)(_.explicitHashKey(_))
.maybeTransform(x.sequenceNumberForOrdering)(
(req, sequenceNum) =>
req.sequenceNumberForOrdering(sequenceNum.value)
)
.build()
)
)
_ <- recordRequests.traverse(x =>
resources.kinesisClient.putRecord(x).toIO
)
shards <- resources.kinesisClient
.listShards(
ListShardsRequest
.builder()
.streamName(resources.streamName.streamName)
.build()
)
.toIO
.map(_.shards().asScala.toVector)
shardIterators <- shards.traverse(shard =>
resources.kinesisClient
.getShardIterator(
GetShardIteratorRequest
.builder()
.shardId(shard.shardId())
.streamName(resources.streamName.streamName)
.shardIteratorType(ShardIteratorType.TRIM_HORIZON)
.build()
)
.toIO
.map(_.shardIterator())
)
gets <- shardIterators.traverse(shardIterator =>
resources.kinesisClient
.getRecords(
GetRecordsRequest
.builder()
.shardIterator(s"\"$shardIterator\"")
.build()
)
.toIO
)
res = gets.flatMap(_.records().asScala.toVector)
} yield assert(
res.length == 1 && res.forall(rec =>
recordRequests.exists(req =>
req.data.asByteArray.sameElements(rec.data.asByteArray)
&& req.partitionKey == rec.partitionKey
)
),
s"$res\n$recordRequests"
)
}
}