Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void ClearDatasetLabels_ExplicitPreconditionFail(bool runAsync)
        {
            var client    = BigQueryClient.Create(_fixture.ProjectId);
            var datasetId = _fixture.LabelsDatasetId;
            var dataset   = client.GetDataset(datasetId);

            var options = new ModifyLabelsOptions {
                ETag = "wrong-" + dataset.Resource.ETag
            };
            var exception = AssertThrowsMaybeAsync <GoogleApiException>(runAsync,
                                                                        () => client.ClearDatasetLabels(datasetId, options),
                                                                        () => client.ClearDatasetLabelsAsync(datasetId, options));

            Assert.Equal(HttpStatusCode.PreconditionFailed, exception.HttpStatusCode);
        }
Exemplo n.º 4
0
        public void NegativeRetries()
        {
            var options = new ModifyLabelsOptions();

            Assert.Throws <ArgumentOutOfRangeException>(() => options.Retries = -1);
        }