use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class ChecksumCalculatingAsyncRequestBodyTest method bytesArrayConstructorHasCorrectContentType.
@Test
public void bytesArrayConstructorHasCorrectContentType() {
AsyncRequestBody requestBody = ChecksumCalculatingAsyncRequestBody.builder().asyncRequestBody(AsyncRequestBody.fromBytes("hello world".getBytes())).algorithm(Algorithm.CRC32).trailerHeader("x-amz-checksum-crc32").build();
assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class ChecksumCalculatingAsyncRequestBodyTest method fromBytes_byteArrayNotNullChecksumSupplied.
@Test
public void fromBytes_byteArrayNotNullChecksumSupplied() {
byte[] original = { 1, 2, 3, 4 };
// Checksum data in byte format.
byte[] expected = { 52, 13, 10, 1, 2, 3, 4, 13, 10, 48, 13, 10, 120, 45, 97, 109, 122, 110, 45, 99, 104, 101, 99, 107, 115, 117, 109, 45, 99, 114, 99, 51, 50, 58, 116, 106, 122, 55, 122, 81, 61, 61, 13, 10, 13, 10 };
byte[] toModify = new byte[original.length];
System.arraycopy(original, 0, toModify, 0, original.length);
AsyncRequestBody body = ChecksumCalculatingAsyncRequestBody.builder().asyncRequestBody(AsyncRequestBody.fromBytes(toModify)).algorithm(Algorithm.CRC32).trailerHeader("x-amzn-checksum-crc32").build();
for (int i = 0; i < toModify.length; ++i) {
toModify[i]++;
}
ByteBuffer publishedBb = Flowable.fromPublisher(body).toList().blockingGet().get(0);
assertThat(BinaryUtils.copyAllBytesFrom(publishedBb)).isEqualTo(expected);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class ChecksumCalculatingAsyncRequestBodyTest method emptyBytesConstructorHasCorrectContentType.
@Test
public void emptyBytesConstructorHasCorrectContentType() {
AsyncRequestBody requestBody = ChecksumCalculatingAsyncRequestBody.builder().asyncRequestBody(AsyncRequestBody.empty()).algorithm(Algorithm.CRC32).trailerHeader("x-amz-checksum-crc32").build();
assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class FileAsyncRequestBodyTest method changingFile_fileGetsShorterThanExistingLength_failsBecauseTooShort.
@Test
public void changingFile_fileGetsShorterThanExistingLength_failsBecauseTooShort() throws Exception {
AsyncRequestBody asyncRequestBody = FileAsyncRequestBody.builder().path(testFile).build();
ControllableSubscriber subscriber = new ControllableSubscriber();
// Start reading file
asyncRequestBody.subscribe(subscriber);
subscriber.sub.request(1);
assertTrue(subscriber.onNextSemaphore.tryAcquire(5, TimeUnit.SECONDS));
// Change the file to be 1 byte shorter than when we started
int currentSize = Math.toIntExact(Files.size(testFile));
byte[] slightlyShorterFileContent = new byte[currentSize - 1];
ThreadLocalRandom.current().nextBytes(slightlyShorterFileContent);
Files.write(testFile, slightlyShorterFileContent);
// Finishing reading the file
subscriber.sub.request(Long.MAX_VALUE);
assertThatThrownBy(() -> subscriber.completed.get(5, TimeUnit.SECONDS)).hasCauseInstanceOf(IOException.class);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class FileAsyncRequestBodyTest method changingFile_fileGetsShorterThanAlreadyRead_failsBecauseTooShort.
@Test
public void changingFile_fileGetsShorterThanAlreadyRead_failsBecauseTooShort() throws Exception {
AsyncRequestBody asyncRequestBody = FileAsyncRequestBody.builder().path(testFile).build();
ControllableSubscriber subscriber = new ControllableSubscriber();
// Start reading file
asyncRequestBody.subscribe(subscriber);
subscriber.sub.request(1);
assertTrue(subscriber.onNextSemaphore.tryAcquire(5, TimeUnit.SECONDS));
// Change the file to be shorter than the amount read so far
Files.write(testFile, "Hello".getBytes(StandardCharsets.UTF_8));
// Finishing reading the file
subscriber.sub.request(Long.MAX_VALUE);
assertThatThrownBy(() -> subscriber.completed.get(5, TimeUnit.SECONDS)).hasCauseInstanceOf(IOException.class);
}
Aggregations