示例#1
0
        public async Task UploadFileWithNoOverWrite()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(UploadFileWithNoOverWrite)}/sample2";

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile2.txt"), Overwrite : true);

            await Assert.ThrowsAsync <System.Net.Http.HttpRequestException>(() => client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Overwrite: false));
        }
示例#2
0
        public async Task UploadFileWithOverWrite()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(UploadFileWithOverWrite)}/sample2";
            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Overwrite : true);

            var fileStat = await client.GetFileStatus(filePath);

            var oldLenght = fileStat.Length;

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile2.txt"), Overwrite : true);

            fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.Length != oldLenght);
        }
示例#3
0
        public async Task Remove()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(Remove)}/sample2";
            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Overwrite : true);

            await client.Delete(filePath);

            await Assert.ThrowsAsync <System.InvalidOperationException>(() => client.GetFileStatus(filePath));
        }
示例#4
0
        public async Task UploadFileWithReplication()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(UploadFileWithReplication)}/sample2";

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Overwrite : true, Replication : 3);

            var fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.Replication == 3);
        }
示例#5
0
        public async Task UploadFileWithPermission()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(UploadFileWithPermission)}/sample2";
            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Permission : 700, Overwrite : true);

            var fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.Type == "FILE");
            Assert.True(fileStat.Permission == "700");
        }
示例#6
0
        public async Task RenameTest()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var dirPath = $"{DataTestUtility.HdfsRootDir}/{nameof(RenameTest)}";
            await client.Delete(dirPath, Recursive : true);

            await client.UploadFile($"{dirPath}/sample", File.OpenRead("Samples/SampleTextFile.txt"));

            var result = await client.Rename($"{dirPath}/sample", $"{dirPath}/notsample");

            Assert.True(result);
        }
示例#7
0
        public async Task UploadFileWithoutParams()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(UploadFileWithoutParams)}/sample2";
            await client.Delete(filePath);

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"));

            var fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.Type == "FILE");
            Assert.True(fileStat.Permission == "755");
        }
示例#8
0
        public async Task AppendTest()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var dirPath = $"{DataTestUtility.HdfsRootDir}/{nameof(AppendTest)}";
            await client.Delete(dirPath, Recursive : true);

            await client.UploadFile($"{dirPath}/sample", File.OpenRead("Samples/SampleTextFile.txt"), Overwrite : true);

            await client.Append($"{dirPath}/sample", File.OpenRead("Samples/SampleTextFile2.txt"));

            var fileStat = await client.GetFileStatus($"{dirPath}/sample");

            Assert.True(fileStat.Length == 12);
        }
示例#9
0
        public async Task ReadFileStream()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(ReadFileStream)}/sample";
            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Overwrite : true);

            var openResponse = await client.OpenStream(filePath, new OpenParams());

            using (StreamReader reader = new StreamReader(openResponse))
            {
                var openResult = reader.ReadToEnd();
                Assert.True("Some text" == openResult);
            }
        }
示例#10
0
        public async Task SetOwnerOfFile()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(SetOwnerOfFile)}/sample";
            await client.Delete(filePath);

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"));

            await client.SetOwner(filePath, "USER");

            var fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.Owner == "USER");
        }
示例#11
0
        public async Task SetPermissOfFile()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(SetPermissOfFile)}/sample";
            await client.Delete(filePath, Recursive : true);

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Permission : 750);

            await client.SetPermission(filePath, 700);

            var fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.Permission == "700");
        }
示例#12
0
        public async Task SetTimes()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(SetTimes)}/sample";
            await client.Delete(filePath, Recursive : true);

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"));

            await client.SetTimes(filePath, 12345678, 87654321);

            var fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.ModificationTime == 12345678 && fileStat.AccessTime == 87654321);
        }
示例#13
0
        public async Task SetReplic()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(SetReplic)}/sample";
            await client.Delete(filePath, Recursive : true);

            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Replication : 5);

            var result = await client.SetReplicationFactor(filePath, 7);

            var fileStat = await client.GetFileStatus(filePath);

            Assert.True(fileStat.Replication == 7);
            Assert.True(result);
        }
示例#14
0
        public async Task ReadWithOffsetWithLenght()
        {
            client = new WebHdfsClient(DataTestUtility.HdfsConnStr);
            var filePath = $"{DataTestUtility.HdfsRootDir}/{nameof(ReadWithOffsetWithLenght)}/sample";
            await client.UploadFile(filePath, File.OpenRead("Samples/SampleTextFile.txt"), Overwrite : true);

            var openResponse = await client.OpenStream(filePath, new OpenParams()
            {
                Offset = 2, Length = 2
            });

            using (StreamReader reader = new StreamReader(openResponse))
            {
                var openResult = reader.ReadToEnd();
                Assert.Equal("me", openResult);
            }
        }