@Override
    public boolean check(final Session<?> session, final CancelCallback callback) throws BackgroundException {
        final Host bookmark = session.getHost();
        if(bookmark.getProtocol().isHostnameConfigurable() && StringUtils.isBlank(bookmark.getHostname())) {
            throw new ConnectionCanceledException();
        }
        if(session.isConnected()) {
            if(log.isDebugEnabled()) {
                log.debug(String.format("Skip opening connection for session %s", session));
            }
            // Connection already open
            return false;
        }
        // Obtain password from keychain or prompt
        synchronized(login) {
            login.validate(bookmark, prompt, new LoginOptions(bookmark.getProtocol()));
        }
        this.connect(session, callback);
        return true;
    }
@Test
    public void testConnectDnsFailure() throws Exception {
        final Session session = new NullSession(new Host(new TestProtocol(), "unknownhost.local", new Credentials("user", "p"))) {
            @Override
            public boolean isConnected() {
                return false;
            }
        };
        final LoginConnectionService s = new LoginConnectionService(new DisabledLoginCallback(), new HostKeyCallback() {
            @Override
            public boolean verify(final Host hostname, final PublicKey key) {
                assertEquals(Session.State.opening, session.getState());
                return true;
            }
        }, new DisabledPasswordStore(),
            new DisabledProgressListener()
        );
        try {
            s.check(session, new DisabledCancelCallback());
            fail();
        }
        catch(ResolveFailedException e) {
            assertEquals("Connection failed", e.getMessage());
            assertEquals("DNS lookup for unknownhost.local failed. DNS is the network service that translates a server name to its Internet address. This error is most often caused by having no connection to the Internet or a misconfigured network. It can also be caused by an unresponsive DNS server or a firewall preventing access to the network.", e.getDetail());
            assertEquals(UnknownHostException.class, e.getCause().getClass());
            assertEquals(Session.State.closed, session.getState());
        }
        try {
            s.check(new NullSession(new Host(new TestProtocol(), "localhost", new Credentials("user", ""))) {
                @Override
                public boolean isConnected() {
                    return false;
                }
            }, new DisabledCancelCallback());
            fail();
        }
        catch(LoginCanceledException e) {

        }
    }