示例#1
0
        private static string GetHostnameForSpnegoPrincipal(Configuration conf)
        {
            string addr = conf.GetTrimmed(DFSConfigKeys.DfsDatanodeHttpAddressKey, null);

            if (addr == null)
            {
                addr = conf.GetTrimmed(DFSConfigKeys.DfsDatanodeHttpsAddressKey, DFSConfigKeys.DfsDatanodeHttpsAddressDefault
                                       );
            }
            IPEndPoint inetSocker = NetUtils.CreateSocketAddr(addr);

            return(inetSocker.GetHostString());
        }
示例#2
0
        public virtual void TestWebHdfsOffsetAndLength()
        {
            MiniDFSCluster cluster = null;
            Configuration  conf    = WebHdfsTestUtil.CreateConf();
            int            Offset  = 42;
            int            Length  = 512;
            string         Path    = "/foo";

            byte[] Contents = new byte[1024];
            Random.NextBytes(Contents);
            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
                WebHdfsFileSystem fs = WebHdfsTestUtil.GetWebHdfsFileSystem(conf, WebHdfsFileSystem
                                                                            .Scheme);
                using (OutputStream os = fs.Create(new Path(Path)))
                {
                    os.Write(Contents);
                }
                IPEndPoint addr = cluster.GetNameNode().GetHttpAddress();
                Uri        url  = new Uri("http", addr.GetHostString(), addr.Port, WebHdfsFileSystem.PathPrefix
                                          + Path + "?op=OPEN" + Param.ToSortedString("&", new OffsetParam((long)Offset),
                                                                                     new LengthParam((long)Length)));
                HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();
                conn.SetInstanceFollowRedirects(true);
                NUnit.Framework.Assert.AreEqual(Length, conn.GetContentLength());
                byte[] subContents  = new byte[Length];
                byte[] realContents = new byte[Length];
                System.Array.Copy(Contents, Offset, subContents, 0, Length);
                IOUtils.ReadFully(conn.GetInputStream(), realContents);
                Assert.AssertArrayEquals(subContents, realContents);
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }