use of io.vertx.core.streams.WriteStream in project vertx-web by vert-x3.
the class WebClientTest method testResponseWriteStreamMissingBody.
@Test
public void testResponseWriteStreamMissingBody() throws Exception {
AtomicInteger length = new AtomicInteger();
AtomicBoolean ended = new AtomicBoolean();
WriteStream<Buffer> stream = new WriteStream<Buffer>() {
@Override
public WriteStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
return this;
}
@Override
public WriteStream<Buffer> write(Buffer data) {
length.addAndGet(data.length());
return this;
}
@Override
public void end() {
ended.set(true);
}
@Override
public WriteStream<Buffer> setWriteQueueMaxSize(int maxSize) {
return this;
}
@Override
public boolean writeQueueFull() {
return false;
}
@Override
public WriteStream<Buffer> drainHandler(Handler<Void> handler) {
return this;
}
};
testResponseMissingBody(BodyCodec.pipe(stream));
assertTrue(ended.get());
assertEquals(0, length.get());
}
use of io.vertx.core.streams.WriteStream in project vertx-web by vert-x3.
the class WebClientTest method testResponseBodyCodecError.
@Test
public void testResponseBodyCodecError() throws Exception {
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.setChunked(true);
resp.end(TestUtils.randomBuffer(2048));
});
startServer();
RuntimeException cause = new RuntimeException();
WriteStream<Buffer> stream = new WriteStream<Buffer>() {
Handler<Throwable> exceptionHandler;
@Override
public WriteStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
exceptionHandler = handler;
return this;
}
@Override
public WriteStream<Buffer> write(Buffer data) {
exceptionHandler.handle(cause);
return this;
}
@Override
public void end() {
}
@Override
public WriteStream<Buffer> setWriteQueueMaxSize(int maxSize) {
return this;
}
@Override
public boolean writeQueueFull() {
return false;
}
@Override
public WriteStream<Buffer> drainHandler(Handler<Void> handler) {
return this;
}
};
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get.as(BodyCodec.pipe(stream)).send(onFailure(err -> {
assertSame(cause, err);
testComplete();
}));
await();
}
use of io.vertx.core.streams.WriteStream in project vertx-web by vert-x3.
the class WebClientTest method testResponseBodyStreamError.
@Test
public void testResponseBodyStreamError() throws Exception {
CompletableFuture<Void> fail = new CompletableFuture<>();
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.setChunked(true);
resp.write(TestUtils.randomBuffer(2048));
fail.thenAccept(v -> resp.close());
});
startServer();
AtomicInteger received = new AtomicInteger();
WriteStream<Buffer> stream = new WriteStream<Buffer>() {
@Override
public WriteStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
return this;
}
@Override
public WriteStream<Buffer> write(Buffer data) {
received.addAndGet(data.length());
return this;
}
@Override
public void end() {
}
@Override
public WriteStream<Buffer> setWriteQueueMaxSize(int maxSize) {
return this;
}
@Override
public boolean writeQueueFull() {
return false;
}
@Override
public WriteStream<Buffer> drainHandler(Handler<Void> handler) {
return this;
}
};
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get.as(BodyCodec.pipe(stream)).send(onFailure(err -> testComplete()));
assertWaitUntil(() -> received.get() == 2048);
fail.complete(null);
await();
}
use of io.vertx.core.streams.WriteStream in project georocket by georocket.
the class StoreClientImportTest method importTagsAndProperties.
/**
* Test importing tags and properties
* @param context the test context
* @throws Exception if something goes wrong
*/
@Test
public void importTagsAndProperties(TestContext context) throws Exception {
String url = "/store?tags=testTag%2CtestTag2&props=hello%3Awo%5C%3Arld%2Challo2%3Aworld2";
stubFor(post(urlEqualTo(url)).willReturn(aResponse().withStatus(202)));
Async async = context.async();
WriteStream<Buffer> w = client.getStore().startImport(null, Arrays.asList("testTag", "testTag2"), Arrays.asList("hello:wo\\:rld", "hallo2:world2"), context.asyncAssertSuccess(v -> {
verifyPosted(url, XML, context);
async.complete();
}));
w.end(Buffer.buffer(XML));
}
use of io.vertx.core.streams.WriteStream in project georocket by georocket.
the class StoreClientImportTest method importLayerWithSpecialChars.
/**
* Test importing to a layer with special characters
* @param context the test context
*/
@Test
public void importLayerWithSpecialChars(TestContext context) {
String url = "/store/he%2Bllo/world/";
stubFor(post(urlEqualTo(url)).willReturn(aResponse().withStatus(202)));
Async async = context.async();
WriteStream<Buffer> w = client.getStore().startImport("he+llo/world", context.asyncAssertSuccess(v -> {
verifyPosted(url, XML, context);
async.complete();
}));
w.end(Buffer.buffer(XML));
}
Aggregations