Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(kinesis): accept same-value Increase/DecreaseStreamRetentionPeriod (#352)

TiM98a6bd563991
diff --git a/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java b/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java
index 00688b1423..0833efe224 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kinesis/KinesisService.java
@@ -147,12 +147,19 @@ public class KinesisService {
throw new AwsException("InvalidArgumentException",
"Retention period must not exceed 8760 hours (365 days)", 400);
}
- if (retentionPeriodHours <= stream.getRetentionPeriodHours()) {
+ if (retentionPeriodHours < stream.getRetentionPeriodHours()) {
throw new AwsException("InvalidArgumentException",
"Requested retention period (" + retentionPeriodHours +
- " hours) must be greater than current retention period (" +
+ " hours) must not be less than current retention period (" +
stream.getRetentionPeriodHours() + " hours)", 400);
}
+ // Same value is a no-op on real AWS despite the API doc wording ("must be more than
+ // current"). Proof: terraform-provider-aws calls IncreaseStreamRetentionPeriod on
+ // stream creation unconditionally when retention_period is set (stream.go Create path),
+ // so every default-retention TF stream would fail if AWS rejected same-value. See #342.
+ if (retentionPeriodHours == stream.getRetentionPeriodHours()) {
+ return;
+ }
stream.setRetentionPeriodHours(retentionPeriodHours);
store.put(regionKey(region, streamName), stream);
LOG.infov("Increased retention period for stream {0} to {1} hours", streamName, retentionPeriodHours);
@@ -164,12 +171,16 @@ public class KinesisService {
throw new AwsException("InvalidArgumentException",
"Retention period must not be less than 24 hours", 400);
}
- if (retentionPeriodHours >= stream.getRetentionPeriodHours()) {
+ if (retentionPeriodHours > stream.getRetentionPeriodHours()) {
throw new AwsException("InvalidArgumentException",
"Requested retention period (" + retentionPeriodHours +
- " hours) must be less than current retention period (" +
+ " hours) must not be greater than current retention period (" +
stream.getRetentionPeriodHours() + " hours)", 400);
}
+ // Same value is a no-op on real AWS (mirrors IncreaseStreamRetentionPeriod). See #342.
+ if (retentionPeriodHours == stream.getRetentionPeriodHours()) {
+ return;
+ }
stream.setRetentionPeriodHours(retentionPeriodHours);
store.put(regionKey(region, streamName), stream);
LOG.infov("Decreased retention period for stream {0} to {1} hours", streamName, retentionPeriodHours);
diff --git a/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisIntegrationTest.java
index f5d3d27536..6fe39eb8ac 100644
--- a/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/kinesis/KinesisIntegrationTest.java
@@ -396,6 +396,66 @@ class KinesisIntegrationTest {
@Test
@Order(12)
+ void increaseRetentionPeriodSameValueIsNoOp() {
+ // Stream is currently at 48 (from Order 11). Increase to 48 should be a no-op,
+ // not an InvalidArgumentException. See #342: real AWS accepts same-value
+ // (terraform-provider-aws stream.go Create path calls this unconditionally on
+ // stream creation with the configured retention_period, so every default-retention
+ // TF stream would fail on first apply if AWS rejected same-value).
+ given()
+ .header("X-Amz-Target", "Kinesis_20131202.IncreaseStreamRetentionPeriod")
+ .contentType(KINESIS_CONTENT_TYPE)
+ .body("""
+ {"StreamName": "retention-test", "RetentionPeriodHours": 48}
+ """)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .header("X-Amz-Target", "Kinesis_20131202.DescribeStream")
+ .contentType(KINESIS_CONTENT_TYPE)
+ .body("""
+ {"StreamName": "retention-test"}
+ """)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("StreamDescription.RetentionPeriodHours", equalTo(48));
+ }
+
+ @Test
+ @Order(13)
+ void decreaseRetentionPeriodSameValueIsNoOp() {
+ // Stream is still at 48. Decrease to 48 should also be a no-op.
+ given()
+ .header("X-Amz-Target", "Kinesis_20131202.DecreaseStreamRetentionPeriod")
+ .contentType(KINESIS_CONTENT_TYPE)
+ .body("""
+ {"StreamName": "retention-test", "RetentionPeriodHours": 48}
+ """)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .header("X-Amz-Target", "Kinesis_20131202.DescribeStream")
+ .contentType(KINESIS_CONTENT_TYPE)
+ .body("""
+ {"StreamName": "retention-test"}
+ """)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("StreamDescription.RetentionPeriodHours", equalTo(48));
+ }
+
+ @Test
+ @Order(14)
void listShardsForNonExistentStream() {
given()
.header("X-Amz-Target", "Kinesis_20131202.ListShards")