Пример #1
0
        public async Task RestoreWithSelect()
        {
            using (StringWriter sw = new StringWriter())
            {
                sw.WriteLine("name,age,status");
                sw.WriteLine("santa,800,missing");
                sw.WriteLine("\"donald trump\",7,present");
                sw.WriteLine("fantastic fox,31,missing");

                await ObjectClient.PutObjectStringAsync(BucketName, nameof(RestoreWithSelect), sw.ToString(), Encoding.UTF8, req => req.StorageClass = StorageClass.Glacier).ConfigureAwait(false);
            }

            RestoreObjectResponse restoreResp = await ObjectClient.RestoreObjectAsync(BucketName, nameof(RestoreWithSelect), req =>
            {
                req.RequestType = RestoreRequestType.Select;
                req.Description = "This is a description";
                req.RequestTier = RetrievalTier.Standard;

                S3CsvInputFormat inputFormat = new S3CsvInputFormat();
                inputFormat.HeaderUsage      = HeaderUsage.Use;

                S3CsvOutputFormat outputFormat = new S3CsvOutputFormat();
                req.SelectParameters           = new S3SelectParameters("SELECT * FROM object WHERE age > 7", inputFormat, outputFormat);

                req.OutputLocation = new S3OutputLocation(BucketName, "outputJob");
                req.OutputLocation.StorageClass = StorageClass.Standard;
            }).ConfigureAwait(false);

            Assert.Equal(202, restoreResp.StatusCode);

            //TODO: List objects beneath outputJob/* and GET file to determine if format is correct
        }
Пример #2
0
        public async Task GetWithPrefix()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                string tempObjName  = "object-" + Guid.NewGuid();
                string tempObjName2 = "something-" + Guid.NewGuid();

                await ObjectClient.PutObjectStringAsync(bucket, tempObjName, "hello").ConfigureAwait(false);
                await ObjectClient.PutObjectStringAsync(bucket, tempObjName2, "world!").ConfigureAwait(false);

                GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket, request => request.Prefix = "object").ConfigureAwait(false);
                Assert.True(gResp.IsSuccess);

                Assert.Equal(1, gResp.KeyCount);
                Assert.Equal(1, gResp.Objects.Count);

                Assert.Equal("object", gResp.Prefix);

                Assert.Equal(tempObjName, gResp.Objects[0].Name);
                Assert.Equal(DateTime.UtcNow, gResp.Objects[0].LastModified.DateTime, TimeSpan.FromSeconds(5));
                Assert.Equal("\"5d41402abc4b2a76b9719d911017c592\"", gResp.Objects[0].ETag);
                Assert.Equal(5, gResp.Objects[0].Size);
                Assert.Equal(StorageClass.Standard, gResp.Objects[0].StorageClass);
            }).ConfigureAwait(false);
        }
Пример #3
0
        public async Task PutObjectInvalidCharacters(string name)
        {
            //These 2 test cases came after an exhaustive search in the whole UTF-16 character space.

            PutObjectResponse resp = await ObjectClient.PutObjectStringAsync(BucketName, name, string.Empty).ConfigureAwait(false);

            Assert.False(resp.IsSuccess);
        }
Пример #4
0
        public async Task Range()
        {
            await ObjectClient.PutObjectStringAsync(BucketName, nameof(Range), "123456789012345678901234567890123456789012345678901234567890").ConfigureAwait(false);

            GetObjectResponse resp = await ObjectClient.GetObjectAsync(BucketName, nameof(Range), request => request.Range.Add(0, 10)).ConfigureAwait(false);

            Assert.Equal(206, resp.StatusCode);
            Assert.Equal(11, resp.ContentLength);
        }
Пример #5
0
 public async Task PutObjectTooManyTags()
 {
     await Assert.ThrowsAsync <Exception>(async() => await ObjectClient.PutObjectStringAsync(BucketName, nameof(PutObjectTooManyTags), "data", null, request =>
     {
         for (int i = 0; i < 51; i++)
         {
             request.Tags.Add(i.ToString(NumberFormatInfo.InvariantInfo), i.ToString(NumberFormatInfo.InvariantInfo));
         }
     }).ConfigureAwait(false)).ConfigureAwait(false);
 }
Пример #6
0
        public async Task PutObjectValidCharacters(string name)
        {
            PutObjectResponse putResp = await ObjectClient.PutObjectStringAsync(BucketName, name, string.Empty).ConfigureAwait(false);

            Assert.True(putResp.IsSuccess);

            GetObjectResponse getResp = await ObjectClient.GetObjectAsync(BucketName, name).ConfigureAwait(false);

            Assert.True(getResp.IsSuccess);
        }
Пример #7
0
        public async Task NameTests(string name)
        {
            await ObjectClient.PutObjectStringAsync(BucketName, name, name).ConfigureAwait(false);

            GetObjectResponse dlResp = await ObjectClient.GetObjectAsync(BucketName, name).ConfigureAwait(false);

            Assert.Equal("binary/octet-stream", dlResp.ContentType);
            Assert.Equal(name.Length, dlResp.ContentLength);

            Assert.Equal(name, Encoding.UTF8.GetString(await dlResp.Content.AsDataAsync().ConfigureAwait(false)));
        }
Пример #8
0
 private async Task UploadString(string bucketName, string objName, SemaphoreSlim semaphore)
 {
     try
     {
         await ObjectClient.PutObjectStringAsync(bucketName, objName, string.Empty).ConfigureAwait(false);
     }
     finally
     {
         semaphore.Release();
     }
 }
Пример #9
0
        public async Task RangeFluid()
        {
            await ObjectClient.PutObjectStringAsync(BucketName, nameof(RangeFluid), "123456789012345678901234567890123456789012345678901234567890").ConfigureAwait(false);

            GetObjectResponse resp = await Transfer.Download(BucketName, nameof(RangeFluid))
                                     .WithRange(0, 10)
                                     .ExecuteAsync()
                                     .ConfigureAwait(false);

            Assert.Equal(206, resp.StatusCode);
            Assert.Equal(11, resp.ContentLength);
        }
Пример #10
0
        public async Task PutAndGet()
        {
            string tempBucketName = "testbucket-" + Guid.NewGuid();

            PutBucketResponse pResp = await BucketClient.PutBucketAsync(tempBucketName, request =>
            {
                request.Region = Config.Region;
                request.Acl    = BucketCannedAcl.Private;
            }).ConfigureAwait(false);

            Assert.True(pResp.IsSuccess);

            //We prefix with a number here to keep sort order when we download the list of objects further down
            string tempObjName  = "object-1" + Guid.NewGuid();
            string tempObjName2 = "object-2" + Guid.NewGuid();

            await ObjectClient.PutObjectStringAsync(tempBucketName, tempObjName, "hello").ConfigureAwait(false);

            await ObjectClient.PutObjectStringAsync(tempBucketName, tempObjName2, "world!", null, request => request.StorageClass = StorageClass.OneZoneIa).ConfigureAwait(false);

            GetBucketResponse gResp = await BucketClient.GetBucketAsync(tempBucketName).ConfigureAwait(false);

            Assert.True(gResp.IsSuccess);

            Assert.Equal(2, gResp.KeyCount);
            Assert.Equal(2, gResp.Objects.Count);
            Assert.Equal(string.Empty, gResp.Prefix);

            Assert.Equal(tempObjName, gResp.Objects[0].Name);
            Assert.Equal(DateTime.UtcNow, gResp.Objects[0].LastModified.DateTime, TimeSpan.FromSeconds(5));
            Assert.Equal("\"5d41402abc4b2a76b9719d911017c592\"", gResp.Objects[0].ETag);
            Assert.Equal(5, gResp.Objects[0].Size);
            Assert.Equal(StorageClass.Standard, gResp.Objects[0].StorageClass);

            Assert.Equal(tempObjName2, gResp.Objects[1].Name);
            Assert.Equal(DateTime.UtcNow, gResp.Objects[1].LastModified.DateTime, TimeSpan.FromSeconds(5));
            Assert.Equal("\"08cf82251c975a5e9734699fadf5e9c0\"", gResp.Objects[1].ETag);
            Assert.Equal(6, gResp.Objects[1].Size);
            Assert.Equal(StorageClass.OneZoneIa, gResp.Objects[1].StorageClass);

            GetBucketResponse gResp2 = await BucketClient.GetBucketAsync(tempBucketName, request => request.EncodingType = EncodingType.Url).ConfigureAwait(false);

            Assert.True(gResp2.IsSuccess);
            Assert.Equal(2, gResp2.KeyCount);

            //The keys should be URL encoded at this point
            Assert.Equal(UrlHelper.UrlEncode(tempObjName), gResp.Objects[0].Name);
            Assert.Equal(UrlHelper.UrlEncode(tempObjName2), gResp.Objects[1].Name);
        }
Пример #11
0
        protected async Task <PutObjectResponse> UploadAsync(string bucketName, string objectKey, Action <PutObjectRequest>?config = null, bool assumeSuccess = true)
        {
            PutObjectResponse resp = await ObjectClient.PutObjectStringAsync(bucketName, objectKey, "test", Encoding.UTF8, config).ConfigureAwait(false);

            if (assumeSuccess)
            {
                Assert.True(resp.IsSuccess);
            }
            else
            {
                Assert.False(resp.IsSuccess);
            }

            return(resp);
        }
Пример #12
0
        public async Task DownloadContentRange()
        {
            await ObjectClient.PutObjectStringAsync(BucketName, nameof(DownloadContentRange), "123456789012345678901234567890123456789012345678901234567890").ConfigureAwait(false);

            GetObjectResponse resp = await Transfer.CreateDownload(BucketName, nameof(DownloadContentRange))
                                     .WithRange(0, 10)
                                     .DownloadAsync()
                                     .ConfigureAwait(false);

            Assert.Equal(206, resp.StatusCode);
            Assert.Equal(11, resp.ContentLength);
            Assert.Equal("bytes", resp.AcceptRanges);
            Assert.Equal("bytes 0-10/60", resp.ContentRange);
            Assert.Equal("12345678901", await resp.Content.AsStringAsync().ConfigureAwait(false));
        }
Пример #13
0
        public async Task ListObjectsWithOwner()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                string tempObjName = "object-" + Guid.NewGuid();
                await ObjectClient.PutObjectStringAsync(bucket, tempObjName, "hello", config: req => req.AclGrantFullControl.AddEmail(TestConstants.TestEmail)).ConfigureAwait(false);

                ListObjectsResponse resp = await ObjectClient.ListObjectsAsync(bucket, req => req.FetchOwner = true).ConfigureAwait(false);
                Assert.True(resp.IsSuccess);

                S3Object obj = resp.Objects.First();
                Assert.Equal(TestConstants.TestUsername, obj.Owner.Name);
                Assert.Equal(TestConstants.TestUserId, obj.Owner.Id);
            }).ConfigureAwait(false);
        }
Пример #14
0
        public async Task GetWithOwner()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                string tempObjName = "object-" + Guid.NewGuid();
                await ObjectClient.PutObjectStringAsync(bucket, tempObjName, string.Empty, config: request => request.AclGrantFullControl.AddEmail(TestConstants.TestEmail)).ConfigureAwait(false);

                GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket, request => request.FetchOwner = true).ConfigureAwait(false);
                Assert.True(gResp.IsSuccess);
                Assert.Equal(1, gResp.KeyCount);

                S3Object obj = gResp.Objects.First();
                Assert.Equal(TestConstants.TestUsername, obj.Owner.Name);
                Assert.Equal(TestConstants.TestUserId, obj.Owner.Id);
            }).ConfigureAwait(false);
        }
Пример #15
0
        public async Task ListObjectsWithEncoding()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                string tempObjName = "!#/()";

                await ObjectClient.PutObjectStringAsync(bucket, tempObjName, string.Empty).ConfigureAwait(false);

                ListObjectsResponse resp = await ObjectClient.ListObjectsAsync(bucket, req => req.EncodingType = EncodingType.Url).ConfigureAwait(false);
                Assert.True(resp.IsSuccess);

                Assert.Equal(EncodingType.Url, resp.EncodingType);

                S3Object obj = Assert.Single(resp.Objects);

                Assert.Equal("%21%23/%28%29", obj.ObjectKey);
            }).ConfigureAwait(false);
        }
Пример #16
0
        public async Task GetWithDelimiter()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                string tempObjName  = "object-" + Guid.NewGuid();
                string tempObjName2 = "something-" + Guid.NewGuid();

                await ObjectClient.PutObjectStringAsync(bucket, tempObjName, "hello").ConfigureAwait(false);
                await ObjectClient.PutObjectStringAsync(bucket, tempObjName2, "world!").ConfigureAwait(false);

                GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket, request => request.Delimiter = "-").ConfigureAwait(false);
                Assert.True(gResp.IsSuccess);

                Assert.Equal(2, gResp.KeyCount);
                Assert.Equal(2, gResp.CommonPrefixes.Count);
                Assert.Equal("object-", gResp.CommonPrefixes[0]);
                Assert.Equal("something-", gResp.CommonPrefixes[1]);
            }).ConfigureAwait(false);
        }
Пример #17
0
        public async Task ListObjectsWithPrefix()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                string tempObjName  = "object-" + Guid.NewGuid();
                string tempObjName2 = "something-" + Guid.NewGuid();

                await ObjectClient.PutObjectStringAsync(bucket, tempObjName, "hello").ConfigureAwait(false);
                await ObjectClient.PutObjectStringAsync(bucket, tempObjName2, "world!").ConfigureAwait(false);

                ListObjectsResponse resp = await ObjectClient.ListObjectsAsync(bucket, req => req.Prefix = "object").ConfigureAwait(false);
                Assert.True(resp.IsSuccess);

                Assert.Equal(1, resp.KeyCount);
                Assert.Equal("object", resp.Prefix);

                S3Object obj = Assert.Single(resp.Objects);

                Assert.Equal(tempObjName, obj.ObjectKey);
            }).ConfigureAwait(false);
        }
Пример #18
0
        public async Task ListObjects()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                string tempObjName = "object-" + Guid.NewGuid();
                await ObjectClient.PutObjectStringAsync(bucket, tempObjName, "hello").ConfigureAwait(false);

                ListObjectsResponse gResp = await ObjectClient.ListObjectsAsync(bucket).ConfigureAwait(false);
                Assert.True(gResp.IsSuccess);

                Assert.Equal(bucket, gResp.BucketName);
                Assert.Equal(1, gResp.KeyCount);
                Assert.Equal(1000, gResp.MaxKeys);
                Assert.False(gResp.IsTruncated);

                S3Object obj = gResp.Objects.First();
                Assert.Equal(tempObjName, obj.ObjectKey);
                Assert.Equal("\"5d41402abc4b2a76b9719d911017c592\"", obj.ETag);
                Assert.Equal(StorageClass.Standard, obj.StorageClass);
                Assert.Equal(5, obj.Size);
                Assert.Equal(DateTime.UtcNow, obj.LastModifiedOn.UtcDateTime, TimeSpan.FromSeconds(5));
            }).ConfigureAwait(false);
        }