use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class FileAsyncRequestBodyTest method changingFile_fileGetsDeleted_failsBecauseDeleted.
@Test
public void changingFile_fileGetsDeleted_failsBecauseDeleted() 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));
// Delete the file
Files.delete(testFile);
// 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_fileGetsLongerThanExistingLength_failsBecauseTooLong.
@Test
public void changingFile_fileGetsLongerThanExistingLength_failsBecauseTooLong() 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 longer than when we started
int currentSize = Math.toIntExact(Files.size(testFile));
byte[] slightlyLongerFileContent = new byte[currentSize + 1];
ThreadLocalRandom.current().nextBytes(slightlyLongerFileContent);
Files.write(testFile, slightlyLongerFileContent);
// 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_fileGetsTouched_failsBecauseUpdatedModificationTime.
@Test
public void changingFile_fileGetsTouched_failsBecauseUpdatedModificationTime() 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 updated
// Wait for 1 second so that we are definitely in a different second than when the file was created
Thread.sleep(1_000);
Files.setLastModifiedTime(testFile, FileTime.from(Instant.now()));
// 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 ContentLengthMismatchTest method contentShorterThanContentLengthHeaderFails.
@Test
public void contentShorterThanContentLengthHeaderFails() {
String bucket = "Example-Bucket";
String key = "Example-Object";
S3AsyncClient s3Client = getAsyncClientBuilder().build();
AsyncRequestBody requestBody = new AsyncRequestBody() {
@Override
public Optional<Long> contentLength() {
return Optional.empty();
}
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
AsyncRequestBody.fromString("A").subscribe(subscriber);
}
};
assertThatThrownBy(() -> s3Client.putObject(r -> r.bucket(bucket).key(key).contentLength(2L), requestBody).get(10, TimeUnit.SECONDS)).isInstanceOf(ExecutionException.class).hasMessageContaining("content-length");
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class AsyncChecksumValidationInterceptorTest method modifyAsyncHttpContent_putObjectRequest_checksumDisabled_shouldNotModify.
@Test
public void modifyAsyncHttpContent_putObjectRequest_checksumDisabled_shouldNotModify() {
ExecutionAttributes executionAttributes = getExecutionAttributesWithChecksumDisabled();
Context.ModifyHttpRequest modifyHttpRequest = InterceptorTestUtils.modifyHttpRequestContext(GetObjectRequest.builder().build());
Optional<AsyncRequestBody> asyncRequestBody = interceptor.modifyAsyncHttpContent(modifyHttpRequest, executionAttributes);
assertThat(asyncRequestBody).isEqualTo(modifyHttpRequest.asyncRequestBody());
}
Aggregations