Search in sources :

Example 36 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobServerGetTest method testGetFailsDuringStreaming.

@Test
public void testGetFailsDuringStreaming() {
    BlobServer server = null;
    BlobClient client = null;
    try {
        Configuration config = new Configuration();
        server = new BlobServer(config);
        InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
        client = new BlobClient(serverAddress, config);
        byte[] data = new byte[5000000];
        rnd.nextBytes(data);
        // put content addressable (like libraries)
        BlobKey key = client.put(data);
        assertNotNull(key);
        // issue a GET request that succeeds
        InputStream is = client.get(key);
        byte[] receiveBuffer = new byte[50000];
        BlobUtils.readFully(is, receiveBuffer, 0, receiveBuffer.length, null);
        BlobUtils.readFully(is, receiveBuffer, 0, receiveBuffer.length, null);
        // shut down the server
        for (BlobServerConnection conn : server.getCurrentActiveConnections()) {
            conn.close();
        }
        try {
            byte[] remainder = new byte[data.length - 2 * receiveBuffer.length];
            BlobUtils.readFully(is, remainder, 0, remainder.length, null);
        // we tolerate that this succeeds, as the receiver socket may have buffered
        // everything already
        } catch (IOException e) {
        // expected
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 37 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobServerPutTest method testPutChunkedStreamSuccessful.

@Test
public void testPutChunkedStreamSuccessful() {
    BlobServer server = null;
    BlobClient client = null;
    try {
        Configuration config = new Configuration();
        server = new BlobServer(config);
        InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
        client = new BlobClient(serverAddress, config);
        byte[] data = new byte[2000000];
        rnd.nextBytes(data);
        // put content addressable (like libraries)
        {
            BlobKey key1 = client.put(new ChunkedInputStream(data, 19));
            assertNotNull(key1);
        }
        // put under job and name scope
        {
            JobID jid = new JobID();
            String stringKey = "my test key";
            client.put(jid, stringKey, new ChunkedInputStream(data, 17));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) JobID(org.apache.flink.api.common.JobID) IOException(java.io.IOException) Test(org.junit.Test)

Example 38 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobServerPutTest method testPutBufferFails.

@Test
public void testPutBufferFails() {
    //setWritable doesn't work on Windows.
    assumeTrue(!OperatingSystem.isWindows());
    BlobServer server = null;
    BlobClient client = null;
    File tempFileDir = null;
    try {
        Configuration config = new Configuration();
        server = new BlobServer(config);
        // make sure the blob server cannot create any files in its storage dir
        tempFileDir = server.createTemporaryFilename().getParentFile().getParentFile();
        assertTrue(tempFileDir.setExecutable(true, false));
        assertTrue(tempFileDir.setReadable(true, false));
        assertTrue(tempFileDir.setWritable(false, false));
        InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
        client = new BlobClient(serverAddress, config);
        byte[] data = new byte[2000000];
        rnd.nextBytes(data);
        // put content addressable (like libraries)
        try {
            client.put(data);
            fail("This should fail.");
        } catch (IOException e) {
            assertTrue(e.getMessage(), e.getMessage().contains("Server side error"));
        }
        try {
            client.put(data);
            fail("Client should be closed");
        } catch (IllegalStateException e) {
        // expected
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        // set writable again to make sure we can remove the directory
        if (tempFileDir != null) {
            tempFileDir.setWritable(true, false);
        }
        if (client != null) {
            try {
                client.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 39 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobServerPutTest method testPutStreamSuccessful.

@Test
public void testPutStreamSuccessful() {
    BlobServer server = null;
    BlobClient client = null;
    try {
        Configuration config = new Configuration();
        server = new BlobServer(config);
        InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
        client = new BlobClient(serverAddress, config);
        byte[] data = new byte[2000000];
        rnd.nextBytes(data);
        // put content addressable (like libraries)
        {
            BlobKey key1 = client.put(new ByteArrayInputStream(data));
            assertNotNull(key1);
        }
        // put under job and name scope
        {
            JobID jid = new JobID();
            String stringKey = "my test key";
            client.put(jid, stringKey, new ByteArrayInputStream(data));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) InetSocketAddress(java.net.InetSocketAddress) JobID(org.apache.flink.api.common.JobID) IOException(java.io.IOException) Test(org.junit.Test)

Example 40 with InetSocketAddress

use of java.net.InetSocketAddress in project flink by apache.

the class BlobServerPutTest method testPutNamedBufferFails.

@Test
public void testPutNamedBufferFails() {
    //setWritable doesn't work on Windows.
    assumeTrue(!OperatingSystem.isWindows());
    BlobServer server = null;
    BlobClient client = null;
    File tempFileDir = null;
    try {
        Configuration config = new Configuration();
        server = new BlobServer(config);
        // make sure the blob server cannot create any files in its storage dir
        tempFileDir = server.createTemporaryFilename().getParentFile().getParentFile();
        assertTrue(tempFileDir.setExecutable(true, false));
        assertTrue(tempFileDir.setReadable(true, false));
        assertTrue(tempFileDir.setWritable(false, false));
        InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
        client = new BlobClient(serverAddress, config);
        byte[] data = new byte[2000000];
        rnd.nextBytes(data);
        // put under job and name scope
        try {
            JobID jid = new JobID();
            String stringKey = "my test key";
            client.put(jid, stringKey, data);
            fail("This should fail.");
        } catch (IOException e) {
            assertTrue(e.getMessage(), e.getMessage().contains("Server side error"));
        }
        try {
            JobID jid = new JobID();
            String stringKey = "another key";
            client.put(jid, stringKey, data);
            fail("Client should be closed");
        } catch (IllegalStateException e) {
        // expected
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        // set writable again to make sure we can remove the directory
        if (tempFileDir != null) {
            tempFileDir.setWritable(true, false);
        }
        if (client != null) {
            try {
                client.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) File(java.io.File) JobID(org.apache.flink.api.common.JobID) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2586 Test (org.junit.Test)595 IOException (java.io.IOException)592 Socket (java.net.Socket)345 InetAddress (java.net.InetAddress)242 SocketAddress (java.net.SocketAddress)176 ServerSocket (java.net.ServerSocket)170 ArrayList (java.util.ArrayList)168 Configuration (org.apache.hadoop.conf.Configuration)140 ByteBuffer (java.nio.ByteBuffer)129 UnknownHostException (java.net.UnknownHostException)122 InputStream (java.io.InputStream)102 OutputStream (java.io.OutputStream)101 SocketChannel (java.nio.channels.SocketChannel)101 SocketException (java.net.SocketException)89 File (java.io.File)88 HashMap (java.util.HashMap)78 URI (java.net.URI)72 Proxy (java.net.Proxy)65 SocketTimeoutException (java.net.SocketTimeoutException)65