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();
}