public void testUploadBigFile() throws Exception {
MockWebServer server = mockWebServer(new MD5CheckDispatcher());
IntegrationTestClient client = client(server.getUrl("/").toString());
File f = null;
Payload payload = null;
try {
f = File.createTempFile("jclouds", "tmp");
f.deleteOnExit();
long length = (new Random().nextInt(32) + 1) * 1024 * 1024;
MessageDigest digester = md5Digest();
CharSink fileSink = Files.asCharSink(f, Charsets.UTF_8);
Writer out = null;
try {
out = fileSink.openStream();
for (long i = 0; i < length; i++) {
out.append('a');
digester.update((byte) 'a');
}
out.flush();
} finally {
close(out, true);
}
payload = newByteSourcePayload(asByteSource(f));
byte[] digest = digester.digest();
String strDigest = base64().encode(digest);
payload.getContentMetadata().setContentMD5(digest);
payload.getContentMetadata().setContentLength(f.length());
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
RecordedRequest request = server.takeRequest();
assertEquals(request.getHeader("Content-MD5"), strDigest);
assertEquals(headers.get("x-Content-MD5"), ImmutableList.of(strDigest));
} finally {
if (payload != null) {
payload.release();
}
if (f != null && f.exists()) {
f.delete();
}
close(client, true);