示例#1
0
        public async Task MoreThanMaxKeys()
        {
            await CreateTempBucketAsync(async bucket =>
            {
                int concurrent     = 10;
                int count          = 1001;
                Queue <Task> tasks = new Queue <Task>(count);

                using (SemaphoreSlim semaphore = new SemaphoreSlim(concurrent))
                {
                    for (int i = 0; i < count; i++)
                    {
                        await semaphore.WaitAsync().ConfigureAwait(false);

                        string tempObjName = "object-" + Guid.NewGuid();
                        tasks.Enqueue(UploadString(bucket, tempObjName, semaphore));
                    }

                    await Task.WhenAll(tasks).ConfigureAwait(false);
                }

                GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket).ConfigureAwait(false);
                Assert.True(gResp.IsSuccess);
                Assert.Equal(1000, gResp.KeyCount);
                Assert.Equal(1000, gResp.Objects.Count);
                Assert.NotEmpty(gResp.NextContinuationToken);
                Assert.True(gResp.IsTruncated);
            }).ConfigureAwait(false);
        }
示例#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 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);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        public async Task DeleteBucket()
        {
            string tempBucketName = "testbucket-" + Guid.NewGuid();

            DeleteBucketResponse delete1 = await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false);

            Assert.False(delete1.IsSuccess);
            Assert.Equal(ErrorCode.NoSuchBucket, delete1.Error.Code);

            await BucketClient.PutBucketAsync(tempBucketName, request => request.Region = Config.Region).ConfigureAwait(false);

            DeleteBucketResponse delete2 = await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false);

            Assert.True(delete2.IsSuccess);
            Assert.Equal(204, delete2.StatusCode);

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

            Assert.False(resp.IsSuccess);
            Assert.Equal(404, resp.StatusCode);
        }