Example usage for io.netty.util.concurrent Promise await

List of usage examples for io.netty.util.concurrent Promise await

Introduction

In this page you can find the example usage for io.netty.util.concurrent Promise await.

Prototype

boolean await(long timeoutMillis) throws InterruptedException;

Source Link

Document

Waits for this future to be completed within the specified time limit.

Usage

From source file:de.unipassau.isl.evs.ssh.master.network.ServerTest.java

License:Open Source License

public void testSerialRoundTrip() throws InterruptedException, ExecutionException {
    final BlockingQueue<Object> serverQueue = new LinkedBlockingQueue<>();
    final BlockingQueue<Object> clientQueue = new LinkedBlockingQueue<>();
    final Promise<SocketChannel> serverChannel = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);
    final Promise<SocketChannel> clientChannel = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);

    SimpleContainer serverContainer = new SimpleContainer();
    addContext(serverContainer);//w  w w  .  j a v a  2 s. c om
    Server server = new TestServer(serverQueue, serverChannel);
    serverContainer.register(UDPDiscoveryServer.KEY, new UDPDiscoveryServer());
    serverContainer.register(Server.KEY, server);
    try {
        SimpleContainer clientContainer = new SimpleContainer();
        addContext(clientContainer);
        Client client = new TestClient(clientQueue, clientChannel);
        clientContainer.register(UDPDiscoveryClient.KEY, new UDPDiscoveryClient());
        clientContainer.register(Client.KEY, client);

        try {
            serverChannel.await(1000);
            clientChannel.await(1000);

            runRoundTripTests(serverQueue, clientQueue, serverChannel, clientChannel);
        } finally {
            clientContainer.unregister(Client.KEY);
            client.awaitShutdown();
        }
    } finally {
        shutdownServer(serverContainer);
    }
    assertTrue(serverQueue.isEmpty());
    assertTrue(clientQueue.isEmpty());
}