2727import java .nio .file .Path ;
2828import java .time .Duration ;
2929import java .util .Optional ;
30- import java .util .concurrent .atomic .AtomicLong ;
3130import org .apache .commons .lang3 .RandomStringUtils ;
3231import org .apache .logging .log4j .Level ;
3332import org .assertj .core .api .Assertions ;
@@ -152,11 +151,8 @@ void pauseAndResume_ObjectNotChanged_shouldResumeDownload(S3TransferManager tm)
152151 assertEqualsBySdkFields (resumableFileDownload .downloadFileRequest (), request );
153152 assertThat (testDownloadListener .getObjectResponse ).isNotNull ();
154153
155- // wait to give CRT client time to write last bytes to file if any
156- long actualInProgressFileSize = waitUntilFileSizeStable (path );
157-
158154 // Skip the test if everything has been downloaded.
159- Assumptions .assumeTrue (actualInProgressFileSize < sourceFile .length ());
155+ Assumptions .assumeTrue (resumableFileDownload . bytesTransferred () < sourceFile .length ());
160156
161157 assertThat (resumableFileDownload .s3ObjectLastModified ()).hasValue (testDownloadListener .getObjectResponse .lastModified ());
162158 // Request may not be cancelled right away when pause is invoked, so there may be more bytes written to the file
@@ -166,7 +162,7 @@ void pauseAndResume_ObjectNotChanged_shouldResumeDownload(S3TransferManager tm)
166162 assertThat (download .completionFuture ()).isCancelled ();
167163
168164 log .debug (() -> "Resuming download " );
169- verifyFileDownload (path , resumableFileDownload , OBJ_SIZE - actualInProgressFileSize , tm );
165+ verifyFileDownload (path , resumableFileDownload , OBJ_SIZE - bytesTransferred , tm );
170166 }
171167
172168 private void assertEqualsBySdkFields (DownloadFileRequest actual , DownloadFileRequest expected ) {
@@ -256,25 +252,6 @@ private static void waitUntilFirstByteBufferDelivered(FileDownload download) {
256252 waiter .run (() -> download .progress ().snapshot ());
257253 }
258254
259- /**
260- * CRT File downloads can continue to flush bytes to the file after pause. Wait until the file size is stable.
261- *
262- * @param file
263- * @return the final file size
264- */
265- private static long waitUntilFileSizeStable (Path file ) {
266- final AtomicLong fileSize = new AtomicLong (0L );
267- Waiter <Path > waiter = Waiter .builder (Path .class )
268- .addAcceptor (WaiterAcceptor .successOnResponseAcceptor (p -> file .toFile ().length () == fileSize .getAndSet (file .toFile ().length ())))
269- .addAcceptor (WaiterAcceptor .retryOnResponseAcceptor (r -> true ))
270- .overrideConfiguration (o -> o .waitTimeout (Duration .ofMinutes (1 ))
271- .maxAttempts (Integer .MAX_VALUE )
272- .backoffStrategy (FixedDelayBackoffStrategy .create (Duration .ofMillis (500 ))))
273- .build ();
274- waiter .run (() -> file );
275- return file .toFile ().length ();
276- }
277-
278255 private static final class TestDownloadListener implements TransferListener {
279256 private int transferInitiatedCount = 0 ;
280257 private GetObjectResponse getObjectResponse ;
0 commit comments