mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): return a null Message for non-failed item cancellation reason (#1623)
* fix(dynamodb): return a null Message for non-failed item cancellation reason * fix(ec2): fix flaky launchInstanceUserDataStreamToCloudWatch test * fix: address PR review feedback for TransactWriteItems and revert unrelated imports
This commit is contained in:
1 parent
0ac1a01884
commit
6dfdd892aa
5 files changed
+161
-14
No files matched your search
+76
@@ -2459,6 +2459,82 @@ given()
|
||||
"Second page should return the remaining 1 item");
|
||||
|
||||
// Cleanup
|
||||
deleteTable(tableName);
|
||||
}
|
||||
|
||||
// Reproduces #1604
|
||||
@Test
|
||||
void transactWriteCancellationReasonMessageIsNullForNonFailedItems() {
|
||||
String tableName = "TxCancelMsgTest";
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.PutItem")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"Item": {"pk": {"S": "A"}}
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// item 0 passes (A exists), item 1 fails (B absent)
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.TransactWriteItems")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TransactItems": [
|
||||
{
|
||||
"ConditionCheck": {
|
||||
"TableName": "%s",
|
||||
"Key": {"pk": {"S": "A"}},
|
||||
"ConditionExpression": "attribute_exists(pk)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ConditionCheck": {
|
||||
"TableName": "%s",
|
||||
"Key": {"pk": {"S": "B"}},
|
||||
"ConditionExpression": "attribute_exists(pk)"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(tableName, tableName))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("TransactionCanceledException"))
|
||||
.body("CancellationReasons[0].Code", equalTo("None"))
|
||||
.body("CancellationReasons[0].Message", nullValue())
|
||||
.body("CancellationReasons[1].Code", equalTo("ConditionalCheckFailed"));
|
||||
|
||||
// Cleanup
|
||||
deleteTable(tableName);
|
||||
}
|
||||
|
||||
private void deleteTable(String tableName) {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
|
||||
+45
-6
@@ -1,18 +1,17 @@
|
||||
package io.github.hectorvent.floci.services.dynamodb;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.AttributeDefinition;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.KeySchemaElement;
|
||||
import io.github.hectorvent.floci.services.dynamodb.model.TableDefinition;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -294,4 +293,44 @@ class DynamoDbJsonHandlerTest {
|
||||
assertNotNull(responseData);
|
||||
assertFalse(responseData.has("Attributes"), "Attributes property must not be present");
|
||||
}
|
||||
|
||||
// Reproduces #1604
|
||||
@Test
|
||||
void transactWriteItemsCancellationReasonMessageIsNullForNonFailedItems() throws Exception {
|
||||
createUsersTable("us-east-1");
|
||||
service.putItem("Users", item("userId", "A"), "us-east-1");
|
||||
|
||||
ObjectNode condCheckA = mapper.createObjectNode();
|
||||
condCheckA.put("TableName", "Users");
|
||||
condCheckA.set("Key", item("userId", "A"));
|
||||
condCheckA.put("ConditionExpression", "attribute_exists(userId)");
|
||||
|
||||
ObjectNode condCheckB = mapper.createObjectNode();
|
||||
condCheckB.put("TableName", "Users");
|
||||
condCheckB.set("Key", item("userId", "B"));
|
||||
condCheckB.put("ConditionExpression", "attribute_exists(userId)");
|
||||
|
||||
ObjectNode txItemA = mapper.createObjectNode();
|
||||
txItemA.set("ConditionCheck", condCheckA);
|
||||
ObjectNode txItemB = mapper.createObjectNode();
|
||||
txItemB.set("ConditionCheck", condCheckB);
|
||||
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
ArrayNode txItems = request.putArray("TransactItems");
|
||||
txItems.add(txItemA);
|
||||
txItems.add(txItemB);
|
||||
|
||||
Response response = handler.handle("TransactWriteItems", request, "us-east-1");
|
||||
|
||||
assertEquals(400, response.getStatus());
|
||||
|
||||
JsonNode body = mapper.convertValue(response.getEntity(), JsonNode.class);
|
||||
assertEquals("TransactionCanceledException", body.get("__type").asText());
|
||||
|
||||
ArrayNode reasons = (ArrayNode) body.get("CancellationReasons");
|
||||
assertEquals(2, reasons.size());
|
||||
|
||||
assertEquals("None", reasons.get(0).get("Code").asText());
|
||||
assertNull(reasons.get(0).get("Message"), "non failed item must not have a Message field");
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Answers.RETURNS_SELF;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
Reference in new issue
Block a user