Search in sources :

Example 1 with SingleMasterInquireClient

use of alluxio.master.SingleMasterInquireClient in project alluxio by Alluxio.

the class ServiceSocketBindIntegrationTest method connectDifferentAddress.

@Test
public void connectDifferentAddress() throws Exception {
    startCluster(NetworkAddressUtils.getLocalHostName(100));
    // Connect to Master RPC service on loopback, while Master is listening on local hostname.
    InetSocketAddress masterRpcAddr = new InetSocketAddress("127.0.0.1", mLocalAlluxioCluster.getLocalAlluxioMaster().getRpcLocalPort());
    mBlockMasterClient = BlockMasterClient.Factory.create(MasterClientContext.newBuilder(ClientContext.create(ServerConfiguration.global())).setMasterInquireClient(new SingleMasterInquireClient(masterRpcAddr)).build());
    try {
        mBlockMasterClient.connect();
        Assert.fail("Client should not have successfully connected to master RPC service.");
    } catch (UnavailableException e) {
    // This is expected, since Master RPC service is NOT listening on loopback.
    }
    // Connect to Worker RPC service on loopback, while Worker is listening on local hostname.
    try {
        mBlockMasterClient.connect();
        Assert.fail("Client should not have successfully connected to Worker RPC service.");
    } catch (Exception e) {
    // This is expected, since Work RPC service is NOT listening on loopback.
    }
    // connect Worker data service on loopback, while Worker is listening on local hostname.
    InetSocketAddress workerDataAddr = new InetSocketAddress("127.0.0.1", mLocalAlluxioCluster.getWorkerProcess().getDataLocalPort());
    try {
        mWorkerDataService = SocketChannel.open(workerDataAddr);
        Assert.assertTrue(mWorkerDataService.isConnected());
        Assert.fail("Client should not have successfully connected to Worker RPC service.");
    } catch (IOException e) {
    // This is expected, since Worker data service is NOT listening on loopback.
    }
    // connect Master Web service on loopback, while Master is listening on local hostname.
    try {
        mMasterWebService = (HttpURLConnection) new URL("http://127.0.0.1:" + mLocalAlluxioCluster.getLocalAlluxioMaster().getMasterProcess().getWebAddress().getPort() + "/home").openConnection();
        Assert.assertEquals(200, mMasterWebService.getResponseCode());
        Assert.fail("Client should not have successfully connected to Master Web service.");
    } catch (IOException e) {
    // This is expected, since Master Web service is NOT listening on loopback.
    } finally {
        Assert.assertNotNull(mMasterWebService);
        mMasterWebService.disconnect();
    }
    // connect Worker Web service on loopback, while Worker is listening on local hostname.
    try {
        mWorkerWebService = (HttpURLConnection) new URL("http://127.0.0.1:" + mLocalAlluxioCluster.getWorkerProcess().getWebLocalPort() + "/home").openConnection();
        Assert.assertEquals(200, mWorkerWebService.getResponseCode());
        Assert.fail("Client should not have successfully connected to Worker Web service.");
    } catch (IOException e) {
    // This is expected, since Worker Web service is NOT listening on loopback.
    } finally {
        mWorkerWebService.disconnect();
    }
}
Also used : SingleMasterInquireClient(alluxio.master.SingleMasterInquireClient) InetSocketAddress(java.net.InetSocketAddress) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException) ConnectionFailedException(alluxio.exception.ConnectionFailedException) IOException(java.io.IOException) UnavailableException(alluxio.exception.status.UnavailableException) URL(java.net.URL) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Aggregations

ConnectionFailedException (alluxio.exception.ConnectionFailedException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 SingleMasterInquireClient (alluxio.master.SingleMasterInquireClient)1 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 Test (org.junit.Test)1