public void ClearBucketLabels_RetryFails(bool runAsync) { var evilClient = StorageClient.Create(); var independentClient = StorageClient.Create(); var bucketName = _fixture.LabelsTestBucket; _fixture.SetUpLabels(new Dictionary <string, string> { { "label", "before" } }); // Just before the "set-it-to-after" patch call is made, we modify the label ourselves, // which will change the metageneration and cause a conflict response to the patch. // We do this three times - which is why the overall result is failure. var interceptor = new PatchFoilingInterceptor(3, count => independentClient.SetBucketLabel(bucketName, "label", $"intercept{count}")); evilClient.Service.HttpClient.MessageHandler.AddExecuteInterceptor(interceptor); var options = new ModifyBucketLabelsOptions { Retries = 2 }; var exception = AssertThrowsMaybeAsync <GoogleApiException>(runAsync, () => evilClient.ClearBucketLabels(bucketName, options), () => evilClient.ClearBucketLabelsAsync(bucketName, options)); Assert.Equal(HttpStatusCode.PreconditionFailed, exception.HttpStatusCode); }
public void ClearBucketLabels_RetrySucceeds(bool runAsync) { var evilClient = StorageClient.Create(); var independentClient = StorageClient.Create(); var bucketName = _fixture.LabelsTestBucket; _fixture.SetUpLabels(new Dictionary <string, string> { { "label", "before" } }); // Just before the "set-it-to-after" patch call is made, we modify the label ourselves, // which will change the metageneration and cause a conflict response to the patch. // We only do this twice though - on the third time, the read/modify/write cycle will work // - but we'll be able to tell that it *did* intercept twice, as the "old" value will be // the one set by the final intercept. var interceptor = new PatchFoilingInterceptor(2, count => independentClient.SetBucketLabel(bucketName, "label", $"intercept{count}")); evilClient.Service.HttpClient.MessageHandler.AddExecuteInterceptor(interceptor); var options = new ModifyBucketLabelsOptions { Retries = 2 }; var result = RunMaybeAsync(runAsync, () => evilClient.ClearBucketLabels(bucketName, options), () => evilClient.ClearBucketLabelsAsync(bucketName, options)); Assert.Equal(new Dictionary <string, string> { { "label", "intercept2" } }, result); Assert.Null(independentClient.GetBucket(bucketName).Labels); }
public void Retries_Valid(int?retries) { var options = new ModifyBucketLabelsOptions { Retries = retries }; Assert.Equal(retries, options.Retries); }
public void ClearBucketLabels_ExplicitPreconditionFail(bool runAsync) { var client = _fixture.Client; var bucketName = _fixture.LabelsTestBucket; var bucket = client.GetBucket(bucketName); var options = new ModifyBucketLabelsOptions { IfMetagenerationMatch = bucket.Metageneration + 1 }; var exception = AssertThrowsMaybeAsync <GoogleApiException>(runAsync, () => client.ClearBucketLabels(bucketName, options), () => client.ClearBucketLabelsAsync(bucketName, options)); Assert.Equal(HttpStatusCode.PreconditionFailed, exception.HttpStatusCode); }
public void RemoveLabel() { var bucketName = "bucket"; var key = "key"; var options = new ModifyBucketLabelsOptions(); var mock = new Mock <StorageClient> { CallBase = true }; mock.Setup(obj => obj.ModifyBucketLabels(bucketName, new Dictionary <string, string> { { key, null } }, options)) .Returns(new Dictionary <string, string> { { key, null } }); var actual = mock.Object.RemoveBucketLabel(bucketName, key, options); Assert.Null(actual); mock.VerifyAll(); }
public void RemoveLabelAsync() { var bucketName = "bucket"; var key = "key"; var options = new ModifyBucketLabelsOptions(); var token = new CancellationTokenSource().Token; var mock = new Mock <StorageClient> { CallBase = true }; mock.Setup(obj => obj.ModifyBucketLabelsAsync(bucketName, new Dictionary <string, string> { { "key", null } }, options, token)) .Returns(Task.FromResult <IDictionary <string, string> >(new Dictionary <string, string> { { "key", null } })); var actual = mock.Object.RemoveBucketLabelAsync(bucketName, key, options, token).Result; Assert.Null(actual); mock.VerifyAll(); }
public void SetLabel() { var bucketName = "bucket"; var key = "key"; var oldValue = "old-value"; var newValue = "new-value"; var options = new ModifyBucketLabelsOptions(); var mock = new Mock <StorageClient> { CallBase = true }; mock.Setup(obj => obj.ModifyBucketLabels(bucketName, new Dictionary <string, string> { { key, newValue } }, options)) .Returns(new Dictionary <string, string> { { key, oldValue } }); var actual = mock.Object.SetBucketLabel(bucketName, key, newValue, options); Assert.Equal(oldValue, actual); mock.VerifyAll(); }
public void Retries_Invalid(int?retries) { var options = new ModifyBucketLabelsOptions(); Assert.Throws <ArgumentOutOfRangeException>(() => options.Retries = retries); }