@@ -142,42 +142,47 @@ public void testReadFromPositionLargerThanBlobLength() {
142142 public void testResumeAfterUpdate () {
143143 createRepository (PROXIED_TEST_REPO , PROXIED_CLIENT );
144144
145- // The blob needs to be large enough that it won't be entirely buffered on the first request
146- final int enoughBytesToNotBeEntirelyBuffered = Math .toIntExact (ByteSizeValue .ofMb (10 ).getBytes ());
147-
148- final BlobStoreRepository repo = getRepository (PROXIED_TEST_REPO );
149- final String blobKey = randomIdentifier ();
150- final byte [] initialValue = randomByteArrayOfLength (enoughBytesToNotBeEntirelyBuffered );
151- executeOnBlobStore (repo , container -> {
152- container .writeBlob (randomPurpose (), blobKey , new BytesArray (initialValue ), true );
153-
154- try (InputStream inputStream = container .readBlob (randomPurpose (), blobKey )) {
155- // Trigger the first request for the blob, partially read it
156- int read = inputStream .read ();
157- assert read != -1 ;
158-
159- // Restart the server (this triggers a retry)
160- proxyServer .restart ();
161-
162- // Update the file
163- byte [] updatedValue = randomByteArrayOfLength (enoughBytesToNotBeEntirelyBuffered );
164- container .writeBlob (randomPurpose (), blobKey , new BytesArray (updatedValue ), false );
165-
166- // Read the rest of the stream, it should throw because the contents changed
167- String message = assertThrows (NoSuchFileException .class , () -> readFully (inputStream )).getMessage ();
168- assertThat (
169- message ,
170- startsWith (
171- "Blob object ["
172- + container .path ().buildAsString ()
173- + blobKey
174- + "] generation [1] unavailable on resume (contents changed, or object deleted):"
175- )
176- );
177- } catch (Exception e ) {
178- fail (e );
179- }
180- return null ;
181- });
145+ try {
146+ // The blob needs to be large enough that it won't be entirely buffered on the first request
147+ final int enoughBytesToNotBeEntirelyBuffered = Math .toIntExact (ByteSizeValue .ofMb (10 ).getBytes ());
148+
149+ final BlobStoreRepository repo = getRepository (PROXIED_TEST_REPO );
150+ final String blobKey = randomIdentifier ();
151+ final byte [] initialValue = randomByteArrayOfLength (enoughBytesToNotBeEntirelyBuffered );
152+ executeOnBlobStore (repo , container -> {
153+ container .writeBlob (randomPurpose (), blobKey , new BytesArray (initialValue ), true );
154+
155+ try (InputStream inputStream = container .readBlob (randomPurpose (), blobKey )) {
156+ // Trigger the first request for the blob, partially read it
157+ int read = inputStream .read ();
158+ assert read != -1 ;
159+
160+ // Restart the server (this triggers a retry)
161+ proxyServer .restart ();
162+
163+ // Update the file
164+ byte [] updatedValue = randomByteArrayOfLength (enoughBytesToNotBeEntirelyBuffered );
165+ container .writeBlob (randomPurpose (), blobKey , new BytesArray (updatedValue ), false );
166+
167+ // Read the rest of the stream, it should throw because the contents changed
168+ String message = assertThrows (NoSuchFileException .class , () -> readFully (inputStream )).getMessage ();
169+ assertThat (
170+ message ,
171+ startsWith (
172+ "Blob object ["
173+ + container .path ().buildAsString ()
174+ + blobKey
175+ + "] generation [1] unavailable on resume (contents changed, or object deleted):"
176+ )
177+ );
178+ } catch (Exception e ) {
179+ fail (e );
180+ }
181+ return null ;
182+ });
183+ } finally {
184+ final BlobStoreRepository repository = getRepository (PROXIED_TEST_REPO );
185+ deleteAndAssertEmpty (repository , repository .basePath ());
186+ }
182187 }
183188}
0 commit comments