Skip to content
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

Fix flaky test in RetryableS3OutputStreamTest #16639

Merged
Merged
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 @@ -171,6 +171,27 @@
s3.assertCompleted(chunkSize, 600);
}

@Test
public void testWriteSmallBufferExactChunkSizeShouldSucceed() throws IOException
{
chunkSize = 128;
final int numChunks = 5;
final long fileSize = chunkSize * numChunks;
try (RetryableS3OutputStream out = new RetryableS3OutputStream(
config,
s3,
path,
s3UploadManager
)) {
Akshat-Jain marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < fileSize; i++) {
out.write(i);
}
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
}
// each chunk 128 bytes, so there should be 5 chunks.
Assert.assertEquals(numChunks, s3.partRequests.size());
s3.assertCompleted(chunkSize, fileSize);
}

@Test
public void testSuccessToUploadAfterRetry() throws IOException
{
Expand Down Expand Up @@ -284,13 +305,22 @@
Set<Integer> partNumbersFromRequest = partRequests.stream().map(UploadPartRequest::getPartNumber).collect(Collectors.toSet());
Assert.assertEquals(partRequests.size(), partNumbersFromRequest.size());

for (int i = 0; i < partRequests.size(); i++) {
if (i < partRequests.size() - 1) {
Assert.assertEquals(chunkSize, partRequests.get(i).getPartSize());
} else {
Assert.assertTrue(chunkSize >= partRequests.get(i).getPartSize());
}
int numChunksOfChunkSize = 0;
long fileSize = expectedFileSize;
while (fileSize - chunkSize >= 0) {
fileSize -= chunkSize;
numChunksOfChunkSize++;
}

int numChunksOfSmallerSize = fileSize == 0 ? 0 : 1;

// Validate part sizes
long numOfExactChunks = partRequests.stream().filter(part -> part.getPartSize() == chunkSize).count();
long numOfSmallerChunks = partRequests.stream().filter(part -> part.getPartSize() < chunkSize).count();

Assert.assertEquals(numChunksOfChunkSize, numOfExactChunks);
Assert.assertEquals(numChunksOfSmallerSize, numOfSmallerChunks);

final List<PartETag> eTags = completeRequest.getPartETags();
Assert.assertEquals(partRequests.size(), eTags.size());
Assert.assertEquals(
Expand Down
Loading