コード例 #1
0
ファイル: S3V4FilesystemTests.cs プロジェクト: sergey-msu/nfx
    public void CombinePaths()
    {
      using(var fs = new S3V4FileSystem("S3-1"))
      {
        Assert.AreEqual("https://dxw.s3-us-west-2.amazonaws.com/a.txt", fs.CombinePaths("https://dxw.s3-us-west-2.amazonaws.com/", "a.txt"));
        Assert.AreEqual("https://dxw.s3-us-west-2.amazonaws.com/a.txt", fs.CombinePaths("https://dxw.s3-us-west-2.amazonaws.com/", "/a.txt"));

              
        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "nfx", "books", "saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "nfx", "/books", "saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "/nfx", "/books", "saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "/nfx", "/books", "/saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "nfx", "books", "/saga.pdf"));


        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "nfx/", "books", "saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "nfx/", "/books", "saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "/nfx/", "/books", "saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "/nfx/", "/books", "/saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "/nfx/", "/books", "/saga.pdf"));

        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "nfx/", "books", "/saga.pdf"));


        Assert.AreEqual("https://dxw.s3-us-west-1.amazonaws.com/nfx/books/saga.pdf", 
        fs.CombinePaths("https://dxw.s3-us-west-1.amazonaws.com/", "nfx", "books", "/saga.pdf"));
      }   
    }
コード例 #2
0
ファイル: S3V4FilesystemTests.cs プロジェクト: cole2295/nfx
        public void Parallel_CreateWriteReadFile()
        {
            using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig()))
              {
            using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3)))
            {
              System.Threading.Tasks.Parallel.For(PARALLEL_FROM, PARALLEL_TO,
            (i) =>
            {
              var fn = FN_PARALLEL_MASK.Args(i);
              var session = fs.StartSession();

              var dir = session[S3_ROOT_FS] as FileSystemDirectory;

              using (var file = dir.CreateFile(fn))
              {
                file.WriteAllText("Hello, {0}".Args(i));
              }

              using (var file = session[fs.CombinePaths(S3_ROOT_FS, fn)] as FileSystemFile)
              {
                Assert.AreEqual("Hello, {0}".Args(i), file.ReadAllText());
                file.Delete();
              }
              Assert.IsNull(session[fs.CombinePaths(S3_ROOT_FS, fn)]);

            });//Parallel.For
            }
              }
        }
コード例 #3
0
ファイル: S3V4FilesystemTests.cs プロジェクト: cole2295/nfx
        public void CreateWriteReadFile_3()
        {
            using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig()))
              {
            using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3)))
            {
              var session = fs.StartSession();

              var dir = session[S3_ROOT_FS] as FileSystemDirectory;

              using (var file = dir.CreateFile(FN4_FS))
              {
            file.WriteAllText("Hello,");
            file.WriteAllText("this will overwrite");
              }

              using (var file = session[fs.CombinePaths(S3_ROOT_FS, FN4_FS)] as FileSystemFile)
              {
            Assert.AreEqual("this will overwrite", file.ReadAllText());
              }
            }
              }
        }
コード例 #4
0
ファイル: S3V4FilesystemTests.cs プロジェクト: cole2295/nfx
        public void CreateWriteReadFile_1()
        {
            using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig()))
              {
            using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3)))
            {
              var session = fs.StartSession();

              var dir = session[S3_ROOT_FS] as FileSystemDirectory;

              using (var file = dir.CreateFile(FN2_FS))
              {
            var str = file.FileStream;

            var wri = new BinaryWriter(str);

            wri.Write("Hello!");
            wri.Write(true);
            wri.Write(27.4d);
            wri.Close();
              }

              using (var file = session[fs.CombinePaths(S3_ROOT_FS, FN2_FS)] as FileSystemFile)
              {
            var str = file.FileStream;

            var rdr = new BinaryReader(str);

            Assert.AreEqual("Hello!", rdr.ReadString());
            Assert.AreEqual(true, rdr.ReadBoolean());
            Assert.AreEqual(27.4d, rdr.ReadDouble());
              }
            }
              }
        }
コード例 #5
0
ファイル: S3V4FilesystemTests.cs プロジェクト: cole2295/nfx
        public void CreateWriteCopyReadFile()
        {
            using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig()))
              {
            using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3)))
            {
              var session = fs.StartSession();

              var dir = session[S3_ROOT_FS] as FileSystemDirectory;

              using (Stream s = new FileStream(FN2_FS_FULLPATH, FileMode.Create, FileAccess.Write))
              {
            var wri = new BinaryWriter(s);

            wri.Write("Hello!");
            wri.Write(true);
            wri.Write(27.4d);
            wri.Close();
              }

              //FN3 copied from FN2 and made readonly

              Assert.IsNotNull(dir.CreateFile(FN3_FS, Path.Combine(LOCAL_ROOT_FS, FN2_FS), true));

              using (var file = session[fs.CombinePaths(S3_ROOT_FS, FN3_FS)] as FileSystemFile)
              {
            var str = file.FileStream;

            var rdr = new BinaryReader(str);

            Assert.AreEqual("Hello!", rdr.ReadString());
            Assert.AreEqual(true, rdr.ReadBoolean());
            Assert.AreEqual(27.4d, rdr.ReadDouble());
              }
            }
              }
        }
コード例 #6
0
ファイル: S3V4FilesystemTests.cs プロジェクト: cole2295/nfx
        public void CreateDeleteFile()
        {
            using(new NFX.ApplicationModel.ServiceBaseApplication(null, LACONF.AsLaconicConfig()))
              {
            using (var fs = new S3V4FileSystem(NFX_S3, getFSNode(NFX_S3)))
            {
              var session = fs.StartSession();
              var dir = session[S3_ROOT_FS] as FileSystemDirectory;
              var file = dir.CreateFile(S3_FN1, 1500);

              Assert.AreEqual(S3_FN1, file.Name);

              IDictionary<string, string> headersFN1 = S3V4.GetItemMetadata(file.Path, S3_ACCESSKEY, S3_SECRETKEY, S3_BUCKET, S3_REGION, 0);
              Assert.AreEqual(1500, headersFN1["Content-Length"].AsInt());
              Assert.AreEqual(1500, file.FileStream.Length);

              Assert.AreEqual(1500, file.Size);

              var file2 = session[fs.CombinePaths(S3_ROOT_FS, S3_FN1)];
              Assert.IsNotNull(file2);
              Assert.IsTrue(file2 is FileSystemFile);
              Assert.AreEqual(S3_FN1, ((FileSystemFile)file2).Name);

              file.Dispose();

              file2.Delete();
              Assert.IsFalse(fileExists((FileSystemFile)file2));
            }
              }
        }