Example #1
0
        public void GetDataset_FailThenRetry()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetDatasetReference(projectId, datasetId);

            service.ExpectRequest(
                service.Datasets.Get(projectId, datasetId),
                HttpStatusCode.InternalServerError,
                new RequestError {
                Errors = new[] { new SingleError {
                                     Reason = "backendError"
                                 } }
            });
            service.ExpectRequest(
                service.Datasets.Get(projectId, datasetId),
                new Dataset {
                DatasetReference = reference
            });
            var result = client.GetDataset(reference);

            service.Verify();
            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(datasetId, result.Reference.DatasetId);
        }
Example #2
0
        public void UpdateDataset_NoRetryIfETagAbsent()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetDatasetReference(projectId, datasetId);
            var dataset   = new Dataset {
                FriendlyName = "Foo"
            };

            service.ExpectRequest(
                service.Datasets.Update(dataset, projectId, datasetId),
                HttpStatusCode.InternalServerError,
                new RequestError {
                Errors = new[] { new SingleError {
                                     Reason = "backendError"
                                 } }
            });
            // No second chance...
            var exception = Assert.Throws <GoogleApiException>(() => client.UpdateDataset(reference, dataset));

            Assert.Equal("backendError", exception.Error.Errors[0].Reason);
            service.Verify();
        }
Example #3
0
        public void UpdateDataset_RetryIfETagPresent()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetDatasetReference(projectId, datasetId);
            var dataset   = new Dataset {
                FriendlyName = "Foo", ETag = "\"etag\""
            };

            service.ExpectRequest(
                service.Datasets.Update(dataset, projectId, datasetId),
                HttpStatusCode.InternalServerError,
                new RequestError {
                Errors = new[] { new SingleError {
                                     Reason = "backendError"
                                 } }
            });
            service.ExpectRequest(
                service.Datasets.Update(dataset, projectId, datasetId),
                new Dataset {
                DatasetReference = reference
            });
            var result = client.UpdateDataset(reference, dataset);

            service.Verify();
            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(datasetId, result.Reference.DatasetId);
        }
Example #4
0
        public async Task DeleteDatasetAsync()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetDatasetReference(projectId, datasetId);

            service.ExpectRequest(
                service.Datasets.Delete(projectId, datasetId),
                "OK");
            await client.DeleteDatasetAsync(reference);
        }
Example #5
0
        public void GetDataset()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetDatasetReference(projectId, datasetId);

            service.ExpectRequest(
                service.Datasets.Get(projectId, datasetId),
                new Dataset {
                DatasetReference = reference
            });
            var result = client.GetDataset(reference);

            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(datasetId, result.Reference.DatasetId);
        }
Example #6
0
        public void GetDataset_NonRetriableFailure()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetDatasetReference(projectId, datasetId);

            service.ExpectRequest(
                service.Datasets.Get(projectId, datasetId),
                HttpStatusCode.BadRequest,
                new RequestError {
                Errors = new[] { new SingleError {
                                     Reason = "youCan'tRetryThis"
                                 } }
            });
            Assert.Throws <GoogleApiException>(() => client.GetDataset(reference));
            service.Verify();
        }
Example #7
0
        public async Task CreateDatasetAsync()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetDatasetReference(projectId, datasetId);

            service.ExpectRequest(
                service.Datasets.Insert(new Dataset {
                DatasetReference = reference
            }, projectId),
                new Dataset {
                DatasetReference = reference
            });
            var result = await client.CreateDatasetAsync(reference);

            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(datasetId, result.Reference.DatasetId);
        }
Example #8
0
        public async Task ListDatasetsAsync()
        {
            var projectId        = "project";
            var datasetId        = "dataset";
            var service          = new FakeBigqueryService();
            var client           = new BigQueryClientImpl(projectId, service);
            var projectReference = client.GetProjectReference(projectId);
            var datasetReference = client.GetDatasetReference(projectId, datasetId);

            service.ExpectRequest(
                service.Datasets.List(projectId),
                new DatasetList {
                Datasets = new[] { new DatasetsData {
                                       DatasetReference = datasetReference
                                   } }
            });
            var result  = client.ListDatasetsAsync(projectReference);
            var dataset = await result.Single();

            Assert.Equal(projectId, dataset.Reference.ProjectId);
            Assert.Equal(datasetId, dataset.Reference.DatasetId);
        }