use of io.vertx.core.Promise in project vert.x by eclipse.
the class WriteHandlerLookupFailureTest method test.
@Test
public void test() {
Throwable cause = new Throwable();
VertxOptions options = new VertxOptions();
options.getEventBusOptions().setHost("localhost").setPort(0);
NodeSelector nodeSelector = new DefaultNodeSelector() {
@Override
public void selectForSend(Message<?> message, Promise<String> promise) {
promise.fail(cause);
}
@Override
public void selectForPublish(Message<?> message, Promise<Iterable<String>> promise) {
promise.fail("Not implemented");
}
};
new VertxBuilder(options).init().clusterNodeSelector(nodeSelector).clusteredVertx(onSuccess(node -> {
vertx = node;
MessageProducer<String> sender = vertx.eventBus().sender("foo");
sender.write("the_string", onFailure(err -> {
assertSame(cause, err);
testComplete();
}));
}));
await();
}
use of io.vertx.core.Promise in project vert.x by eclipse.
the class TracerTest method testWorkerExecutor.
@Test
public void testWorkerExecutor() {
WorkerExecutor exec = vertx.createSharedWorkerExecutor("exec");
ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext();
ContextInternal duplicate = ctx.duplicate();
duplicate.runOnContext(v -> {
exec.executeBlocking(Promise::complete, onSuccess(res -> {
testComplete();
}));
});
await();
}
use of io.vertx.core.Promise in project vert.x by eclipse.
the class AsyncFileImpl method doFlush.
private synchronized void doFlush(Handler<AsyncResult<Void>> handler) {
checkClosed();
context.executeBlockingInternal((Promise<Void> fut) -> {
try {
ch.force(false);
fut.complete();
} catch (IOException e) {
throw new FileSystemException(e);
}
}, handler);
}
use of io.vertx.core.Promise in project vert.x by eclipse.
the class Http1xServerConnection method netSocket.
void netSocket(Promise<NetSocket> promise) {
context.execute(() -> {
// Flush out all pending data
flush();
// remove old http handlers and replace the old handler with one that handle plain sockets
ChannelPipeline pipeline = chctx.pipeline();
ChannelHandler compressor = pipeline.get(HttpChunkContentCompressor.class);
if (compressor != null) {
pipeline.remove(compressor);
}
pipeline.remove("httpDecoder");
if (pipeline.get("chunkedWriter") != null) {
pipeline.remove("chunkedWriter");
}
pipeline.replace("handler", "handler", VertxHandler.create(ctx -> {
NetSocketImpl socket = new NetSocketImpl(context, ctx, sslHelper, metrics) {
@Override
protected void handleClosed() {
if (metrics != null) {
Http1xServerRequest request = Http1xServerConnection.this.responseInProgress;
metrics.responseEnd(request.metric(), request.response(), request.response().bytesWritten());
}
super.handleClosed();
}
@Override
public synchronized void handleMessage(Object msg) {
if (msg instanceof HttpContent) {
ReferenceCountUtil.release(msg);
return;
}
super.handleMessage(msg);
}
};
socket.metric(metric());
return socket;
}));
// check if the encoder can be removed yet or not.
pipeline.remove("httpEncoder");
//
VertxHandler<NetSocketImpl> handler = (VertxHandler<NetSocketImpl>) pipeline.get("handler");
promise.complete(handler.getConnection());
});
}
use of io.vertx.core.Promise in project vert.x by eclipse.
the class ClusteredAsynchronousLockTest method testLockReleasedForKilledNode.
/**
* Cannot run with the fake cluster manager.
* Subclasses need to override the method and call <code>super.testLockReleasedForKilledNode()</code>.
*/
@Test
@Ignore
public void testLockReleasedForKilledNode() throws Exception {
testLockReleased(latch -> {
VertxInternal vi = (VertxInternal) vertices[0];
Promise<Void> promise = vi.getOrCreateContext().promise();
vi.getClusterManager().leave(promise);
promise.future().onComplete(onSuccess(v -> {
latch.countDown();
}));
});
}
Aggregations