mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(emr): honor ListClusters creation time filters (#6123)
* fix(emr): honor ListClusters creation time filters * fix(emr): preserve ListClusters timestamp precision * fix(emr): share millisecond timestamp parsing
This commit is contained in:
1 parent
89317831bb
commit
7c0d592b85
9 files changed
+171
-20
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class AwsJsonTimestampTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void epochSecondsRoundsNumericValuesToMilliseconds() throws Exception {
|
||||
JsonNode positive = mapper.readTree("{\"time\":1761000000.1256}");
|
||||
JsonNode negative = mapper.readTree("{\"time\":-0.0016}");
|
||||
|
||||
assertEquals(Instant.ofEpochMilli(1_761_000_000_126L),
|
||||
AwsJsonTimestamp.epochSeconds(positive, "time", "InvalidRequestException"));
|
||||
assertEquals(Instant.ofEpochMilli(-2),
|
||||
AwsJsonTimestamp.epochSeconds(negative, "time", "ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingAndNullMembersRemainAbsent() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
assertNull(AwsJsonTimestamp.epochSeconds(request, "time", "ValidationException"));
|
||||
|
||||
request.putNull("time");
|
||||
assertNull(AwsJsonTimestamp.epochSeconds(request, "time", "ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidValuesUseTheRequestedAwsErrorCode() throws Exception {
|
||||
JsonNode wrongType = mapper.readTree("{\"time\":\"invalid\"}");
|
||||
JsonNode outOfRange = mapper.readTree("{\"time\":123456789012345678901234567890}");
|
||||
|
||||
AwsException emrError = assertThrows(AwsException.class,
|
||||
() -> AwsJsonTimestamp.epochSeconds(wrongType, "time", "InvalidRequestException"));
|
||||
assertEquals("InvalidRequestException", emrError.getErrorCode());
|
||||
assertEquals(400, emrError.getHttpStatus());
|
||||
|
||||
AwsException redshiftError = assertThrows(AwsException.class,
|
||||
() -> AwsJsonTimestamp.epochSeconds(outOfRange, "time", "ValidationException"));
|
||||
assertEquals("ValidationException", redshiftError.getErrorCode());
|
||||
assertEquals(400, redshiftError.getHttpStatus());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.emr;
|
||||
|
||||
import io.github.hectorvent.floci.services.emr.model.EmrCluster;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
@@ -10,6 +11,9 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.EmrRequests.emr;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -17,6 +21,7 @@ import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
@@ -79,10 +84,66 @@ class EmrIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listClustersFilteredByState() {
|
||||
void listClustersFilteredByStateAndCreationTime() {
|
||||
emr("ListClusters", "{\"ClusterStates\":[\"WAITING\"]}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }.Name", equalTo("floci-emr"));
|
||||
|
||||
emr("ListClusters", "{\"CreatedAfter\":4102444800}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }", nullValue());
|
||||
emr("ListClusters", "{\"CreatedBefore\":946684800}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }", nullValue());
|
||||
emr("ListClusters", "{\"ClusterStates\":[\"WAITING\"],\"CreatedAfter\":946684800,"
|
||||
+ "\"CreatedBefore\":4102444800}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }.Name", equalTo("floci-emr"));
|
||||
|
||||
Instant createdAt = emrService.describeCluster(clusterId).getCreationDateTime();
|
||||
BigDecimal epochSeconds = BigDecimal.valueOf(createdAt.getEpochSecond())
|
||||
.add(BigDecimal.valueOf(createdAt.getNano(), 9));
|
||||
String shortlyBefore = epochSeconds.subtract(new BigDecimal("0.1")).toPlainString();
|
||||
String shortlyAfter = epochSeconds.add(new BigDecimal("0.1")).toPlainString();
|
||||
emr("ListClusters", "{\"CreatedAfter\":" + shortlyAfter + "}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }", nullValue());
|
||||
emr("ListClusters", "{\"CreatedBefore\":" + shortlyBefore + "}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }", nullValue());
|
||||
emr("ListClusters", "{\"CreatedAfter\":" + shortlyBefore + ",\"CreatedBefore\":" + shortlyAfter + "}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }.Name", equalTo("floci-emr"));
|
||||
emr("ListClusters", "{\"ClusterStates\":[\"TERMINATED\"],\"CreatedAfter\":" + shortlyBefore + "}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }", nullValue());
|
||||
|
||||
EmrCluster cluster = emrService.describeCluster(clusterId);
|
||||
Instant originalCreationTime = cluster.getCreationDateTime();
|
||||
cluster.setCreationDateTime(Instant.ofEpochMilli(1_761_000_000_000L));
|
||||
try {
|
||||
emr("ListClusters", "{\"CreatedBefore\":1761000000.001}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }.Name", equalTo("floci-emr"));
|
||||
emr("ListClusters", "{\"CreatedAfter\":1760999999.999}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }.Name", equalTo("floci-emr"));
|
||||
emr("ListClusters", "{\"CreatedBefore\":1761000000.000000001}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }", nullValue());
|
||||
emr("ListClusters", "{\"CreatedAfter\":1760999999.999999999}")
|
||||
.then().statusCode(200)
|
||||
.body("Clusters.find { it.Id == '" + clusterId + "' }", nullValue());
|
||||
} finally {
|
||||
cluster.setCreationDateTime(originalCreationTime);
|
||||
}
|
||||
|
||||
emr("ListClusters", "{\"CreatedAfter\":\"invalid\"}")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
emr("ListClusters", "{\"CreatedBefore\":123456789012345678901234567890}")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+9
@@ -312,6 +312,15 @@ class RedshiftServerlessIntegrationTest {
|
||||
call("ListSnapshots", "{\"startTime\":4102444800}")
|
||||
.statusCode(200)
|
||||
.body("snapshots", hasSize(0));
|
||||
call("ListSnapshots", "{\"startTime\":4102444800.125}")
|
||||
.statusCode(200)
|
||||
.body("snapshots", hasSize(0));
|
||||
call("ListSnapshots", "{\"startTime\":\"invalid\"}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
call("ListSnapshots", "{\"startTime\":123456789012345678901234567890}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
call("RestoreFromSnapshot", "{\"namespaceName\":\"snap-life-ns\",\"workgroupName\":\"snap-life-wg\","
|
||||
+ "\"snapshotName\":\"snap-life\",\"snapshotArn\":\"" + snapshotArn + "\"}")
|
||||
.statusCode(400)
|
||||
|
||||
Reference in new issue
Block a user