public void TestDirectorySetAttributes() { Dictionary <string, string> metadata = new Dictionary <string, string>(); if (DMLibTestContext.SourceType != DMLibDataType.Local) { metadata.Add("foo", "bar"); } DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); for (int i = 0; i < 3; ++i) { FileNode fileNode = new FileNode(DMLibTestBase.FileName + i) { SizeInByte = DMLibTestBase.FileSizeInKB * 1024L, Metadata = metadata }; sourceDataInfo.RootNode.AddFileNode(fileNode); } DirectoryTransferContext context = new DirectoryTransferContext() { SetAttributesCallbackAsync = async(destObj) => { dynamic destCloudObj = destObj; destCloudObj.Properties.ContentType = SetAttributesTest.TestContentType; destCloudObj.Metadata.Add("aa", "bb"); } }; var options = new TestExecutionOptions <DMLibDataInfo>(); options.TransferItemModifier = (node, transferItem) => { dynamic transferOptions = DefaultTransferDirectoryOptions; transferOptions.Recursive = true; transferItem.Options = transferOptions; transferItem.TransferContext = context; }; options.IsDirectoryTransfer = true; var result = this.ExecuteTestCase(sourceDataInfo, options); foreach (FileNode fileNode in sourceDataInfo.EnumerateFileNodes()) { fileNode.Metadata.Add("aa", "bb"); } VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo); VerificationHelper.VerifySingleTransferStatus(result, 3, 0, 0, 3 * DMLibTestBase.FileSizeInKB * 1024L); foreach (FileNode destFileNode in result.DataInfo.EnumerateFileNodes()) { Test.Assert(TestContentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, TestContentType); } }
private void UploadFromStreamTest(DMLibDataType destType, long[] variedSourceLength, int?blockSize, bool seekable, bool fixedSized) { DataAdaptor <DMLibDataInfo> sourceAdaptor = GetSourceAdaptor(DMLibDataType.Stream); DataAdaptor <DMLibDataInfo> destAdaptor = GetDestAdaptor(destType); DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); foreach (long fileSizeInByte in variedSourceLength) { sourceDataInfo.RootNode.AddFileNode(new FileNode($"{FileName}_{fileSizeInByte}") { SizeInByte = fileSizeInByte, }); } sourceAdaptor.GenerateData(sourceDataInfo); destAdaptor.CreateIfNotExists(); List <TransferItem> uploadItems = new List <TransferItem>(); foreach (long fileSizeInByte in variedSourceLength) { string fileName = $"{FileName}_{fileSizeInByte}"; FileNode fileNode = sourceDataInfo.RootNode.GetFileNode(fileName); uploadItems.Add(new TransferItem() { SourceObject = new DMLibTestStream(sourceAdaptor.GetTransferObject(string.Empty, fileNode) as FileStream, seekable, fixedSized), DestObject = destAdaptor.GetTransferObject(string.Empty, fileNode), SourceType = DMLibDataType.Stream, DestType = destType, IsServiceCopy = false }); } // Execution var result = this.RunTransferItems( uploadItems, new TestExecutionOptions <DMLibDataInfo>() { DisableDestinationFetch = true, BlockSize = blockSize.HasValue ? blockSize.Value : 4 * 1024 * 1024 }); if (!fixedSized && (destType == DMLibDataType.PageBlob || destType == DMLibDataType.CloudFile)) { Test.Assert(result.Exceptions.Count == 1 && result.Exceptions[0].Message.Contains("Source must be fixed size"), "Verify error is expected."); } else { // Verify all files are transfered successfully Test.Assert(result.Exceptions.Count == 0, "Verify no exception occurs."); DMLibDataInfo destDataInfo = destAdaptor.GetTransferDataInfo(string.Empty); foreach (FileNode destFileNode in destDataInfo.EnumerateFileNodes()) { FileNode sourceFileNode = sourceDataInfo.RootNode.GetFileNode(destFileNode.Name); Test.Assert(DMLibDataHelper.Equals(sourceFileNode, destFileNode), "Verify transfer result."); } } sourceAdaptor.Cleanup(); destAdaptor.Cleanup(); }
private void DownloadToMultipleStreams(DMLibDataType sourceType, long fileSize, int blockSize = 0) { DataAdaptor <DMLibDataInfo> sourceAdaptor = GetSourceAdaptor(sourceType); DataAdaptor <DMLibDataInfo> destAdaptor1 = GetDestAdaptor(DMLibDataType.Stream); Test.Info("SourceType: {0}, filesize {1}, blocksize {2}", sourceType, fileSize, blockSize); DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty); long fileSizeInByte = fileSize; sourceDataInfo.RootNode.AddFileNode(new FileNode(FileName) { SizeInByte = fileSizeInByte, }); sourceAdaptor.GenerateData(sourceDataInfo); destAdaptor1.CreateIfNotExists(); List <TransferItem> downloadItems = new List <TransferItem>(); FileNode fileNode = sourceDataInfo.RootNode.GetFileNode(FileName); int streamCount = random.Next(2, 6); for (int i = 0; i < streamCount; ++i) { downloadItems.Add(new TransferItem() { SourceObject = sourceAdaptor.GetTransferObject(string.Empty, fileNode), DestObject = (destAdaptor1 as LocalDataAdaptor).GetTransferObject(string.Empty, $"{FileName}_{i}"), SourceType = sourceType, DestType = DMLibDataType.Stream, IsServiceCopy = false }); } var options = new TestExecutionOptions <DMLibDataInfo>() { DisableDestinationFetch = true, }; if (0 != blockSize) { options.BlockSize = blockSize; } // Execution var result = this.RunTransferItems( downloadItems, options); // Verify all files are transfered successfully Test.Assert(result.Exceptions.Count == 0, "Verify no exception occurs."); DMLibDataInfo destDataInfo = destAdaptor1.GetTransferDataInfo(string.Empty); foreach (FileNode destFileNode in destDataInfo.EnumerateFileNodes()) { var toBeValidateFileNode = destFileNode.Clone(FileName); FileNode sourceFileNode = sourceDataInfo.RootNode.GetFileNode(FileName); Test.Assert(DMLibDataHelper.Equals(sourceFileNode, toBeValidateFileNode), "Verify transfer result."); } sourceAdaptor.Cleanup(); destAdaptor1.Cleanup(); }
public static void SetCalculatedFileMD5(DMLibDataInfo dataInfo, DataAdaptor<DMLibDataInfo> destAdaptor, bool disableMD5Check = false) { foreach (FileNode fileNode in dataInfo.EnumerateFileNodes()) { if (DMLibTestBase.IsCloudBlob(DMLibTestContext.DestType)) { CloudBlobDataAdaptor cloudBlobDataAdaptor = destAdaptor as CloudBlobDataAdaptor; CloudBlob cloudBlob = cloudBlobDataAdaptor.GetCloudBlobReference(dataInfo.RootPath, fileNode); fileNode.MD5 = CloudBlobHelper.CalculateMD5ByDownloading(cloudBlob, disableMD5Check); } else if (DMLibTestContext.DestType == DMLibDataType.CloudFile) { CloudFileDataAdaptor cloudFileDataAdaptor = destAdaptor as CloudFileDataAdaptor; CloudFile cloudFile = cloudFileDataAdaptor.GetCloudFileReference(dataInfo.RootPath, fileNode); fileNode.MD5 = CloudFileHelper.CalculateMD5ByDownloading(cloudFile, disableMD5Check); } // No need to set md5 for local destination } }