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(issues1072): fix MultiPartWriterTest unstable test #1165

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
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 @@ -19,6 +19,8 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -48,13 +50,15 @@ class MultiPartWriterTest {
private S3AsyncClient s3;
private DefaultS3Operator operator;
private MultiPartWriter writer;
private Lock lock;

@BeforeEach
void setUp() {
s3 = mock(S3AsyncClient.class);
operator = new DefaultS3Operator(s3, "unit-test-bucket");
CreateMultipartUploadResponse.Builder builder = CreateMultipartUploadResponse.builder();
when(s3.createMultipartUpload(any(CreateMultipartUploadRequest.class))).thenReturn(CompletableFuture.completedFuture(builder.build()));
lock = new ReentrantLock();
}

@Test
Expand Down Expand Up @@ -132,9 +136,14 @@ void testCopyWrite() throws NoSuchMethodException, InvocationTargetException, Il

when(s3.uploadPart(any(UploadPartRequest.class), any(AsyncRequestBody.class))).thenAnswer(invocation -> {
UploadPartRequest request = invocation.getArgument(0);
uploadPartRequests.add(request);
AsyncRequestBody body = invocation.getArgument(1);
writeContentLengths.add(body.contentLength().orElse(0L));
lock.lock();
try {
uploadPartRequests.add(request);
AsyncRequestBody body = invocation.getArgument(1);
writeContentLengths.add(body.contentLength().orElse(0L));
} finally {
lock.unlock();
}
return CompletableFuture.completedFuture(builder.build());
});

Expand Down
Loading