public void ClearDatasetLabels_RetrySucceeds(bool runAsync) { var evilClient = BigQueryClient.Create(_fixture.ProjectId); var independentClient = BigQueryClient.Create(_fixture.ProjectId); var datasetId = _fixture.LabelsDatasetId; _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.SetDatasetLabel(datasetId, "label", $"intercept{count}")); evilClient.Service.HttpClient.MessageHandler.AddExecuteInterceptor(interceptor); var options = new ModifyLabelsOptions { Retries = 2 }; var result = RunMaybeAsync(runAsync, () => evilClient.ClearDatasetLabels(datasetId, options), () => evilClient.ClearDatasetLabelsAsync(datasetId, options)); Assert.Equal(new Dictionary <string, string> { { "label", "intercept2" } }, result); Assert.Null(independentClient.GetDataset(datasetId).Resource.Labels); }
public void ClearDatasetLabels_RetryFails(bool runAsync) { var evilClient = BigQueryClient.Create(_fixture.ProjectId); var independentClient = BigQueryClient.Create(_fixture.ProjectId); var datasetId = _fixture.LabelsDatasetId; _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.SetDatasetLabel(datasetId, "label", $"intercept{count}")); evilClient.Service.HttpClient.MessageHandler.AddExecuteInterceptor(interceptor); var options = new ModifyLabelsOptions { Retries = 2 }; var exception = AssertThrowsMaybeAsync <GoogleApiException>(runAsync, () => evilClient.ClearDatasetLabels(datasetId, options), () => evilClient.ClearDatasetLabelsAsync(datasetId, options)); Assert.Equal(HttpStatusCode.PreconditionFailed, exception.HttpStatusCode); }
public void ModifyBucketLabels_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.SetBucketLabel(bucketName, "label", "after", options), () => evilClient.SetBucketLabelAsync(bucketName, "label", "after", options)); Assert.Equal("intercept2", result); var finalLabels = independentClient.GetBucket(bucketName).Labels; Assert.Equal("after", finalLabels["label"]); }