aws-kclrb 2.1.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -37
- data/VERSION +1 -1
- data/lib/aws/kclrb/kcl_process.rb +2 -2
- data/pom.xml +71 -23
- data/spec/kcl_process_spec.rb +99 -41
- metadata +35 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3beff85e7553d852f6c1dfadd44ee7279fdb29256f2ed40fd98358b51751ae72
|
4
|
+
data.tar.gz: 3c63d7db385a48655dfde264d574859084d71aa7eb5dd3f4642673e8076fca53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c6979336047673a21d5012c4ecd7afb23e51c51aa510b359b5520af40911ceff6a32db68f496fa6c55d2d9112ff9b754607e7a1d2badd47f8a4b943c84ad983
|
7
|
+
data.tar.gz: b180e3db5cf893c5104cd2522eb5d997015f241be081d974f0f5deb317177d2934a95dc7ef6d805c4cc64d6d98c28581d9c21e0199bc32c7c6ccd3e66171d8cf
|
data/README.md
CHANGED
@@ -11,38 +11,38 @@ This package wraps and manages the interaction with the [MultiLangDaemon][multi-
|
|
11
11
|
executable. A record processor in Ruby typically looks something like:
|
12
12
|
|
13
13
|
```ruby
|
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
|
-
|
14
|
+
#! /usr/bin/env ruby
|
15
|
+
|
16
|
+
require 'aws/kclrb'
|
17
|
+
|
18
|
+
class SampleRecordProcessor < Aws::KCLrb::V2::RecordProcessorBase
|
19
|
+
def init_processor(initialize_input)
|
20
|
+
# initialize
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_records(process_records_input)
|
24
|
+
# process batch of records
|
25
|
+
end
|
26
|
+
|
27
|
+
def lease_lost(lease_lost_input)
|
28
|
+
# lease was lost, cleanup
|
29
|
+
end
|
30
|
+
|
31
|
+
def shard_ended(shard_ended_input)
|
32
|
+
# shard has ended, cleanup
|
33
|
+
end
|
34
|
+
|
35
|
+
def shutdown_requested(shutdown_requested_input)
|
36
|
+
# shutdown has been requested
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if __FILE__ == $0
|
41
|
+
# Start the main processing loop
|
42
|
+
record_processor = SampleRecordProcessor.new
|
43
|
+
driver = Aws::KCLrb::KCLProcess.new(record_processor)
|
44
|
+
driver.run
|
45
|
+
end
|
46
46
|
```
|
47
47
|
|
48
48
|
## Before You Get Started
|
@@ -51,7 +51,7 @@ Before running the samples, you'll want to make sure that your environment is
|
|
51
51
|
configured to allow the samples to use your
|
52
52
|
[AWS Security Credentials](http://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html).
|
53
53
|
|
54
|
-
By default the samples use the [
|
54
|
+
By default the samples use the [DefaultCredentialsProvider][DefaultCredentialsProvider]
|
55
55
|
so you'll want to make your credentials available to one of the credentials providers in that
|
56
56
|
provider chain. There are several ways to do this such as providing a `~/.aws/credentials` file,
|
57
57
|
or if you're running on Amazon EC2, you can associate an IAM role with your instance with appropriate
|
@@ -94,11 +94,11 @@ To run the data producer, run the following commands:
|
|
94
94
|
|
95
95
|
#### Notes
|
96
96
|
|
97
|
-
* The [AWS Ruby SDK gem][aws-ruby-sdk-gem] needs to be installed as a pre-requisite. To install,
|
97
|
+
* The [AWS Ruby SDK gem][aws-ruby-sdk-gem] for Kinesis needs to be installed as a pre-requisite. To install,
|
98
98
|
run:
|
99
99
|
|
100
100
|
```sh
|
101
|
-
sudo gem install aws-sdk
|
101
|
+
sudo gem install aws-sdk-kinesis
|
102
102
|
```
|
103
103
|
|
104
104
|
* The script `samples/sample_kcl_producer.rb` takes several parameters that you can use
|
@@ -187,6 +187,40 @@ all languages.
|
|
187
187
|
|
188
188
|
## Release Notes
|
189
189
|
|
190
|
+
### Release 3.0.0 (November 6, 2024)
|
191
|
+
* New lease assignment / load balancing algorithm
|
192
|
+
* KCL 3.x introduces a new lease assignment and load balancing algorithm. It assigns leases among workers based on worker utilization metrics and throughput on each lease, replacing the previous lease count-based lease assignment algorithm.
|
193
|
+
* When KCL detects higher variance in CPU utilization among workers, it proactively reassigns leases from over-utilized workers to under-utilized workers for even load balancing. This ensures even CPU utilization across workers and removes the need to over-provision the stream processing compute hosts.
|
194
|
+
* Optimized DynamoDB RCU usage
|
195
|
+
* KCL 3.x optimizes DynamoDB read capacity unit (RCU) usage on the lease table by implementing a global secondary index with leaseOwner as the partition key. This index mirrors the leaseKey attribute from the base lease table, allowing workers to efficiently discover their assigned leases by querying the index instead of scanning the entire table.
|
196
|
+
* This approach significantly reduces read operations compared to earlier KCL versions, where workers performed full table scans, resulting in higher RCU consumption.
|
197
|
+
* Graceful lease handoff
|
198
|
+
* KCL 3.x introduces a feature called "graceful lease handoff" to minimize data reprocessing during lease reassignments. Graceful lease handoff allows the current worker to complete checkpointing of processed records before transferring the lease to another worker. For graceful lease handoff, you should implement checkpointing logic within the existing `shutdownRequested()` method.
|
199
|
+
* This feature is enabled by default in KCL 3.x, but you can turn off this feature by adjusting the configuration property `isGracefulLeaseHandoffEnabled`.
|
200
|
+
* While this approach significantly reduces the probability of data reprocessing during lease transfers, it doesn't completely eliminate the possibility. To maintain data integrity and consistency, it's crucial to design your downstream consumer applications to be idempotent. This ensures that the application can handle potential duplicate record processing without adverse effects.
|
201
|
+
* New DynamoDB metadata management artifacts
|
202
|
+
* KCL 3.x introduces two new DynamoDB tables for improved lease management:
|
203
|
+
* Worker metrics table: Records CPU utilization metrics from each worker. KCL uses these metrics for optimal lease assignments, balancing resource utilization across workers. If CPU utilization metric is not available, KCL assigns leases to balance the total sum of shard throughput per worker instead.
|
204
|
+
* Coordinator state table: Stores internal state information for workers. Used to coordinate in-place migration from KCL 2.x to KCL 3.x and leader election among workers.
|
205
|
+
* Follow this [documentation](https://docs.aws.amazon.com/streams/latest/dev/kcl-migration-from-2-3.html#kcl-migration-from-2-3-IAM-permissions) to add required IAM permissions for your KCL application.
|
206
|
+
* Other improvements and changes
|
207
|
+
* Dependency on the AWS SDK for Java 1.x has been fully removed.
|
208
|
+
* The Glue Schema Registry integration functionality no longer depends on AWS SDK for Java 1.x. Previously, it required this as a transient dependency.
|
209
|
+
* Multilangdaemon has been upgraded to use AWS SDK for Java 2.x. It no longer depends on AWS SDK for Java 1.x.
|
210
|
+
* `idleTimeBetweenReadsInMillis` (PollingConfig) now has a minimum default value of 200.
|
211
|
+
* This polling configuration property determines the [publishers](https://github.com/awslabs/amazon-kinesis-client/blob/master/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisher.java) wait time between GetRecords calls in both success and failure cases. Previously, setting this value below 200 caused unnecessary throttling. This is because Amazon Kinesis Data Streams supports up to five read transactions per second per shard for shared-throughput consumers.
|
212
|
+
* Shard lifecycle management is improved to deal with edge cases around shard splits and merges to ensure records continue being processed as expected.
|
213
|
+
* Migration
|
214
|
+
* The programming interfaces of KCL 3.x remain identical with KCL 2.x for an easier migration. For detailed migration instructions, please refer to the [Migrate consumers from KCL 2.x to KCL 3.x](https://docs.aws.amazon.com/streams/latest/dev/kcl-migration-from-2-3.html) page in the Amazon Kinesis Data Streams developer guide.
|
215
|
+
* Configuration properties
|
216
|
+
* New configuration properties introduced in KCL 3.x are listed in this [doc](https://github.com/awslabs/amazon-kinesis-client/blob/master/docs/kcl-configurations.md#new-configurations-in-kcl-3x).
|
217
|
+
* Deprecated configuration properties in KCL 3.x are listed in this [doc](https://github.com/awslabs/amazon-kinesis-client/blob/master/docs/kcl-configurations.md#discontinued-configuration-properties-in-kcl-3x). You need to keep the deprecated configuration properties during the migration from any previous KCL version to KCL 3.x.
|
218
|
+
* Metrics
|
219
|
+
* New CloudWatch metrics introduced in KCL 3.x are explained in the [Monitor the Kinesis Client Library with Amazon CloudWatch](https://docs.aws.amazon.com/streams/latest/dev/monitoring-with-kcl.html) in the Amazon Kinesis Data Streams developer guide. The following operations are newly added in KCL 3.x:
|
220
|
+
* `LeaseAssignmentManager`
|
221
|
+
* `WorkerMetricStatsReporter`
|
222
|
+
* `LeaseDiscovery`
|
223
|
+
|
190
224
|
### Release 2.1.1 (February 21, 2023)
|
191
225
|
* [#69](https://github.com/awslabs/amazon-kinesis-client-ruby/pull/69) Include `pom.xml` in the gemspec
|
192
226
|
|
@@ -232,8 +266,8 @@ all languages.
|
|
232
266
|
[amazon-kcl]: http://docs.aws.amazon.com/kinesis/latest/dev/kinesis-record-processor-app.html
|
233
267
|
[amazon-kcl-github]: https://github.com/awslabs/amazon-kinesis-client
|
234
268
|
[amazon-kinesis-python-github]: https://github.com/awslabs/amazon-kinesis-client-python
|
235
|
-
[multi-lang-daemon]: https://github.com/awslabs/amazon-kinesis-client/blob/master/src/main/java/
|
236
|
-
[
|
269
|
+
[multi-lang-daemon]: https://github.com/awslabs/amazon-kinesis-client/blob/master/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/package-info.java
|
270
|
+
[DefaultCredentialsProvider]: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html
|
237
271
|
[kinesis-forum]: http://developer.amazonwebservices.com/connect/forum.jspa?forumID=169
|
238
272
|
[aws-ruby-sdk-gem]: https://rubygems.org/gems/aws-sdk
|
239
273
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
@@ -52,8 +52,8 @@ module Aws
|
|
52
52
|
# @param action [Hash] A hash that represents an action to take with
|
53
53
|
# appropriate attributes, as retrieved from {IOProxy#read_action}, e.g.
|
54
54
|
#
|
55
|
-
# - `{"action":"initialize","shardId":"shardId-123"}`
|
56
|
-
# - `{"action":"processRecords","records":[{"data":"bWVvdw==","partitionKey":"cat","sequenceNumber":"456"}]}`
|
55
|
+
# - `{"action":"initialize","shardId":"shardId-123","sequenceNumber":123}`
|
56
|
+
# - `{"action":"processRecords","records":[{"data":"bWVvdw==","partitionKey":"cat","sequenceNumber":"456"}],"millisBehindLatest":"0"}`
|
57
57
|
# - `{"action":"shutdown","reason":"TERMINATE"}`
|
58
58
|
# @raise [MalformedAction] if the action is missing expected attributes.
|
59
59
|
def process_action(action)
|
data/pom.xml
CHANGED
@@ -2,23 +2,23 @@
|
|
2
2
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
3
3
|
<modelVersion>4.0.0</modelVersion>
|
4
4
|
<properties>
|
5
|
-
<awssdk.version>2.
|
6
|
-
<
|
7
|
-
<netty.version>4.1.
|
5
|
+
<awssdk.version>2.25.64</awssdk.version>
|
6
|
+
<kcl.version>3.0.0</kcl.version>
|
7
|
+
<netty.version>4.1.108.Final</netty.version>
|
8
8
|
<netty-reactive.version>2.0.6</netty-reactive.version>
|
9
|
-
<fasterxml-jackson.version>2.13.
|
10
|
-
<logback.version>1.3.
|
9
|
+
<fasterxml-jackson.version>2.13.5</fasterxml-jackson.version>
|
10
|
+
<logback.version>1.3.14</logback.version>
|
11
11
|
</properties>
|
12
12
|
<dependencies>
|
13
13
|
<dependency>
|
14
14
|
<groupId>software.amazon.kinesis</groupId>
|
15
15
|
<artifactId>amazon-kinesis-client-multilang</artifactId>
|
16
|
-
<version
|
16
|
+
<version>${kcl.version}</version>
|
17
17
|
</dependency>
|
18
18
|
<dependency>
|
19
19
|
<groupId>software.amazon.kinesis</groupId>
|
20
20
|
<artifactId>amazon-kinesis-client</artifactId>
|
21
|
-
<version
|
21
|
+
<version>${kcl.version}</version>
|
22
22
|
</dependency>
|
23
23
|
<dependency>
|
24
24
|
<groupId>software.amazon.awssdk</groupId>
|
@@ -30,6 +30,18 @@
|
|
30
30
|
<artifactId>dynamodb</artifactId>
|
31
31
|
<version>${awssdk.version}</version>
|
32
32
|
</dependency>
|
33
|
+
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/dynamodb-enhanced -->
|
34
|
+
<dependency>
|
35
|
+
<groupId>software.amazon.awssdk</groupId>
|
36
|
+
<artifactId>dynamodb-enhanced</artifactId>
|
37
|
+
<version>${awssdk.version}</version>
|
38
|
+
</dependency>
|
39
|
+
<!-- https://mvnrepository.com/artifact/com.amazonaws/dynamodb-lock-client -->
|
40
|
+
<dependency>
|
41
|
+
<groupId>com.amazonaws</groupId>
|
42
|
+
<artifactId>dynamodb-lock-client</artifactId>
|
43
|
+
<version>1.3.0</version>
|
44
|
+
</dependency>
|
33
45
|
<dependency>
|
34
46
|
<groupId>software.amazon.awssdk</groupId>
|
35
47
|
<artifactId>cloudwatch</artifactId>
|
@@ -135,6 +147,41 @@
|
|
135
147
|
<artifactId>apache-client</artifactId>
|
136
148
|
<version>${awssdk.version}</version>
|
137
149
|
</dependency>
|
150
|
+
<dependency>
|
151
|
+
<groupId>software.amazon.awssdk</groupId>
|
152
|
+
<artifactId>arns</artifactId>
|
153
|
+
<version>${awssdk.version}</version>
|
154
|
+
</dependency>
|
155
|
+
<dependency>
|
156
|
+
<groupId>software.amazon.awssdk</groupId>
|
157
|
+
<artifactId>http-auth-spi</artifactId>
|
158
|
+
<version>${awssdk.version}</version>
|
159
|
+
</dependency>
|
160
|
+
<dependency>
|
161
|
+
<groupId>software.amazon.awssdk</groupId>
|
162
|
+
<artifactId>http-auth</artifactId>
|
163
|
+
<version>${awssdk.version}</version>
|
164
|
+
</dependency>
|
165
|
+
<dependency>
|
166
|
+
<groupId>software.amazon.awssdk</groupId>
|
167
|
+
<artifactId>http-auth-aws</artifactId>
|
168
|
+
<version>${awssdk.version}</version>
|
169
|
+
</dependency>
|
170
|
+
<dependency>
|
171
|
+
<groupId>software.amazon.awssdk</groupId>
|
172
|
+
<artifactId>checksums-spi</artifactId>
|
173
|
+
<version>${awssdk.version}</version>
|
174
|
+
</dependency>
|
175
|
+
<dependency>
|
176
|
+
<groupId>software.amazon.awssdk</groupId>
|
177
|
+
<artifactId>checksums</artifactId>
|
178
|
+
<version>${awssdk.version}</version>
|
179
|
+
</dependency>
|
180
|
+
<dependency>
|
181
|
+
<groupId>software.amazon.awssdk</groupId>
|
182
|
+
<artifactId>identity-spi</artifactId>
|
183
|
+
<version>${awssdk.version}</version>
|
184
|
+
</dependency>
|
138
185
|
<dependency>
|
139
186
|
<groupId>io.netty</groupId>
|
140
187
|
<artifactId>netty-codec-http</artifactId>
|
@@ -203,7 +250,7 @@
|
|
203
250
|
<dependency>
|
204
251
|
<groupId>com.google.guava</groupId>
|
205
252
|
<artifactId>guava</artifactId>
|
206
|
-
<version>
|
253
|
+
<version>32.1.1-jre</version>
|
207
254
|
</dependency>
|
208
255
|
<dependency>
|
209
256
|
<groupId>com.google.code.findbugs</groupId>
|
@@ -233,22 +280,22 @@
|
|
233
280
|
<dependency>
|
234
281
|
<groupId>com.google.protobuf</groupId>
|
235
282
|
<artifactId>protobuf-java</artifactId>
|
236
|
-
<version>
|
283
|
+
<version>4.27.5</version>
|
237
284
|
</dependency>
|
238
285
|
<dependency>
|
239
286
|
<groupId>org.apache.commons</groupId>
|
240
287
|
<artifactId>commons-lang3</artifactId>
|
241
|
-
<version>3.
|
288
|
+
<version>3.14.0</version>
|
242
289
|
</dependency>
|
243
290
|
<dependency>
|
244
291
|
<groupId>org.slf4j</groupId>
|
245
292
|
<artifactId>slf4j-api</artifactId>
|
246
|
-
<version>2.0.
|
293
|
+
<version>2.0.13</version>
|
247
294
|
</dependency>
|
248
295
|
<dependency>
|
249
296
|
<groupId>io.reactivex.rxjava3</groupId>
|
250
297
|
<artifactId>rxjava</artifactId>
|
251
|
-
<version>3.1.
|
298
|
+
<version>3.1.8</version>
|
252
299
|
</dependency>
|
253
300
|
<dependency>
|
254
301
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
@@ -291,19 +338,20 @@
|
|
291
338
|
<version>4.4.15</version>
|
292
339
|
</dependency>
|
293
340
|
<dependency>
|
294
|
-
<groupId>com.
|
295
|
-
<artifactId>aws-java-sdk-core</artifactId>
|
296
|
-
<version>${aws-java-sdk.version}</version>
|
297
|
-
</dependency>
|
298
|
-
<dependency>
|
299
|
-
<groupId>software.amazon.ion</groupId>
|
341
|
+
<groupId>com.amazon.ion</groupId>
|
300
342
|
<artifactId>ion-java</artifactId>
|
301
|
-
<version>1.
|
343
|
+
<version>1.11.4</version>
|
302
344
|
</dependency>
|
303
345
|
<dependency>
|
304
346
|
<groupId>software.amazon.glue</groupId>
|
305
347
|
<artifactId>schema-registry-serde</artifactId>
|
306
|
-
<version>1.1.
|
348
|
+
<version>1.1.19</version>
|
349
|
+
<exclusions>
|
350
|
+
<exclusion>
|
351
|
+
<groupId>com.amazonaws</groupId>
|
352
|
+
<artifactId>aws-java-sdk-sts</artifactId>
|
353
|
+
</exclusion>
|
354
|
+
</exclusions>
|
307
355
|
</dependency>
|
308
356
|
<dependency>
|
309
357
|
<groupId>joda-time</groupId>
|
@@ -328,7 +376,7 @@
|
|
328
376
|
<dependency>
|
329
377
|
<groupId>commons-io</groupId>
|
330
378
|
<artifactId>commons-io</artifactId>
|
331
|
-
<version>2.
|
379
|
+
<version>2.16.1</version>
|
332
380
|
</dependency>
|
333
381
|
<dependency>
|
334
382
|
<groupId>commons-logging</groupId>
|
@@ -338,7 +386,7 @@
|
|
338
386
|
<dependency>
|
339
387
|
<groupId>org.apache.commons</groupId>
|
340
388
|
<artifactId>commons-collections4</artifactId>
|
341
|
-
<version>4.
|
389
|
+
<version>4.4</version>
|
342
390
|
</dependency>
|
343
391
|
<dependency>
|
344
392
|
<groupId>commons-beanutils</groupId>
|
@@ -351,4 +399,4 @@
|
|
351
399
|
<version>3.2.2</version>
|
352
400
|
</dependency>
|
353
401
|
</dependencies>
|
354
|
-
</project>
|
402
|
+
</project>
|
data/spec/kcl_process_spec.rb
CHANGED
@@ -27,66 +27,124 @@ module Aws::KCLrb
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
checkpointer.checkpoint
|
30
|
+
def shutdown_requested(checkpointer)
|
31
|
+
checkpointer.checkpoint
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
class TestRecordProcessorV2 < Aws::KCLrb::V2::RecordProcessorBase
|
36
|
+
|
37
|
+
def init_processor(shard_id)
|
38
|
+
# no-op
|
39
|
+
end
|
40
|
+
|
41
|
+
def shutdown_requested(shutdown_requested_input)
|
42
|
+
shutdown_requested_input.checkpointer.checkpoint
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_records(process_records_input)
|
46
|
+
last_seq = nil
|
47
|
+
records = process_records_input.records
|
48
|
+
records.each do |record|
|
49
|
+
last_seq = record['sequenceNumber']
|
50
|
+
end
|
51
|
+
|
52
|
+
if last_seq
|
53
|
+
checkpointer = process_records_input.checkpointer
|
54
|
+
begin
|
55
|
+
checkpointer.checkpoint(last_seq)
|
56
|
+
rescue CheckpointError => cpe
|
57
|
+
if cpe.value == 'ThrottlingException'
|
58
|
+
checkpointer.checkpoint(last_seq)
|
59
|
+
else
|
60
|
+
raise
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
35
68
|
describe KCLProcess do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
69
|
+
|
70
|
+
input_specs = [
|
71
|
+
{:method => :init_processor, :action => 'initialize', :input => '{"action":"initialize","shardId":"shard-000001","sequenceNumber":123456789}'},
|
72
|
+
{:method => :process_records, :action => 'processRecords', :input => '{"action":"processRecords","records":[],"millisBehindLatest":0}'},
|
73
|
+
{:method => :shutdown, :action => 'shutdownRequested', :input => '{"action":"shutdownRequested","reason":"TERMINATE"}'}
|
74
|
+
]
|
75
|
+
versions = [1, 2]
|
76
|
+
|
77
|
+
describe "#action_response" do
|
78
|
+
|
79
|
+
before(:each) do
|
80
|
+
@processor = double(RecordProcessorBase)
|
81
|
+
end
|
82
|
+
|
83
|
+
input_specs.each do |input_spec|
|
84
|
+
versions.each do |version|
|
85
|
+
it "V#{version} should respond to #{input_spec[:method]} action by invoking the corresponding processor's method and write a status message to the output IO" do
|
86
|
+
allow(@processor).to receive(:version).and_return(version)
|
87
|
+
action_response_common_test(input_spec[:method], input_spec[:action], input_spec[:input], version)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def action_response_common_test(method, action, input, version)
|
93
|
+
if method == :shutdown
|
94
|
+
expected_shutdown_input = version == 1 ? Aws::KCLrb::CheckpointerImpl : Aws::KCLrb::V2::ShutdownRequestedInput
|
95
|
+
allow(@processor).to receive(:shutdown_requested).with(expected_shutdown_input).and_return(nil)
|
96
|
+
else
|
97
|
+
expect(@processor).to receive(method).once
|
98
|
+
end
|
99
|
+
input = StringIO.new(input)
|
48
100
|
output = StringIO.new
|
49
101
|
error = StringIO.new
|
50
|
-
driver = KCLProcess.new(processor, input, output, error)
|
102
|
+
driver = KCLProcess.new(@processor, input, output, error)
|
51
103
|
driver.run
|
52
104
|
|
53
|
-
expected_output = %Q[{"action":"status","responseFor":"#{
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
105
|
+
expected_output = %Q[{"action":"status","responseFor":"#{action}"}]
|
106
|
+
expect(output.string.gsub(/\s+/, "")).to eq(expected_output.gsub(/\s+/, ""))
|
107
|
+
expect(error.string).to eq("")
|
108
|
+
expect(input.eof?).to eq(true)
|
57
109
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#run" do
|
114
|
+
versions.each do |version|
|
115
|
+
it "V#{version} should process a normal stream of actions and produce expected output" do
|
116
|
+
input_string = <<-INPUT
|
117
|
+
{"action":"initialize","shardId":"shardId-123","sequenceNumber":123}
|
118
|
+
{"action":"processRecords","records":[{"data":"bWVvdw==","partitionKey":"cat","sequenceNumber":"456"}],"millisBehindLatest":"0"}
|
62
119
|
{"action":"checkpoint","sequenceNumber":"456","error":"ThrottlingException"}
|
63
120
|
{"action":"checkpoint","sequenceNumber":"456"}
|
64
|
-
{"action":"
|
121
|
+
{"action":"shutdownRequested","reason":"TERMINATE"}
|
65
122
|
{"action":"checkpoint","sequenceNumber":"456"}
|
66
|
-
|
123
|
+
INPUT
|
67
124
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
125
|
+
# NOTE: The first checkpoint is expected to fail
|
126
|
+
# with a ThrottlingException and hence the
|
127
|
+
# retry.
|
128
|
+
expected_output_string = <<-OUTPUT
|
72
129
|
{"action":"status","responseFor":"initialize"}
|
73
130
|
{"action":"checkpoint","sequenceNumber":"456"}
|
74
131
|
{"action":"checkpoint","sequenceNumber":"456"}
|
75
132
|
{"action":"status","responseFor":"processRecords"}
|
76
133
|
{"action":"checkpoint","sequenceNumber":null}
|
77
|
-
{"action":"status","responseFor":"
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
134
|
+
{"action":"status","responseFor":"shutdownRequested"}
|
135
|
+
OUTPUT
|
136
|
+
processor = version == 1 ? TestRecordProcessor.new : TestRecordProcessorV2.new
|
137
|
+
input = StringIO.new(input_string)
|
138
|
+
output = StringIO.new
|
139
|
+
error = StringIO.new
|
140
|
+
driver = KCLProcess.new(processor, input, output, error)
|
141
|
+
driver.run
|
85
142
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
143
|
+
# outputs should be same modulo some whitespaces
|
144
|
+
expect( output.string.gsub(/\s+/, "") ).to eq(expected_output_string.gsub(/\s+/, ""))
|
145
|
+
expect( error.string ).to eq("")
|
146
|
+
expect( input.eof? ).to eq(true)
|
147
|
+
end
|
90
148
|
end
|
91
149
|
end
|
92
150
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-kclrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -24,8 +24,36 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: A ruby interface for the Amazon Kinesis Client Library MultiLangDaemon
|
28
|
-
email:
|
56
|
+
email:
|
29
57
|
executables: []
|
30
58
|
extensions: []
|
31
59
|
extra_rdoc_files: []
|
@@ -51,7 +79,7 @@ homepage: http://github.com/aws/amazon-kinesis-client-ruby
|
|
51
79
|
licenses:
|
52
80
|
- Apache-2.0
|
53
81
|
metadata: {}
|
54
|
-
post_install_message:
|
82
|
+
post_install_message:
|
55
83
|
rdoc_options: []
|
56
84
|
require_paths:
|
57
85
|
- lib
|
@@ -66,8 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
94
|
- !ruby/object:Gem::Version
|
67
95
|
version: '0'
|
68
96
|
requirements: []
|
69
|
-
rubygems_version: 3.3.
|
70
|
-
signing_key:
|
97
|
+
rubygems_version: 3.0.3.1
|
98
|
+
signing_key:
|
71
99
|
specification_version: 4
|
72
100
|
summary: Amazon Kinesis Client Library for Ruby
|
73
101
|
test_files: []
|