Search in sources :

Example 1 with NoRedirectParam

use of org.apache.hadoop.hdfs.web.resources.NoRedirectParam in project hadoop by apache.

the class TestWebHDFS method testWebHdfsNoRedirect.

@Test
public /**
   * Test that when "&noredirect=true" is added to operations CREATE, APPEND,
   * OPEN, and GETFILECHECKSUM the response (which is usually a 307 temporary
   * redirect) is a 200 with JSON that contains the redirected location
   */
void testWebHdfsNoRedirect() throws Exception {
    MiniDFSCluster cluster = null;
    final Configuration conf = WebHdfsTestUtil.createConf();
    try {
        cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
        LOG.info("Started cluster");
        InetSocketAddress addr = cluster.getNameNode().getHttpAddress();
        URL url = new URL("http", addr.getHostString(), addr.getPort(), WebHdfsFileSystem.PATH_PREFIX + "/testWebHdfsNoRedirectCreate" + "?op=CREATE" + Param.toSortedString("&", new NoRedirectParam(true)));
        LOG.info("Sending create request " + url);
        checkResponseContainsLocation(url, "PUT");
        //Write a file that we can read
        final WebHdfsFileSystem fs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME);
        final String PATH = "/testWebHdfsNoRedirect";
        byte[] CONTENTS = new byte[1024];
        RANDOM.nextBytes(CONTENTS);
        try (OutputStream os = fs.create(new Path(PATH))) {
            os.write(CONTENTS);
        }
        url = new URL("http", addr.getHostString(), addr.getPort(), WebHdfsFileSystem.PATH_PREFIX + "/testWebHdfsNoRedirect" + "?op=OPEN" + Param.toSortedString("&", new NoRedirectParam(true)));
        LOG.info("Sending open request " + url);
        checkResponseContainsLocation(url, "GET");
        url = new URL("http", addr.getHostString(), addr.getPort(), WebHdfsFileSystem.PATH_PREFIX + "/testWebHdfsNoRedirect" + "?op=GETFILECHECKSUM" + Param.toSortedString("&", new NoRedirectParam(true)));
        LOG.info("Sending getfilechecksum request " + url);
        checkResponseContainsLocation(url, "GET");
        url = new URL("http", addr.getHostString(), addr.getPort(), WebHdfsFileSystem.PATH_PREFIX + "/testWebHdfsNoRedirect" + "?op=APPEND" + Param.toSortedString("&", new NoRedirectParam(true)));
        LOG.info("Sending append request " + url);
        checkResponseContainsLocation(url, "POST");
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) InetSocketAddress(java.net.InetSocketAddress) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) NoRedirectParam(org.apache.hadoop.hdfs.web.resources.NoRedirectParam) URL(java.net.URL) Test(org.junit.Test) HttpServerFunctionalTest(org.apache.hadoop.http.HttpServerFunctionalTest)

Aggregations

OutputStream (java.io.OutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 NoRedirectParam (org.apache.hadoop.hdfs.web.resources.NoRedirectParam)1 HttpServerFunctionalTest (org.apache.hadoop.http.HttpServerFunctionalTest)1 Test (org.junit.Test)1