Exemplo n.º 1
0
        public void CreateBucketAndObjects()
        {
            // Note: this test may fail if the project location prevents multi-regional storage.
            string initialBucketStorageClass = StorageClasses.Standard;
            string updatedObjectStorageClass = StorageClasses.Coldline;
            string updatedBucketStorageClass = StorageClasses.Nearline;

            string bucketName = _fixture.BucketPrefix + "storage-classes";
            string objectName = IdGenerator.FromGuid();
            var    client     = _fixture.Client;

            client.CreateBucket(_fixture.ProjectId, new Bucket {
                Name = bucketName, StorageClass = initialBucketStorageClass
            });
            StorageFixture.SleepAfterBucketCreateDelete();
            _fixture.RegisterBucketToDelete(bucketName);

            var bucket = client.GetBucket(bucketName);

            Assert.Equal(initialBucketStorageClass, bucket.StorageClass);

            var obj = client.UploadObject(bucketName, objectName, "application/octet-stream", TestHelpers.GenerateData(100));

            Assert.Equal(initialBucketStorageClass, obj.StorageClass);

            // Change storage class via a rewrite
            var options = new CopyObjectOptions
            {
                ExtraMetadata = new Object {
                    StorageClass = updatedObjectStorageClass
                }
            };

            client.CopyObject(bucketName, objectName, bucketName, objectName, options);

            // Fetch separately rather than trusting the return value of CopyObject...
            obj = client.GetObject(bucketName, objectName);
            Assert.Equal(updatedObjectStorageClass, obj.StorageClass);

            bucket.StorageClass = updatedBucketStorageClass;
            client.UpdateBucket(bucket);
            // Wait for 10 seconds to allow the bucket changes to take effect. While a lot of the time
            // the change is effective immediately, this pause just makes things more reliably - and is pretty reasonable
            // given the distributed nature of the system.
            Thread.Sleep(TimeSpan.FromSeconds(10));

            string objectName2 = IdGenerator.FromGuid();

            var obj2 = client.UploadObject(bucketName, objectName2, "application/octet-stream", TestHelpers.GenerateData(100));

            Assert.Equal(updatedBucketStorageClass, obj2.StorageClass);
        }
Exemplo n.º 2
0
            public Task InterceptAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            {
                if (request.Method.Method == "PATCH" && interceptCount < maxIntercepts)
                {
                    interceptCount++;

                    FileLogger.Log($"Starting patching from interceptor {bucketName} by {callerName}.");
                    action(interceptCount);
                    FileLogger.Log($"Finished patching from interceptor {bucketName} by {callerName}.");

                    // Sleep, as everything in this test modifies buckets, and we can't do that very frequently.
                    StorageFixture.SleepAfterBucketCreateDelete();
                }
                return(Task.FromResult(0));
            }
Exemplo n.º 3
0
        private T RunMaybeAsync <T>(bool runAsync, Func <T> sync, Func <Task <T> > async, [CallerMemberName] string callerName = null)
        {
            // This is the bucket used in all of these tests.
            var bucketName = _fixture.LabelsTestBucket;

            FileLogger.Log($"Starting {(runAsync ? "async" : "sync")}-modifying {bucketName} by {callerName}.");
            // Run the async func separately to explicitly avoid synchronization etc.
            var result = runAsync? Task.Run(() => async().Result).Result : sync();

            FileLogger.Log($"Finished {(runAsync ? "async" : "sync")}-modifying {bucketName} by {callerName}.");

            // Sleep, as everything in this test modifies buckets, and we can't do that very frequently.
            StorageFixture.SleepAfterBucketCreateDelete();
            return(result);
        }
Exemplo n.º 4
0
        public void CreateBucketWithStorageClass(string storageClass)
        {
            string bucketName = $"{_fixture.BucketPrefix}-with-class-{storageClass.ToLowerInvariant()}";
            var    client     = _fixture.Client;

            var bucket = client.CreateBucket(_fixture.ProjectId, new Bucket {
                Name = bucketName, StorageClass = storageClass
            });

            StorageFixture.SleepAfterBucketCreateDelete();
            _fixture.RegisterBucketToDelete(bucketName);

            Assert.Equal(storageClass, bucket.StorageClass);
            bucket = client.GetBucket(bucketName);
            Assert.Equal(storageClass, bucket.StorageClass);
        }
        public void CreateBucketAndObjects()
        {
            // Note: this test may fail if the project location prevents multi-regional storage.
            string initialBucketStorageClass = StorageClasses.MultiRegional;
            string updatedObjectStorageClass = StorageClasses.Coldline;
            string updatedBucketStorageClass = StorageClasses.Nearline;

            string bucketName = _fixture.BucketPrefix + "storage-classes";
            string objectName = IdGenerator.FromGuid();
            var    client     = _fixture.Client;

            client.CreateBucket(_fixture.ProjectId, new Bucket {
                Name = bucketName, StorageClass = initialBucketStorageClass
            });
            StorageFixture.SleepAfterBucketCreateDelete();
            _fixture.RegisterBucketToDelete(bucketName);

            var bucket = client.GetBucket(bucketName);

            Assert.Equal(initialBucketStorageClass, bucket.StorageClass);

            var obj = client.UploadObject(bucketName, objectName, "application/octet-stream", TestHelpers.GenerateData(100));

            Assert.Equal(initialBucketStorageClass, obj.StorageClass);

            // Change storage class via a rewrite
            var options = new CopyObjectOptions
            {
                ExtraMetadata = new Object {
                    StorageClass = updatedObjectStorageClass
                }
            };

            client.CopyObject(bucketName, objectName, bucketName, objectName, options);

            // Fetch separately rather than trusting the return value of CopyObject...
            obj = client.GetObject(bucketName, objectName);
            Assert.Equal(updatedObjectStorageClass, obj.StorageClass);

            bucket.StorageClass = updatedBucketStorageClass;
            client.UpdateBucket(bucket);
            string objectName2 = IdGenerator.FromGuid();

            var obj2 = client.UploadObject(bucketName, objectName2, "application/octet-stream", TestHelpers.GenerateData(100));

            Assert.Equal(updatedBucketStorageClass, obj2.StorageClass);
        }