Example #1
0
        public static void WaitUntilFileCreated(FileNode fileNode, DataAdaptor <DMLibDataInfo> dataAdaptor, DMLibDataType dataType, int timeoutInSec = 300)
        {
            Func <bool> checkFileCreated = null;

            if (dataType == DMLibDataType.Local)
            {
                string filePath = dataAdaptor.GetAddress() + fileNode.GetLocalRelativePath();
                checkFileCreated = () =>
                {
                    return(File.Exists(filePath));
                };
            }
            else if (dataType == DMLibDataType.PageBlob ||
                     dataType == DMLibDataType.AppendBlob)
            {
                CloudBlobDataAdaptor blobAdaptor = dataAdaptor as CloudBlobDataAdaptor;

                checkFileCreated = () =>
                {
                    CloudBlob cloudBlob = blobAdaptor.GetCloudBlobReference(fileNode);
                    return(cloudBlob.Exists(options: HelperConst.DefaultBlobOptions));
                };
            }
            else if (dataType == DMLibDataType.BlockBlob)
            {
                CloudBlobDataAdaptor blobAdaptor = dataAdaptor as CloudBlobDataAdaptor;

                checkFileCreated = () =>
                {
                    CloudBlockBlob blockBlob = blobAdaptor.GetCloudBlobReference(fileNode) as CloudBlockBlob;
                    try
                    {
                        return(blockBlob.DownloadBlockList(BlockListingFilter.All, options: HelperConst.DefaultBlobOptions).Any());
                    }
                    catch (StorageException)
                    {
                        return(false);
                    }
                };
            }
            else if (dataType == DMLibDataType.CloudFile)
            {
                CloudFileDataAdaptor fileAdaptor = dataAdaptor as CloudFileDataAdaptor;

                checkFileCreated = () =>
                {
                    CloudFile cloudFile = fileAdaptor.GetCloudFileReference(fileNode);
                    return(cloudFile.Exists(options: HelperConst.DefaultFileOptions));
                };
            }
            else
            {
                Test.Error("Unexpected data type: {0}", DMLibTestContext.SourceType);
            }

            MultiDirectionTestHelper.WaitUntil(checkFileCreated, timeoutInSec);
        }
        public void TransferDifferentSizeObject()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddMultipleFilesNormalSize(sourceDataInfo.RootNode, BVT.UnicodeFileName);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.AfterDataPrepared = () =>
            {
                if ((DMLibTestContext.SourceType == DMLibDataType.CloudFile || DMLibTestContext.SourceType == DMLibDataType.PageBlob) &&
                    !DMLibTestContext.IsAsync)
                {
                    string sparseFileName = "SparseFile";

                    DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, sparseFileName, 1);
                    FileNode sparseFileNode = sourceDataInfo.RootNode.GetFileNode(sparseFileName);

                    if (DMLibTestContext.SourceType == DMLibDataType.CloudFile)
                    {
                        CloudFileDataAdaptor cloudFileDataAdaptor = SourceAdaptor as CloudFileDataAdaptor;
                        CloudFile            sparseCloudFile      = cloudFileDataAdaptor.GetCloudFileReference(sourceDataInfo.RootPath, sparseFileNode);
                        this.PrepareCloudFileWithDifferentSizeRange(sparseCloudFile);
                        sparseFileNode.MD5      = sparseCloudFile.Properties.ContentMD5;
                        sparseFileNode.Metadata = sparseCloudFile.Metadata;
                    }
                    else if (DMLibTestContext.SourceType == DMLibDataType.PageBlob)
                    {
                        CloudBlobDataAdaptor cloudBlobDataAdaptor = SourceAdaptor as CloudBlobDataAdaptor;
                        CloudPageBlob        sparsePageBlob       = cloudBlobDataAdaptor.GetCloudBlobReference(sourceDataInfo.RootPath, sparseFileNode) as CloudPageBlob;
                        this.PreparePageBlobWithDifferenSizePage(sparsePageBlob);
                        sparseFileNode.MD5      = sparsePageBlob.Properties.ContentMD5;
                        sparseFileNode.Metadata = sparsePageBlob.Metadata;
                    }
                }
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // For sync copy, recalculate md5 of destination by downloading the file to local.
            if (IsCloudService(DMLibTestContext.DestType) && !DMLibTestContext.IsAsync)
            {
                DMLibDataHelper.SetCalculatedFileMD5(result.DataInfo, DestAdaptor);
            }

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
Example #3
0
        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(fileNode);

                    fileNode.MD5 = CloudBlobHelper.CalculateMD5ByDownloading(cloudBlob, disableMD5Check);
                }
                else if (DMLibTestContext.DestType == DMLibDataType.CloudFile)
                {
                    CloudFileDataAdaptor cloudFileDataAdaptor = destAdaptor as CloudFileDataAdaptor;
                    CloudFile            cloudFile            = cloudFileDataAdaptor.GetCloudFileReference(fileNode);

                    fileNode.MD5 = CloudFileHelper.CalculateMD5ByDownloading(cloudFile, disableMD5Check);
                }

                // No need to set md5 for local destination
            }
        }