@@ -56,8 +56,8 @@ public class S3TransferManagerDownloadPauseResumeIntegrationTest extends S3Integ
5656 private static final Logger log = Logger .loggerFor (S3TransferManagerDownloadPauseResumeIntegrationTest .class );
5757 private static final String BUCKET = temporaryBucketName (S3TransferManagerDownloadPauseResumeIntegrationTest .class );
5858 private static final String KEY = "key" ;
59- // 24 * MB is chosen to make sure we have data written in the file already upon pausing.
60- private static final long OBJ_SIZE = 24 * MB ;
59+ // 50 * MB is chosen to make sure we have data written in the file already upon pausing.
60+ private static final long OBJ_SIZE = 50 * MB ;
6161 private static File sourceFile ;
6262
6363 @ BeforeAll
@@ -131,36 +131,33 @@ void pauseAndResume_ObjectEtagChange_shouldRestartDownload(S3TransferManager tm)
131131 }
132132 }
133133
134- //TODO: This test currently flakey. Fix this test to ensure that pause happens after bytes written but never before complete.
135- // depending on the timing of waitUntilFirstByteBufferDelivered, the entire file may have been downloaded
136- //
137- // @ParameterizedTest
138- // @MethodSource("transferManagers")
139- // void pauseAndResume_ObjectNotChanged_shouldResumeDownload(S3TransferManager tm) {
140- // Path path = RandomTempFile.randomUncreatedFile().toPath();
141- // TestDownloadListener testDownloadListener = new TestDownloadListener();
142- // DownloadFileRequest request = DownloadFileRequest.builder()
143- // .getObjectRequest(b -> b.bucket(BUCKET).key(KEY))
144- // .destination(path)
145- // .addTransferListener(testDownloadListener)
146- // .build();
147- // FileDownload download = tm.downloadFile(request);
148- // waitUntilFirstByteBufferDelivered(download);
149- //
150- // ResumableFileDownload resumableFileDownload = download.pause();
151- // long bytesTransferred = resumableFileDownload.bytesTransferred();
152- // log.debug(() -> "Paused: " + resumableFileDownload);
153- // assertEqualsBySdkFields(resumableFileDownload.downloadFileRequest(), request);
154- // assertThat(testDownloadListener.getObjectResponse).isNotNull();
155- // assertThat(resumableFileDownload.s3ObjectLastModified()).hasValue(testDownloadListener.getObjectResponse.lastModified());
156- // assertThat(bytesTransferred).isEqualTo(path.toFile().length());
157- // assertThat(resumableFileDownload.totalSizeInBytes()).hasValue(sourceFile.length());
158- // assertThat(bytesTransferred).isLessThan(sourceFile.length());
159- // assertThat(download.completionFuture()).isCancelled();
160- //
161- // log.debug(() -> "Resuming download ");
162- // verifyFileDownload(path, resumableFileDownload, OBJ_SIZE - bytesTransferred, tm);
163- // }
134+ @ ParameterizedTest
135+ @ MethodSource ("transferManagers" )
136+ void pauseAndResume_ObjectNotChanged_shouldResumeDownload (S3TransferManager tm ) {
137+ Path path = RandomTempFile .randomUncreatedFile ().toPath ();
138+ TestDownloadListener testDownloadListener = new TestDownloadListener ();
139+ DownloadFileRequest request = DownloadFileRequest .builder ()
140+ .getObjectRequest (b -> b .bucket (BUCKET ).key (KEY ))
141+ .destination (path )
142+ .addTransferListener (testDownloadListener )
143+ .build ();
144+ FileDownload download = tm .downloadFile (request );
145+ waitUntilFirstByteBufferDelivered (download );
146+
147+ ResumableFileDownload resumableFileDownload = download .pause ();
148+ long bytesTransferred = resumableFileDownload .bytesTransferred ();
149+ log .debug (() -> "Paused: " + resumableFileDownload );
150+ assertEqualsBySdkFields (resumableFileDownload .downloadFileRequest (), request );
151+ assertThat (testDownloadListener .getObjectResponse ).isNotNull ();
152+ assertThat (resumableFileDownload .s3ObjectLastModified ()).hasValue (testDownloadListener .getObjectResponse .lastModified ());
153+ assertThat (bytesTransferred ).isEqualTo (path .toFile ().length ());
154+ assertThat (resumableFileDownload .totalSizeInBytes ()).hasValue (sourceFile .length ());
155+ assertThat (bytesTransferred ).isLessThan (sourceFile .length ());
156+ assertThat (download .completionFuture ()).isCancelled ();
157+
158+ log .debug (() -> "Resuming download " );
159+ verifyFileDownload (path , resumableFileDownload , OBJ_SIZE - bytesTransferred , tm );
160+ }
164161
165162 private void assertEqualsBySdkFields (DownloadFileRequest actual , DownloadFileRequest expected ) {
166163 // Transfer manager adds an execution attribute to the GetObjectRequest, so both objects are different.
@@ -244,7 +241,7 @@ private static void waitUntilFirstByteBufferDelivered(FileDownload download) {
244241 .addAcceptor (WaiterAcceptor .retryOnResponseAcceptor (r -> true ))
245242 .overrideConfiguration (o -> o .waitTimeout (Duration .ofMinutes (1 ))
246243 .maxAttempts (Integer .MAX_VALUE )
247- .backoffStrategy (FixedDelayBackoffStrategy .create (Duration .ofMillis (100 ))))
244+ .backoffStrategy (FixedDelayBackoffStrategy .create (Duration .ofMillis (10 ))))
248245 .build ();
249246 waiter .run (() -> download .progress ().snapshot ());
250247 }
0 commit comments