use of java.net.ConnectException in project hbase by apache.
the class TestMetaTableLocator method testVerifyMetaRegionLocationFails.
/**
* Test get of meta region fails properly if nothing to connect to.
* @throws IOException
* @throws InterruptedException
* @throws KeeperException
* @throws ServiceException
*/
@Test
public void testVerifyMetaRegionLocationFails() throws IOException, InterruptedException, KeeperException, ServiceException {
ClusterConnection connection = Mockito.mock(ClusterConnection.class);
ServiceException connectException = new ServiceException(new ConnectException("Connection refused"));
final AdminProtos.AdminService.BlockingInterface implementation = Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
Mockito.when(implementation.getRegionInfo((RpcController) Mockito.any(), (GetRegionInfoRequest) Mockito.any())).thenThrow(connectException);
Mockito.when(connection.getAdmin(Mockito.any(ServerName.class))).thenReturn(implementation);
RpcControllerFactory controllerFactory = Mockito.mock(RpcControllerFactory.class);
Mockito.when(controllerFactory.newController()).thenReturn(Mockito.mock(HBaseRpcController.class));
Mockito.when(connection.getRpcControllerFactory()).thenReturn(controllerFactory);
ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPENING);
assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100));
MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPEN);
assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100));
}
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 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