use of software.amazon.awssdk.http.async.SimpleSubscriber in project aws-sdk by reactiverse.
the class AsyncHttpClientTest method testPut.
@Test
@Timeout(value = 15, timeUnit = TimeUnit.SECONDS)
public void testPut(VertxTestContext ctx) {
final byte[] payload = "the-body".getBytes();
server.requestHandler(req -> {
req.bodyHandler(buff -> {
req.response().end(buff);
});
});
server.listen(PORT, HOST, res -> {
assertTrue(res.succeeded());
SdkHttpFullRequest request = SdkHttpFullRequest.builder().protocol(SCHEME).host(HOST).port(PORT).method(SdkHttpMethod.PUT).putHeader("Content-Length", String.valueOf(payload.length)).contentStreamProvider(() -> new ByteArrayInputStream(payload)).build();
client.execute(AsyncExecuteRequest.builder().request(request).requestContentPublisher(new SimpleHttpContentPublisher(request)).responseHandler(new SdkAsyncHttpResponseHandler() {
@Override
public void onHeaders(SdkHttpResponse headers) {
assertEquals(200, headers.statusCode());
}
@Override
public void onStream(Publisher<ByteBuffer> stream) {
stream.subscribe(new SimpleSubscriber(body -> {
assertEquals("the-body", Unpooled.wrappedBuffer(body).toString(StandardCharsets.UTF_8));
ctx.completeNow();
}));
}
@Override
public void onError(Throwable error) {
throw new RuntimeException(error);
}
}).build());
});
}
use of software.amazon.awssdk.http.async.SimpleSubscriber in project aws-sdk-java-v2 by aws.
the class AsyncRequestBodyTest method hasCorrectContent.
@Test
public void hasCorrectContent() throws InterruptedException {
StringBuilder sb = new StringBuilder();
CountDownLatch done = new CountDownLatch(1);
Subscriber<ByteBuffer> subscriber = new SimpleSubscriber(buffer -> {
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
sb.append(new String(bytes, StandardCharsets.UTF_8));
}) {
@Override
public void onError(Throwable t) {
super.onError(t);
done.countDown();
}
@Override
public void onComplete() {
super.onComplete();
done.countDown();
}
};
provider.subscribe(subscriber);
done.await();
assertThat(sb.toString()).isEqualTo(testString);
}
use of software.amazon.awssdk.http.async.SimpleSubscriber in project aws-sdk-java-v2 by aws.
the class ChecksumCalculatingAsyncRequestBodyTest method hasCorrectContent.
@Test
public void hasCorrectContent() throws InterruptedException {
StringBuilder sb = new StringBuilder();
CountDownLatch done = new CountDownLatch(1);
Subscriber<ByteBuffer> subscriber = new SimpleSubscriber(buffer -> {
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
sb.append(new String(bytes, StandardCharsets.UTF_8));
}) {
@Override
public void onError(Throwable t) {
super.onError(t);
done.countDown();
}
@Override
public void onComplete() {
super.onComplete();
done.countDown();
}
};
provider.subscribe(subscriber);
done.await(10, TimeUnit.SECONDS);
assertThat(sb).hasToString(expectedTestString);
}
use of software.amazon.awssdk.http.async.SimpleSubscriber in project aws-sdk by reactiverse.
the class AsyncHttpClientTest method testGet.
@Test
@Timeout(value = 15, timeUnit = TimeUnit.SECONDS)
public void testGet(VertxTestContext ctx) {
server.requestHandler(req -> {
req.response().end("foo");
});
server.listen(PORT, HOST, res -> {
assertTrue(res.succeeded());
client.execute(AsyncExecuteRequest.builder().request(SdkHttpRequest.builder().protocol(SCHEME).host(HOST).port(PORT).method(SdkHttpMethod.GET).build()).responseHandler(new SdkAsyncHttpResponseHandler() {
@Override
public void onHeaders(SdkHttpResponse headers) {
assertEquals(200, headers.statusCode());
}
@Override
public void onStream(Publisher<ByteBuffer> stream) {
stream.subscribe(new SimpleSubscriber(body -> {
assertEquals("foo", Unpooled.wrappedBuffer(body).toString(StandardCharsets.UTF_8));
ctx.completeNow();
}));
}
@Override
public void onError(Throwable error) {
throw new RuntimeException(error);
}
}).build());
});
}
use of software.amazon.awssdk.http.async.SimpleSubscriber in project aws-sdk-java-v2 by aws.
the class GetObjectAsyncIntegrationTest method customResponseHandler_InterceptorRecievesResponsePojo.
@Test
public void customResponseHandler_InterceptorRecievesResponsePojo() throws Exception {
final CompletableFuture<String> cf = new CompletableFuture<>();
try (S3AsyncClient asyncWithInterceptor = createClientWithInterceptor(new AssertingExecutionInterceptor())) {
String result = asyncWithInterceptor.getObject(getObjectRequest, new AsyncResponseTransformer<GetObjectResponse, String>() {
@Override
public CompletableFuture<String> prepare() {
return cf;
}
@Override
public void onResponse(GetObjectResponse response) {
// POJO returned by modifyResponse should be delivered to the AsyncResponseTransformer
assertThat(response.metadata()).hasEntrySatisfying("x-amz-assert", s -> assertThat(s).isEqualTo("injected-value"));
}
@Override
public void onStream(SdkPublisher<ByteBuffer> publisher) {
publisher.subscribe(new SimpleSubscriber(b -> {
}) {
@Override
public void onComplete() {
super.onComplete();
cf.complete("result");
}
});
}
@Override
public void exceptionOccurred(Throwable throwable) {
cf.completeExceptionally(throwable);
}
}).join();
assertThat(result).isEqualTo("result");
}
}
Aggregations