示例#1
0
        public async Task CreateTableAsync()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var tableId = "table";
            var service = new FakeBigqueryService();
            var client = new BigQueryClientImpl(projectId, service);
            var reference = client.GetTableReference(projectId, datasetId, tableId);
            var schema = new TableSchemaBuilder {
                { "column", BigQueryDbType.Int64 }
            }.Build();

            service.ExpectRequest(
                service.Tables.Insert(new Table {
                TableReference = reference, Schema = schema
            }, projectId, datasetId),
                new Table {
                TableReference = reference, Schema = schema
            });
            var result = await client.CreateTableAsync(reference, schema);

            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(datasetId, result.Reference.DatasetId);
            Assert.Equal(tableId, result.Reference.TableId);
            Assert.Equal("column", result.Schema.Fields[0].Name);
        }
示例#2
0
 public async Task InsertRowsAsync_NoRows_NoOp()
 {
     // We don't set up any expected requests, so if the client issues any, the test will fail.
     var service = new FakeBigqueryService();
     var client  = new BigQueryClientImpl("project", service);
     await client.InsertRowsAsync("dataset", "table", new BigQueryInsertRow[0]);
 }
示例#3
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();
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        private Job CreateJobWithSampleConfiguration(JobCreationOptions options)
        {
            var projectId = "project";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);

            return(client.CreateJob(new JobConfiguration(), options));
        }
示例#7
0
        public void WithDefaultLocation()
        {
            var projectId = "project";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service).WithDefaultLocation("us");

            Assert.Same(projectId, client.ProjectId);
            Assert.Same(service, client.Service);
            Assert.Equal("us", client.DefaultLocation);
        }
示例#8
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);
        }
示例#9
0
        public void DeleteTable()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var tableId   = "table";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetTableReference(projectId, datasetId, tableId);

            service.ExpectRequest(
                service.Tables.Delete(projectId, datasetId, tableId),
                "OK");
            client.DeleteTable(reference);
        }
示例#10
0
        public async Task GetJobAsync()
        {
            var projectId = "project";
            var jobId     = "job";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetJobReference(projectId, jobId);

            service.ExpectRequest(
                service.Jobs.Get(projectId, jobId),
                new Job {
                JobReference = reference
            });
            var result = await client.GetJobAsync(reference);

            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(jobId, result.Reference.JobId);
        }
示例#11
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);
        }
示例#12
0
        public async Task ListProjectsAsyncAsync()
        {
            var projectId = "project";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetProjectReference(projectId);

            service.ExpectRequest(
                service.Projects.List(),
                new ProjectList {
                Projects = new[] { new ProjectsData {
                                       ProjectReference = reference
                                   } }
            });
            var result  = client.ListProjectsAsync();
            var dataset = await result.Single();

            Assert.Equal(projectId, dataset.Reference.ProjectId);
        }
示例#13
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();
        }
示例#14
0
        public async Task GetTableAsync()
        {
            var projectId = "project";
            var datasetId = "dataset";
            var tableId   = "table";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetTableReference(projectId, datasetId, tableId);

            service.ExpectRequest(
                service.Tables.Get(projectId, datasetId, tableId),
                new Table {
                TableReference = reference
            });
            var result = await client.GetTableAsync(reference);

            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(datasetId, result.Reference.DatasetId);
            Assert.Equal(tableId, result.Reference.TableId);
        }
示例#15
0
        public void CancelJob()
        {
            var projectId = "project";
            var jobId     = "job";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);
            var reference = client.GetJobReference(projectId, jobId);

            service.ExpectRequest(
                service.Jobs.Cancel(projectId, jobId),
                new JobCancelResponse {
                Job = new Job {
                    JobReference = reference
                }
            });
            var result = client.CancelJob(reference);

            Assert.Equal(projectId, result.Reference.ProjectId);
            Assert.Equal(jobId, result.Reference.JobId);
        }
示例#16
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);
        }
示例#17
0
        public void Constructor_DefaultLocations()
        {
            var projectId = "project";
            var service   = new FakeBigqueryService();
            var client    = new BigQueryClientImpl(projectId, service);

            Assert.Null(client.DefaultLocation);
            client = new BigQueryClientImpl(new ProjectReference {
                ProjectId = projectId
            }, service);
            Assert.Null(client.DefaultLocation);

            client = new BigQueryClientImpl(projectId, service, "us");
            Assert.Equal("us", client.DefaultLocation);

            client = new BigQueryClientImpl(new ProjectReference {
                ProjectId = projectId
            }, service, "us");
            Assert.Equal("us", client.DefaultLocation);
        }
示例#18
0
        public void ListDatasets()
        {
            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.ListDatasets(projectReference);
            var dataset = result.Single();

            Assert.Equal(projectId, dataset.Reference.ProjectId);
            Assert.Equal(datasetId, dataset.Reference.DatasetId);
        }
示例#19
0
        public async Task ListJobsAsync()
        {
            var projectId        = "project";
            var jobId            = "job";
            var service          = new FakeBigqueryService();
            var client           = new BigQueryClientImpl(projectId, service);
            var projectReference = client.GetProjectReference(projectId);
            var jobReference     = client.GetJobReference(projectId, jobId);

            service.ExpectRequest(
                service.Jobs.List(projectId),
                new JobList {
                Jobs = new[] { new JobsData {
                                   JobReference = jobReference
                               } }
            });
            var result = client.ListJobsAsync(projectReference);
            var job    = await result.Single();

            Assert.Equal(projectId, job.Reference.ProjectId);
            Assert.Equal(jobId, job.Reference.JobId);
        }