Skip to content

Add configurable s3Key as an optional parameter #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ public interface PayloadStore {
* Stores payload in a store that has higher payload size limit than that is supported by original payload store.
*
* @param payload
* @param optional an array of optional parameters. optional[0] should be a custom s3Key.
* @return a pointer that must be used to retrieve the original payload later.
* @throws SdkClientException 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 S3Exception 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);
String storeOriginalPayload(String payload, String... optional);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a new method that takes a custom s3Key parameter.


/**
* Retrieves the original payload using the given payloadPointer. The pointer must
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public S3BackedPayloadStore(S3Dao s3Dao, String s3BucketName) {
}

@Override
public String storeOriginalPayload(String payload) {
String s3Key = UUID.randomUUID().toString();
public String storeOriginalPayload(String payload, String... optional) {
String s3Key = optional.length > 0 ? optional[0] : UUID.randomUUID().toString();

s3Dao.storeTextInS3(s3BucketName, s3Key, payload);
LOG.info("S3 object created, Bucket name: " + s3BucketName + ", Object key: " + s3Key + ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public void testStoreOriginalPayloadOnSuccess() {
assertEquals(expectedPayloadPointer.toJson(), actualPayloadPointer);
}

@Test
public void testStoreOriginalPayloadWithS3KeyOnSuccess() {
String actualPayloadPointer = payloadStore.storeOriginalPayload(ANY_PAYLOAD, ANY_S3_KEY);

verify(s3Dao, times(1)).storeTextInS3(eq(S3_BUCKET_NAME), eq(ANY_S3_KEY),
eq(ANY_PAYLOAD));

PayloadS3Pointer expectedPayloadPointer = new PayloadS3Pointer(S3_BUCKET_NAME, ANY_S3_KEY);
assertEquals(expectedPayloadPointer.toJson(), actualPayloadPointer);
}

@Test
public void testStoreOriginalPayloadDoesAlwaysCreateNewObjects() {
//Store any payload
Expand Down