Search in sources :

Example 1 with Optional

use of io.socket.util.Optional in project socket.io-client-java by socketio.

the class SocketTest method doesNotFireConnectErrorIfWeForceDisconnectInOpeningState.

@Test(timeout = TIMEOUT)
public void doesNotFireConnectErrorIfWeForceDisconnectInOpeningState() throws URISyntaxException, InterruptedException {
    final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
    IO.Options opts = new IO.Options();
    opts.timeout = 100;
    socket = client(opts);
    socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {

        @Override
        public void call(Object... args) {
            values.offer(Optional.of(new Error("Unexpected")));
        }
    });
    socket.connect();
    socket.disconnect();
    new Timer().schedule(new TimerTask() {

        @Override
        public void run() {
            values.offer(Optional.empty());
        }
    }, 300);
    @SuppressWarnings("unchecked") Optional<Error> err = values.take();
    if (err.isPresent())
        throw err.get();
}
Also used : Emitter(io.socket.emitter.Emitter) Optional(io.socket.util.Optional) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Test(org.junit.Test)

Aggregations

Emitter (io.socket.emitter.Emitter)1 Optional (io.socket.util.Optional)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Test (org.junit.Test)1