use of java.net.ConnectException in project flink by apache.
the class KvStateClientTest method testRequestUnavailableHost.
/**
* Tests that a request to an unavailable host is failed with ConnectException.
*/
@Test
public void testRequestUnavailableHost() throws Exception {
Deadline deadline = TEST_TIMEOUT.fromNow();
AtomicKvStateRequestStats stats = new AtomicKvStateRequestStats();
KvStateClient client = null;
try {
client = new KvStateClient(1, stats);
int availablePort = NetUtils.getAvailablePort();
KvStateServerAddress serverAddress = new KvStateServerAddress(InetAddress.getLocalHost(), availablePort);
Future<byte[]> future = client.getKvState(serverAddress, new KvStateID(), new byte[0]);
try {
Await.result(future, deadline.timeLeft());
fail("Did not throw expected ConnectException");
} catch (ConnectException ignored) {
// Expected
}
} finally {
if (client != null) {
client.shutDown();
}
assertEquals("Channel leak", 0, stats.getNumConnections());
}
}
use of java.net.ConnectException in project screenbird by adamhub.
the class ClientIPC method connect.
/**
* Connects to SocketServer using the SOCKET_NAME and SOCK_PORT
* @return True if client is successful in connecting, false otherwise
*/
public boolean connect() {
try {
log("Connecting to Base Server...");
this.client = new Socket(ServerIPC.SOCKET_NAME, ServerIPC.SOCKET_PORT);
log("Connected to Base Server");
log("Client Initiated...");
return true;
} catch (ConnectException e) {
log(e);
} catch (UnknownHostException e) {
log("Could not connect to " + ServerIPC.SOCKET_NAME + ":" + ServerIPC.SOCKET_PORT);
} catch (IOException e) {
log("Could not connect to " + ServerIPC.SOCKET_NAME + ":" + ServerIPC.SOCKET_PORT);
log(e);
} catch (NullPointerException e) {
log(e);
}
return false;
}
use of java.net.ConnectException in project screenbird by adamhub.
the class Client method connectToBaseServer.
private boolean connectToBaseServer() {
try {
System.out.println("Connecting to Base Server...");
this.client = new Socket(SOCKET_NAME, SOCKET_PORT);
ipcManager.setIsRunning(true);
System.out.println("Connected to Base Server");
System.out.println("Client Initiated...");
} catch (ConnectException e) {
e.printStackTrace(System.err);
System.exit(-1);
} catch (UnknownHostException e) {
System.err.println("Could not connect to " + SOCKET_NAME + ":" + SOCKET_PORT);
e.printStackTrace(System.err);
} catch (IOException e) {
System.err.println("Could not connect to " + SOCKET_NAME + ":" + SOCKET_PORT);
e.printStackTrace(System.err);
} catch (NullPointerException e) {
e.printStackTrace(System.err);
}
return false;
}
use of java.net.ConnectException in project sonarqube by SonarSource.
the class EmbeddedTomcatTest method start.
@Test
public void start() throws Exception {
Props props = new Props(new Properties());
// prepare file system
File home = temp.newFolder();
File data = temp.newFolder();
File webDir = new File(home, "web");
FileUtils.write(new File(home, "web/WEB-INF/web.xml"), "<web-app/>");
props.set("sonar.path.home", home.getAbsolutePath());
props.set("sonar.path.data", data.getAbsolutePath());
props.set("sonar.path.web", webDir.getAbsolutePath());
props.set("sonar.path.logs", temp.newFolder().getAbsolutePath());
// start server on a random port
int httpPort = NetworkUtils.freePort();
int ajpPort = NetworkUtils.freePort();
props.set("sonar.web.port", String.valueOf(httpPort));
props.set("sonar.ajp.port", String.valueOf(ajpPort));
EmbeddedTomcat tomcat = new EmbeddedTomcat(props);
assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.DOWN);
tomcat.start();
assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.UP);
// check that http connector accepts requests
URL url = new URL("http://" + Inet4Address.getLocalHost().getHostAddress() + ":" + httpPort);
url.openConnection().connect();
// stop server
tomcat.terminate();
// tomcat.isUp() must not be called. It is used to wait for server startup, not shutdown.
try {
url.openConnection().connect();
fail();
} catch (ConnectException e) {
// expected
}
}
use of java.net.ConnectException in project openhab1-addons by openhab.
the class EBusTCPConnector method connect.
/*
* (non-Javadoc)
*
* @see org.openhab.binding.ebus.connection.AbstractEBusConnector#connect()
*/
@Override
protected boolean connect() throws IOException {
try {
socket = new Socket(hostname, port);
socket.setSoTimeout(20000);
socket.setKeepAlive(true);
socket.setTcpNoDelay(true);
socket.setTrafficClass((byte) 0x10);
// Useful? We try it
// socket.setReceiveBufferSize(1);
socket.setSendBufferSize(1);
inputStream = socket.getInputStream();
outputStream = socket.getOutputStream();
return super.connect();
} catch (ConnectException e) {
logger.error(e.toString());
} catch (Exception e) {
logger.error(e.toString(), e);
}
return false;
}
Aggregations