use of io.reactiverse.awssdk.converters.VertxAsyncResponseTransformer in project aws-sdk by reactiverse.
the class VertxS3ClientSpec method downloadImageFromBucketToPump.
@Test
@Order(6)
void downloadImageFromBucketToPump(Vertx vertx, VertxTestContext ctx) throws Exception {
final Context originalContext = vertx.getOrCreateContext();
final S3AsyncClient s3 = s3(originalContext);
Buffer received = Buffer.buffer();
AtomicBoolean handlerCalled = new AtomicBoolean(false);
VertxAsyncResponseTransformer<GetObjectResponse> transformer = new VertxAsyncResponseTransformer<>(new WriteStream<Buffer>() {
@Override
public WriteStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
return null;
}
@Override
public Future<Void> write(Buffer data) {
received.appendBuffer(data);
return Future.succeededFuture();
}
@Override
public void write(Buffer data, Handler<AsyncResult<Void>> handler) {
received.appendBuffer(data);
handler.handle(null);
}
@Override
public void end(Handler<AsyncResult<Void>> handler) {
assertTrue(handlerCalled.get(), "Response handler should have been called before first bytes are received");
if (received.length() == fileSize)
ctx.completeNow();
handler.handle(null);
}
@Override
public WriteStream<Buffer> setWriteQueueMaxSize(int maxSize) {
return null;
}
@Override
public boolean writeQueueFull() {
return false;
}
@Override
public WriteStream<Buffer> drainHandler(@Nullable Handler<Void> handler) {
return null;
}
});
transformer.setResponseHandler(resp -> {
handlerCalled.set(true);
});
single(s3.getObject(VertxS3ClientSpec::downloadImgReq, transformer)).subscribe(getRes -> {
}, ctx::failNow);
}
use of io.reactiverse.awssdk.converters.VertxAsyncResponseTransformer in project aws-sdk by reactiverse.
the class VertxS3ClientSpec method downloadImageFromBucketWithoutSettingResponseHandler.
@Test
@Order(7)
void downloadImageFromBucketWithoutSettingResponseHandler(Vertx vertx, VertxTestContext ctx) throws Exception {
final Context originalContext = vertx.getOrCreateContext();
final S3AsyncClient s3 = s3(originalContext);
final Buffer received = Buffer.buffer();
AtomicBoolean handlerCalled = new AtomicBoolean(false);
VertxAsyncResponseTransformer<GetObjectResponse> transformer = new VertxAsyncResponseTransformer<>(new WriteStream<Buffer>() {
@Override
public WriteStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
return null;
}
@Override
public Future<Void> write(Buffer data) {
received.appendBuffer(data);
return Future.succeededFuture();
}
@Override
public void write(Buffer data, Handler<AsyncResult<Void>> handler) {
received.appendBuffer(data);
handler.handle(null);
}
@Override
public void end(Handler<AsyncResult<Void>> handler) {
assertTrue(handlerCalled.get(), "Response handler should have been called before first bytes are received");
if (received.length() == fileSize)
ctx.completeNow();
handler.handle(null);
}
@Override
public WriteStream<Buffer> setWriteQueueMaxSize(int maxSize) {
return null;
}
@Override
public boolean writeQueueFull() {
return false;
}
@Override
public WriteStream<Buffer> drainHandler(@Nullable Handler<Void> handler) {
return null;
}
});
transformer.setResponseHandler(resp -> {
handlerCalled.set(true);
});
single(s3.getObject(VertxS3ClientSpec::downloadImgReq, transformer)).subscribe(getRes -> ctx.completeNow(), ctx::failNow);
}
Aggregations