Fix GCS Mock Broken Handling of some Blobs (#50666) (#50671)

* Fix GCS Mock Broken Handling of some Blobs

We were incorrectly handling blobs starting in `\r\n` which broke
tests randomly when blobs started on these.

Relates #49429
This commit is contained in:
Armin Braun 2020-01-06 19:27:57 +01:00 committed by GitHub
parent f576aefd0f
commit 72a405fafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -271,6 +271,7 @@ public class GoogleCloudStorageHttpHandler implements HttpHandler {
return buf;
}
};
boolean skippedEmptyLine = false;
while ((read = in.read()) != -1) {
out.reset();
boolean markAndContinue = false;
@ -290,7 +291,7 @@ public class GoogleCloudStorageHttpHandler implements HttpHandler {
} while ((read = in.read()) != -1);
final String bucketPrefix = "{\"bucket\":";
final String start = new String(out.toByteArray(), 0, Math.min(out.size(), bucketPrefix.length()), UTF_8);
if (start.length() == 0 || start.equals("\r\n") || start.startsWith("--")
if ((skippedEmptyLine == false && start.length() == 0) || start.startsWith("--")
|| start.toLowerCase(Locale.ROOT).startsWith("content")) {
markAndContinue = true;
} else if (start.startsWith(bucketPrefix)) {
@ -302,6 +303,7 @@ public class GoogleCloudStorageHttpHandler implements HttpHandler {
}
}
if (markAndContinue) {
skippedEmptyLine = start.length() == 0;
in.mark(Integer.MAX_VALUE);
continue;
}

View File

@ -132,7 +132,11 @@ public abstract class ESBlobStoreRepositoryIntegTestCase extends ESIntegTestCase
byte[] buffer = new byte[scaledRandomIntBetween(1, data.length - target.length())];
int offset = scaledRandomIntBetween(0, buffer.length - 1);
int read = stream.read(buffer, offset, buffer.length - offset);
target.append(new BytesRef(buffer, offset, read));
if (read >= 0) {
target.append(new BytesRef(buffer, offset, read));
} else {
fail("Expected [" + (data.length - target.length()) + "] more bytes to be readable but reached EOF");
}
}
assertEquals(data.length, target.length());
assertArrayEquals(data, Arrays.copyOfRange(target.bytes(), 0, target.length()));