public static void ClassInitialize() { //get a OSS client object _ossClient = OssClientFactory.CreateOssClient(); //get current class name, which is prefix of bucket/object _className = TestContext.CurrentContext.Test.FullName; _className = _className.Substring(_className.LastIndexOf('.') + 1).ToLowerInvariant(); //create the bucket _bucketName = OssTestUtils.GetBucketName(_className); _ossClient.CreateBucket(_bucketName); //create sample object _keyName = OssTestUtils.GetObjectKey(_className); }
public void ResumableDownloadBigFileSingleThreadWithProgressUpdateTest() { var targetFile = OssTestUtils.GetTargetFileName(_className); targetFile = Path.Combine(Config.DownloadFolder, targetFile); var key = OssTestUtils.GetObjectKey(_className); _ossClient.PutObject(_bucketName, key, Config.MultiUploadTestFile); bool progressUpdateCalled = false; int percentDone = 0; long totalBytesDownloaded = 0; var config = new ClientConfiguration(); config.EnalbeMD5Check = true; var client = OssClientFactory.CreateOssClient(config); try { DownloadObjectRequest request = new DownloadObjectRequest(_bucketName, key, targetFile); request.ParallelThreadCount = 1; request.StreamTransferProgress += (object sender, StreamTransferProgressArgs e) => { totalBytesDownloaded += e.TransferredBytes; Console.WriteLine("TotalBytes:" + e.TotalBytes); Console.WriteLine("TransferredBytes:" + e.TransferredBytes); Console.WriteLine("PercentageDone:" + e.PercentDone); progressUpdateCalled = true; percentDone = e.PercentDone; }; var metadata = client.ResumableDownloadObject(request); var expectedETag = metadata.ETag; var downloadedFileETag = FileUtils.ComputeContentMd5(targetFile); Assert.AreEqual(expectedETag.ToLowerInvariant(), downloadedFileETag.ToLowerInvariant()); Assert.AreEqual(progressUpdateCalled, true); Assert.AreEqual(percentDone, 100); } finally { try { FileUtils.DeleteFile(targetFile); } catch (Exception e) { LogUtility.LogWarning("Delete file {0} failed with Exception {1}", targetFile, e.Message); } _ossClient.DeleteObject(_bucketName, key); } }
public static void ClassInitialize() { //get a OSS client object _ossClient = OssClientFactory.CreateOssClient(); //get current class name, which is prefix of bucket/object _className = TestContext.CurrentContext.Test.FullName; _className = _className.Substring(_className.LastIndexOf('.') + 1).ToLowerInvariant(); //create the bucket _bucketName = OssTestUtils.GetBucketName(_className); _ossClient.CreateBucket(_bucketName); //create sample object _objectKey = OssTestUtils.GetObjectKey(_className); var poResult = OssTestUtils.UploadObject(_ossClient, _bucketName, _objectKey, Config.UploadTestFile, new ObjectMetadata()); _objectETag = poResult.ETag; }
public static void ClassInitialize() { //get a OSS client object _ossClient = OssClientFactory.CreateOssClient(); //get current class name, which is prefix of bucket/object _className = TestContext.CurrentContext.Test.FullName; _className = _className.Substring(_className.LastIndexOf('.') + 1).ToLowerInvariant(); //create the bucket _bucketName = OssTestUtils.GetBucketName(_className); _ossClient.CreateBucket(_bucketName); //create sample object _keyName = OssTestUtils.GetObjectKey(_className); _keyName += ".jpg"; _process = "image/resize,m_fixed,w_100,h_100"; _localImageFile = Config.ImageTestFile; _processedKey = "process/image" + _keyName; _imageInfo = "{\n \"FileSize\": {\"value\": \"5470\"},\n \"Format\": {\"value\": \"jpg\"},\n \"ImageHeight\": {\"value\": \"100\"},\n \"ImageWidth\": {\"value\": \"100\"},\n \"ResolutionUnit\": {\"value\": \"1\"},\n \"XResolution\": {\"value\": \"1/1\"},\n \"YResolution\": {\"value\": \"1/1\"}}"; }
public void ProxyAuthInvalidTestWithDiffrentHttpClient() { var key = OssTestUtils.GetObjectKey(_className); try { IOss ossClient = OssClientFactory.CreateOssClientWithProxy(Config.Endpoint, Config.DisabledAccessKeyId, Config.DisabledAccessKeySecret, Config.ProxyHost, Int32.Parse(Config.ProxyPort) + 2, null, null); OssTestUtils.ObjectExists(ossClient, _bucketName, key); Assert.Fail("Object Exists should not pass when it was invalid authorization"); } catch (WebException e) { Assert.AreEqual(e.Status, WebExceptionStatus.ProtocolError); } }
public static void ClassInitialize() { //get a OSS client object _ossClient = OssClientFactory.CreateOssClient(); //get current class name, which is prefix of bucket/object _className = TestContext.CurrentContext.Test.FullName; _className = _className.Substring(_className.LastIndexOf('.') + 1).ToLowerInvariant(); //create the bucket _bucketName = OssTestUtils.GetBucketName(_className); _ossClient.CreateBucket(_bucketName); //upload sample object _objectKey = OssTestUtils.GetObjectKey(_className); //upload multipart sample object _bigObjectKey = _objectKey + ".js"; // temporary local file _tmpLocalFile = _className + ".tmp"; }
public static void ClassInitialize() { //get a OSS client object _ossClient = OssClientFactory.CreateOssClient(); //get current class name, which is prefix of bucket/object _className = TestContext.CurrentContext.Test.FullName; _className = _className.Substring(_className.LastIndexOf('.') + 1).ToLowerInvariant(); //create the bucket _bucketName = OssTestUtils.GetBucketName(_className); _ossClient.CreateBucket(_bucketName); //create sample object _keyName = OssTestUtils.GetObjectKey(_className); _sqlMessage = "name,school,company,age\r\n" + "Lora Francis,School A,Staples Inc,27\r\n" + "Eleanor Little,School B,\"Conectiv, Inc\",43\r\n" + "Rosie Hughes,School C,Western Gas Resources Inc,44\r\n" + "Lawrence Ross,School D,MetLife Inc.,24"; _jsonMessage = "{\n" + "\t\"name\": \"Lora Francis\",\n" + "\t\"age\": 27,\n" + "\t\"company\": \"Staples Inc\"\n" + "}\n" + "{\n" + "\t\"name\": \"Eleanor Little\",\n" + "\t\"age\": 43,\n" + "\t\"company\": \"Conectiv, Inc\"\n" + "}\n" + "{\n" + "\t\"name\": \"Rosie Hughes\",\n" + "\t\"age\": 44,\n" + "\t\"company\": \"Western Gas Resources Inc\"\n" + "}\n" + "{\n" + "\t\"name\": \"Lawrence Ross\",\n" + "\t\"age\": 24,\n" + "\t\"company\": \"MetLife Inc.\"\n" + "}"; _test_csv_file = Path.Combine(Config.DownloadFolder, "sample_data.csv"); _test_csv_gzip_file = Path.Combine(Config.DownloadFolder, "sample_data.csv.gz"); }
public static void ClassInitialize() { //get a OSS client object _ossClient = OssClientFactory.CreateOssClient(); //get current class name, which is prefix of bucket/object _className = TestContext.CurrentContext.Test.FullName; _className = _className.Substring(_className.LastIndexOf('.') + 1).ToLowerInvariant(); //create the bucket _bucketName = OssTestUtils.GetBucketName(_className); _ossClient.CreateBucket(_bucketName); //upload sample object _objectKey = OssTestUtils.GetObjectKey(_className); //upload multipart sample object _bigObjectKey = _objectKey + ".js"; // call paramters _callbackUrl = Config.CallbackServer; _callbackBody = "bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&my_var1=${x:var1}"; _callbackOkResponse = "{\"Status\":\"OK\"}"; }
public void PutObjectWithProcessTest() { IOss client = OssClientFactory.CreateOssClientEnableMD5(true); try { //just for code coverage using (Stream content = File.OpenRead(_localImageFile)) { var hashStream = new Common.Internal.MD5Stream(content, null, content.Length); var putRequest = new PutObjectRequest(_bucketName, _keyName, hashStream); putRequest.Process = _process; client.PutObject(putRequest); } // get processed image GetObjectRequest request = new GetObjectRequest(_bucketName, _keyName, _process); OssObject ossObject = client.GetObject(request); // put processed image Stream seekableStream = ConvertStreamToSeekable(ossObject.Content); client.PutObject(_bucketName, _processedKey, seekableStream); // get info of processed image var imgInfo = GetOssImageObjectInfo(_bucketName, _processedKey); // check processed result Assert.AreEqual(imgInfo, _imageInfo); } catch (OssException e) { Assert.AreEqual(OssErrorCode.InvalidArgument, e.ErrorCode); } finally { _ossClient.DeleteObject(_bucketName, _keyName); _ossClient.DeleteObject(_bucketName, _processedKey); } }
public void PutObjectWithPreSignedUriWithoutCrc() { var testStr = FileUtils.GenerateOneKb(); var bytes = Encoding.ASCII.GetBytes(testStr); var now = DateTime.Now; //set expiration time to 5 seconds later var expireDate = now.AddSeconds(5); var targetObject = OssTestUtils.GetObjectKey(_className); var uri = _ossClient.GeneratePresignedUri(_bucketName, targetObject, expireDate, SignHttpMethod.Put); try { Common.ClientConfiguration config = new Common.ClientConfiguration(); config.EnableCrcCheck = false; IOss ossClient = OssClientFactory.CreateOssClient(config); var putResult = ossClient.PutObject(uri, new MemoryStream(bytes)); Assert.AreEqual(putResult.HttpStatusCode, HttpStatusCode.OK); } catch (WebException ex) { Assert.Fail(ex.ToString()); } }
public void ResumableDownloadBigFileWithMd5CheckTest() { var targetFile = OssTestUtils.GetTargetFileName(_className); targetFile = Path.Combine(Config.DownloadFolder, targetFile); var key = OssTestUtils.GetObjectKey(_className); _ossClient.PutObject(_bucketName, key, Config.MultiUploadTestFile); var config = new ClientConfiguration(); config.EnalbeMD5Check = true; var client = OssClientFactory.CreateOssClient(config); try { DownloadObjectRequest request = new DownloadObjectRequest(_bucketName, key, targetFile); var metadata = client.ResumableDownloadObject(request); var expectedETag = metadata.ETag; var downloadedFileETag = FileUtils.ComputeContentMd5(targetFile); Assert.AreEqual(expectedETag.ToLowerInvariant(), downloadedFileETag.ToLowerInvariant()); } finally { try { FileUtils.DeleteFile(targetFile); } catch (Exception e) { LogUtility.LogWarning("Delete file {0} failed with Exception {1}", targetFile, e.Message); } _ossClient.DeleteObject(_bucketName, key); } }
protected virtual IOss GetOssClient(AliyunBlobProviderConfiguration aliyunConfig) { return(OssClientFactory.Create(aliyunConfig)); }
protected virtual IOss GetOssClient(BlobContainerConfiguration blobContainerConfiguration) { var aliyunConfig = blobContainerConfiguration.GetAliyunConfiguration(); return(OssClientFactory.Create(aliyunConfig)); }
private static void RunTest(string name, int numberOfConcurrency, int fileSize, bool isUniqueOssClient) { var allTasks = new List <Task>(); for (var i = 0; i < numberOfConcurrency; i++) { var fileName = string.Format("{0}_{1}", name, i); fileName = Path.Combine(Config.UploadSampleFolder, fileName); var task = Task.Factory.StartNew(() => FileUtils.PrepareSampleFile(fileName, fileSize)); allTasks.Add(task); } Task.WaitAll(allTasks.ToArray()); allTasks.Clear(); for (var i = 0; i < numberOfConcurrency; i++) { var fileName = string.Format("{0}_{1}", name, i); fileName = Path.Combine(Config.UploadSampleFolder, fileName); var index = i; var task = Task.Factory.StartNew(() => PutAndGetObject( isUniqueOssClient ? _ossClient : OssClientFactory.CreateOssClient(), fileName, index)); allTasks.Add(task); } Task.WaitAll(allTasks.ToArray()); }
public static void ClassCleanup() { var client = OssClientFactory.CreateOssClient(); OssTestUtils.CleanBucket(client, _bucketName); }
public void TestDisableCrc() { Common.ClientConfiguration config = new Common.ClientConfiguration(); config.EnableCrcCheck = false; IOss ossClient = OssClientFactory.CreateOssClient(config); var targetFile = OssTestUtils.GetTargetFileName(_className); targetFile = Path.Combine(Config.DownloadFolder, targetFile); var objectKeyName = "test-object-disable-crc"; try { // put & get PutObjectResult putObjectResult = ossClient.PutObject(_bucketName, objectKeyName, Config.UploadTestFile); var actualCrc = putObjectResult.ResponseMetadata[HttpHeaders.HashCrc64Ecma]; OssObject ossObject = ossClient.GetObject(_bucketName, objectKeyName); var expectedCrc = OssUtils.ComputeContentCrc64(ossObject.Content, ossObject.ContentLength); Assert.AreEqual(expectedCrc, actualCrc); ossClient.DeleteObject(_bucketName, objectKeyName); // put & get by uri var testStr = FileUtils.GenerateOneKb(); var content = Encoding.ASCII.GetBytes(testStr); var now = DateTime.Now; var expireDate = now.AddSeconds(120); var uri = _ossClient.GeneratePresignedUri(_bucketName, objectKeyName, expireDate, SignHttpMethod.Put); var putResult = ossClient.PutObject(uri, new MemoryStream(content)); expectedCrc = putResult.ResponseMetadata[HttpHeaders.HashCrc64Ecma]; actualCrc = OssUtils.ComputeContentCrc64(new MemoryStream(content), content.Length); Assert.AreEqual(expectedCrc, actualCrc); uri = _ossClient.GeneratePresignedUri(_bucketName, objectKeyName, expireDate, SignHttpMethod.Get); ossObject = ossClient.GetObject(uri); expectedCrc = OssUtils.ComputeContentCrc64(ossObject.Content, ossObject.ContentLength); Assert.AreEqual(expectedCrc, actualCrc); ossClient.DeleteObject(_bucketName, objectKeyName); // upload & download var uploadObjectResult = ossClient.ResumableUploadObject(_bucketName, objectKeyName, Config.MultiUploadTestFile, null, Config.DownloadFolder); actualCrc = uploadObjectResult.ResponseMetadata[HttpHeaders.HashCrc64Ecma]; DownloadObjectRequest downloadObjectRequest = new DownloadObjectRequest(_bucketName, objectKeyName, targetFile); var metadata = ossClient.ResumableDownloadObject(downloadObjectRequest); Assert.AreEqual(metadata.Crc64, actualCrc); ossClient.DeleteObject(_bucketName, objectKeyName); // append using (var fs = File.Open(Config.UploadTestFile, FileMode.Open)) { var fileLength = fs.Length; var appendObjectRequest = new AppendObjectRequest(_bucketName, objectKeyName) { Content = fs, }; var appendObjectResult = _ossClient.AppendObject(appendObjectRequest); fs.Seek(0, SeekOrigin.Begin); actualCrc = OssUtils.ComputeContentCrc64(fs, fs.Length); Assert.AreEqual(appendObjectResult.HashCrc64Ecma.ToString(), actualCrc); ossClient.DeleteObject(_bucketName, objectKeyName); } } finally { try { FileUtils.DeleteFile(targetFile); } catch (Exception e) { LogUtility.LogWarning("Delete file {0} failed with Exception {1}", targetFile, e.Message); } } }
public void MultipartUploadAbortInMiddleTest() { IOss client = OssClientFactory.CreateOssClientEnableMD5(true); var sourceFile = Config.MultiUploadTestFile; //get target object name var targetObjectKey = OssTestUtils.GetObjectKey(_className); var initRequest = new InitiateMultipartUploadRequest(_bucketName, targetObjectKey); var initResult = _ossClient.InitiateMultipartUpload(initRequest); // Set the part size const int partSize = 1024 * 1024 * 1; var partFile = new FileInfo(sourceFile); // Calculate the part count var partCount = OssTestUtils.CalculatePartCount(partFile.Length, partSize); Assert.IsTrue(partCount > 1, "Source file is too small to perform multipart upload"); LogUtility.LogMessage("File {0} is splitted to {1} parts for multipart upload", sourceFile, partCount); // Create a list to save result var partETags = new List <PartETag>(); //upload the file using (var fs = new FileStream(partFile.FullName, FileMode.Open)) { //use partCount - 1, so that the last part is left for (var i = 0; i < partCount - 1; i++) { // Skip to the start position long skipBytes = partSize * i; fs.Position = skipBytes; // calculate the part size var size = partSize < partFile.Length - skipBytes ? partSize : partFile.Length - skipBytes; // Create a UploadPartRequest, uploading parts var uploadPartRequest = new UploadPartRequest(_bucketName, targetObjectKey, initResult.UploadId); uploadPartRequest.InputStream = fs; uploadPartRequest.PartSize = size; uploadPartRequest.PartNumber = (i + 1); var uploadPartResult = client.UploadPart(uploadPartRequest); // Save the result partETags.Add(uploadPartResult.PartETag); //list parts which are uploaded var listPartsRequest = new ListPartsRequest(_bucketName, targetObjectKey, initResult.UploadId); listPartsRequest.EncodingType = null; var listPartsResult = _ossClient.ListParts(listPartsRequest); //there should be only 1 part was not uploaded Assert.AreEqual(i + 1, OssTestUtils.ToArray <Part>(listPartsResult.Parts).Count, "uploaded parts is not expected"); } } //abort the upload var abortRequest = new AbortMultipartUploadRequest(_bucketName, targetObjectKey, initResult.UploadId); _ossClient.AbortMultipartUpload(abortRequest); }