Beispiel #1
0
        private void DeleteFromS3(S3Settings settings)
        {
            using (var client = new RavenAwsS3Client(settings, _settings.Configuration, progress: null, TaskCancelToken.Token))
            {
                var key = CombinePathAndKey(settings.RemoteFolderName);
                client.DeleteObject(key);

                if (_logger.IsInfoEnabled)
                {
                    _logger.Info($"{ReportDeletion(S3Name)} bucket named: {settings.BucketName}, with key: {key}");
                }
            }
        }
Beispiel #2
0
        public async Task put_object(string region)
        {
            var bucketName = $"testing-{Guid.NewGuid()}";
            var key        = $"test-key-{Guid.NewGuid()}";

            using (var client = new RavenAwsS3Client(AwsAccessKey, AwsSecretKey, region, bucketName))
            {
                // make sure that the bucket doesn't exist
                await client.DeleteBucket();

                try
                {
                    await client.PutBucket();

                    var value1 = Guid.NewGuid().ToString();
                    var value2 = Guid.NewGuid().ToString();
                    await client.PutObject(key, new MemoryStream(Encoding.UTF8.GetBytes("231")), new Dictionary <string, string>
                    {
                        { "property1", value1 },
                        { "property2", value2 }
                    });

                    // can't delete a bucket with existing objects
                    var e = await Assert.ThrowsAsync <StorageException>(async() => await client.DeleteBucket());

                    Assert.True(e.Message.Contains("The bucket you tried to delete is not empty"));

                    var @object = await client.GetObject(key);

                    Assert.NotNull(@object);

                    using (var reader = new StreamReader(@object.Data))
                        Assert.Equal("231", reader.ReadToEnd());

                    var property1 = @object.Metadata.Keys.Single(x => x.Contains("property1"));
                    var property2 = @object.Metadata.Keys.Single(x => x.Contains("property2"));

                    Assert.Equal(value1, @object.Metadata[property1]);
                    Assert.Equal(value2, @object.Metadata[property2]);
                }
                finally
                {
                    await client.DeleteObject(key);

                    await client.DeleteBucket();
                }
            }
        }
Beispiel #3
0
        // ReSharper disable once InconsistentNaming
        private static async Task PutObject(string region,
                                            int sizeInMB, bool testBlobKeyAsFolder, UploadType uploadType)
        {
            var bucketName = $"testing-{Guid.NewGuid()}";
            var key        = testBlobKeyAsFolder == false?
                             Guid.NewGuid().ToString() :
                                 $"{Guid.NewGuid()}/folder/testKey";

            var uploadProgress = new UploadProgress();
            var maxUploadPutObjectInBytesSetter        = ExpressionHelper.CreateFieldSetter <RavenAwsS3Client, int>("MaxUploadPutObjectSizeInBytes");
            var minOnePartUploadSizeLimitInBytesSetter = ExpressionHelper.CreateFieldSetter <RavenAwsS3Client, int>("MinOnePartUploadSizeLimitInBytes");

            using (var client = new RavenAwsS3Client(AwsAccessKey, AwsSecretKey, region, bucketName, uploadProgress))
            {
                maxUploadPutObjectInBytesSetter(client, 10 * 1024 * 1024);       // 10MB
                minOnePartUploadSizeLimitInBytesSetter(client, 7 * 1024 * 1024); // 7MB

                // make sure that the bucket doesn't exist
                await client.DeleteBucket();

                try
                {
                    await client.PutBucket();

                    var value1 = Guid.NewGuid().ToString();
                    var value2 = Guid.NewGuid().ToString();

                    var sb = new StringBuilder();
                    for (var i = 0; i < sizeInMB * 1024 * 1024; i++)
                    {
                        sb.Append("a");
                    }

                    long streamLength;
                    using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
                    {
                        streamLength = memoryStream.Length;
                        await client.PutObject(key,
                                               memoryStream,
                                               new Dictionary <string, string>
                        {
                            { "property1", value1 },
                            { "property2", value2 }
                        });
                    }

                    var @object = await client.GetObject(key);

                    Assert.NotNull(@object);

                    using (var reader = new StreamReader(@object.Data))
                        Assert.Equal(sb.ToString(), reader.ReadToEnd());

                    var property1 = @object.Metadata.Keys.Single(x => x.Contains("property1"));
                    var property2 = @object.Metadata.Keys.Single(x => x.Contains("property2"));

                    Assert.Equal(value1, @object.Metadata[property1]);
                    Assert.Equal(value2, @object.Metadata[property2]);

                    Assert.Equal(UploadState.Done, uploadProgress.UploadState);
                    Assert.Equal(uploadType, uploadProgress.UploadType);
                    Assert.Equal(streamLength, uploadProgress.TotalInBytes);
                    Assert.Equal(streamLength, uploadProgress.UploadedInBytes);
                }
                finally
                {
                    await client.DeleteObject(key);

                    await client.DeleteBucket();
                }
            }
        }