Search in sources :

Example 16 with ConnectException

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));
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 17 with ConnectException

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());
    }
}
Also used : Deadline(scala.concurrent.duration.Deadline) KvStateServerAddress(org.apache.flink.runtime.query.KvStateServerAddress) KvStateID(org.apache.flink.runtime.query.KvStateID) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 18 with ConnectException

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) Socket(java.net.Socket) ConnectException(java.net.ConnectException)

Example 19 with ConnectException

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) Socket(java.net.Socket) ConnectException(java.net.ConnectException)

Example 20 with ConnectException

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;
}
Also used : Socket(java.net.Socket) IOException(java.io.IOException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)521 IOException (java.io.IOException)211 Socket (java.net.Socket)84 SocketTimeoutException (java.net.SocketTimeoutException)69 Test (org.junit.Test)69 UnknownHostException (java.net.UnknownHostException)57 InetSocketAddress (java.net.InetSocketAddress)56 WebServiceException (javax.xml.ws.WebServiceException)48 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 FileNotFoundException (java.io.FileNotFoundException)39 URL (java.net.URL)36 InputStream (java.io.InputStream)33 NoRouteToHostException (java.net.NoRouteToHostException)33 SocketException (java.net.SocketException)33 ArrayList (java.util.ArrayList)31 InetAddress (java.net.InetAddress)29 InputStreamReader (java.io.InputStreamReader)28 OutputStream (java.io.OutputStream)28 HttpURLConnection (java.net.HttpURLConnection)28