From 523caffb878c3329978b22dc0c8c10b58476a939 Mon Sep 17 00:00:00 2001 From: rbugatha Date: Wed, 24 Feb 2021 14:58:00 -0800 Subject: [PATCH] Add configurable s3Key as an optional parameter. (#14) * configure s3key by using additinal parameter for storeOriginalPayload function (by overloading the params) Co-authored-by: Ramesh Bugatha --- .../amazon/payloadoffloading/PayloadStore.java | 15 +++++++++++++++ .../payloadoffloading/S3BackedPayloadStore.java | 7 ++++++- .../S3BackedPayloadStoreTest.java | 11 +++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/software/amazon/payloadoffloading/PayloadStore.java b/src/main/java/software/amazon/payloadoffloading/PayloadStore.java index a47d526..14be6ce 100644 --- a/src/main/java/software/amazon/payloadoffloading/PayloadStore.java +++ b/src/main/java/software/amazon/payloadoffloading/PayloadStore.java @@ -21,6 +21,21 @@ public interface PayloadStore { */ String storeOriginalPayload(String payload, Long payloadContentSize); + /** + * Stores payload in a store that has higher payload size limit than that is supported by original payload store. + * + * @param payload + * @param payloadContentSize + * @param key custom s3Key. + * @return a pointer that must be used to retrieve the original payload later. + * @throws AmazonClientException If any internal errors are encountered on the client side while + * attempting to make the request or handle the response. For example + * if a network connection is not available. + * @throws AmazonServiceException If an error response is returned by actual PayloadStore indicating + * either a problem with the data in the request, or a server side issue. + */ + String storeOriginalPayload(String payload, Long payloadContentSize, String key); + /** * Retrieves the original payload using the given payloadPointer. The pointer must * have been obtained using {@link storeOriginalPayload} diff --git a/src/main/java/software/amazon/payloadoffloading/S3BackedPayloadStore.java b/src/main/java/software/amazon/payloadoffloading/S3BackedPayloadStore.java index 401b68b..5016dde 100644 --- a/src/main/java/software/amazon/payloadoffloading/S3BackedPayloadStore.java +++ b/src/main/java/software/amazon/payloadoffloading/S3BackedPayloadStore.java @@ -21,7 +21,12 @@ public S3BackedPayloadStore(S3Dao s3Dao, String s3BucketName) { @Override public String storeOriginalPayload(String payload, Long payloadContentSize) { - String s3Key = UUID.randomUUID().toString(); + return storeOriginalPayload(payload, payloadContentSize, null); + } + + @Override + public String storeOriginalPayload(String payload, Long payloadContentSize, String key) { + String s3Key = (key!=null) ? key : UUID.randomUUID().toString(); // Store the payload content in S3. s3Dao.storeTextInS3(s3BucketName, s3Key, payload, payloadContentSize); diff --git a/src/test/java/software/amazon/payloadoffloading/S3BackedPayloadStoreTest.java b/src/test/java/software/amazon/payloadoffloading/S3BackedPayloadStoreTest.java index b97c96d..1b0e282 100644 --- a/src/test/java/software/amazon/payloadoffloading/S3BackedPayloadStoreTest.java +++ b/src/test/java/software/amazon/payloadoffloading/S3BackedPayloadStoreTest.java @@ -50,6 +50,17 @@ public void testStoreOriginalPayloadOnSuccess() { assertEquals(expectedPayloadPointer.toJson(), actualPayloadPointer); } + @Test + public void testStoreOriginalPayloadWithS3KeyOnSuccess() { + String actualPayloadPointer = payloadStore.storeOriginalPayload(ANY_PAYLOAD, ANY_PAYLOAD_LENGTH, ANY_S3_KEY); + + verify(s3Dao, times(1)).storeTextInS3(eq(S3_BUCKET_NAME), eq(ANY_S3_KEY), + eq(ANY_PAYLOAD), eq(ANY_PAYLOAD_LENGTH)); + + PayloadS3Pointer expectedPayloadPointer = new PayloadS3Pointer(S3_BUCKET_NAME, ANY_S3_KEY); + assertEquals(expectedPayloadPointer.toJson(), actualPayloadPointer); + } + @Test public void testStoreOriginalPayloadDoesAlwaysCreateNewObjects() { //Store any payload