|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -package com.google.gcloud.bigquery.it; |
18 | | - |
| 17 | +package com.google.gcloud.bigquery; |
| 18 | + |
| 19 | +import static com.google.gcloud.bigquery.BigQuery.DatasetField; |
| 20 | +import static com.google.gcloud.bigquery.BigQuery.JobField; |
| 21 | +import static com.google.gcloud.bigquery.BigQuery.JobListOption; |
| 22 | +import static com.google.gcloud.bigquery.BigQuery.JobOption; |
| 23 | +import static com.google.gcloud.bigquery.BigQuery.TableField; |
| 24 | +import static com.google.gcloud.bigquery.BigQuery.TableOption; |
19 | 25 | import static org.junit.Assert.assertEquals; |
20 | 26 | import static org.junit.Assert.assertFalse; |
21 | 27 | import static org.junit.Assert.assertNotNull; |
|
26 | 32 | import com.google.common.collect.ImmutableList; |
27 | 33 | import com.google.common.collect.ImmutableMap; |
28 | 34 | import com.google.gcloud.Page; |
29 | | -import com.google.gcloud.WriteChannel; |
30 | | -import com.google.gcloud.bigquery.BigQuery; |
31 | | -import com.google.gcloud.bigquery.BigQuery.DatasetField; |
32 | 35 | import com.google.gcloud.bigquery.BigQuery.DatasetOption; |
33 | | -import com.google.gcloud.bigquery.BigQuery.JobField; |
34 | | -import com.google.gcloud.bigquery.BigQuery.JobListOption; |
35 | | -import com.google.gcloud.bigquery.BigQuery.JobOption; |
36 | | -import com.google.gcloud.bigquery.BigQuery.TableField; |
37 | | -import com.google.gcloud.bigquery.BigQuery.TableOption; |
38 | | -import com.google.gcloud.bigquery.BigQueryError; |
39 | | -import com.google.gcloud.bigquery.BigQueryException; |
40 | | -import com.google.gcloud.bigquery.CopyJobConfiguration; |
41 | | -import com.google.gcloud.bigquery.Dataset; |
42 | | -import com.google.gcloud.bigquery.DatasetId; |
43 | | -import com.google.gcloud.bigquery.DatasetInfo; |
44 | | -import com.google.gcloud.bigquery.ExternalTableDefinition; |
45 | | -import com.google.gcloud.bigquery.ExtractJobConfiguration; |
46 | | -import com.google.gcloud.bigquery.Field; |
47 | | -import com.google.gcloud.bigquery.FieldValue; |
48 | | -import com.google.gcloud.bigquery.FormatOptions; |
49 | | -import com.google.gcloud.bigquery.InsertAllRequest; |
50 | | -import com.google.gcloud.bigquery.InsertAllResponse; |
51 | | -import com.google.gcloud.bigquery.Job; |
52 | | -import com.google.gcloud.bigquery.JobInfo; |
53 | | -import com.google.gcloud.bigquery.JobStatistics; |
54 | | -import com.google.gcloud.bigquery.LoadJobConfiguration; |
55 | | -import com.google.gcloud.bigquery.QueryJobConfiguration; |
56 | | -import com.google.gcloud.bigquery.QueryRequest; |
57 | | -import com.google.gcloud.bigquery.QueryResponse; |
58 | | -import com.google.gcloud.bigquery.Schema; |
59 | | -import com.google.gcloud.bigquery.StandardTableDefinition; |
60 | | -import com.google.gcloud.bigquery.Table; |
61 | | -import com.google.gcloud.bigquery.TableDefinition; |
62 | | -import com.google.gcloud.bigquery.TableId; |
63 | | -import com.google.gcloud.bigquery.TableInfo; |
64 | | -import com.google.gcloud.bigquery.ViewDefinition; |
65 | | -import com.google.gcloud.bigquery.WriteChannelConfiguration; |
66 | 36 | import com.google.gcloud.bigquery.testing.RemoteBigQueryHelper; |
67 | 37 | import com.google.gcloud.storage.BlobInfo; |
68 | 38 | import com.google.gcloud.storage.BucketInfo; |
|
75 | 45 | import org.junit.Test; |
76 | 46 | import org.junit.rules.Timeout; |
77 | 47 |
|
| 48 | +import java.io.FileNotFoundException; |
78 | 49 | import java.io.IOException; |
79 | 50 | import java.nio.ByteBuffer; |
80 | 51 | import java.nio.charset.StandardCharsets; |
@@ -169,7 +140,7 @@ public class ITBigQueryTest { |
169 | 140 | public Timeout globalTimeout = Timeout.seconds(300); |
170 | 141 |
|
171 | 142 | @BeforeClass |
172 | | - public static void beforeClass() throws InterruptedException { |
| 143 | + public static void beforeClass() throws IOException, InterruptedException { |
173 | 144 | RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); |
174 | 145 | RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(); |
175 | 146 | bigquery = bigqueryHelper.options().service(); |
@@ -198,9 +169,8 @@ public static void afterClass() throws ExecutionException, InterruptedException |
198 | 169 | if (bigquery != null) { |
199 | 170 | RemoteBigQueryHelper.forceDelete(bigquery, DATASET); |
200 | 171 | } |
201 | | - if (storage != null) { |
202 | | - boolean wasDeleted = RemoteGcsHelper.forceDelete(storage, BUCKET, 10, TimeUnit.SECONDS); |
203 | | - if (!wasDeleted && LOG.isLoggable(Level.WARNING)) { |
| 172 | + if (storage != null && !RemoteGcsHelper.forceDelete(storage, BUCKET, 10, TimeUnit.SECONDS)) { |
| 173 | + if (LOG.isLoggable(Level.WARNING)) { |
204 | 174 | LOG.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET); |
205 | 175 | } |
206 | 176 | } |
@@ -684,9 +654,10 @@ public void testQuery() throws InterruptedException { |
684 | 654 | rowCount++; |
685 | 655 | } |
686 | 656 | assertEquals(2, rowCount); |
687 | | - Job queryJob = bigquery.getJob(response.jobId()); |
688 | | - JobStatistics.QueryStatistics statistics = queryJob.statistics(); |
689 | | - assertNotNull(statistics.queryPlan()); |
| 657 | + // todo(mziccard) uncomment as soon as #624 is closed |
| 658 | + // Job queryJob = bigquery.getJob(response.jobId()); |
| 659 | + // JobStatistics.QueryStatistics statistics = queryJob.statistics(); |
| 660 | + // assertNotNull(statistics.queryPlan()); |
690 | 661 | } |
691 | 662 |
|
692 | 663 | @Test |
@@ -714,7 +685,7 @@ public void testListJobsWithSelectedFields() { |
714 | 685 | } |
715 | 686 |
|
716 | 687 | @Test |
717 | | - public void testCreateAndGetJob() { |
| 688 | + public void testCreateAndGetJob() throws InterruptedException { |
718 | 689 | String sourceTableName = "test_create_and_get_job_source_table"; |
719 | 690 | String destinationTableName = "test_create_and_get_job_destination_table"; |
720 | 691 | TableId sourceTable = TableId.of(DATASET, sourceTableName); |
@@ -746,7 +717,7 @@ public void testCreateAndGetJob() { |
746 | 717 | } |
747 | 718 |
|
748 | 719 | @Test |
749 | | - public void testCreateAndGetJobWithSelectedFields() { |
| 720 | + public void testCreateAndGetJobWithSelectedFields() throws InterruptedException { |
750 | 721 | String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table"; |
751 | 722 | String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table"; |
752 | 723 | TableId sourceTable = TableId.of(DATASET, sourceTableName); |
@@ -851,9 +822,10 @@ public void testQueryJob() throws InterruptedException { |
851 | 822 | } |
852 | 823 | assertEquals(2, rowCount); |
853 | 824 | assertTrue(bigquery.delete(DATASET, tableName)); |
854 | | - Job queryJob = bigquery.getJob(remoteJob.jobId()); |
855 | | - JobStatistics.QueryStatistics statistics = queryJob.statistics(); |
856 | | - assertNotNull(statistics.queryPlan()); |
| 825 | + // todo(mziccard) uncomment as soon as #624 is closed |
| 826 | + // Job queryJob = bigquery.getJob(remoteJob.jobId()); |
| 827 | + // JobStatistics.QueryStatistics statistics = queryJob.statistics(); |
| 828 | + // assertNotNull(statistics.queryPlan()); |
857 | 829 | } |
858 | 830 |
|
859 | 831 | @Test |
@@ -902,20 +874,20 @@ public void testCancelJob() throws InterruptedException { |
902 | 874 | } |
903 | 875 |
|
904 | 876 | @Test |
905 | | - public void testCancelNonExistingJob() { |
| 877 | + public void testCancelNonExistingJob() throws InterruptedException { |
906 | 878 | assertFalse(bigquery.cancel("test_cancel_non_existing_job")); |
907 | 879 | } |
908 | 880 |
|
909 | 881 | @Test |
910 | | - public void testInsertFromFile() throws InterruptedException { |
| 882 | + public void testInsertFromFile() throws InterruptedException, FileNotFoundException { |
911 | 883 | String destinationTableName = "test_insert_from_file_table"; |
912 | 884 | TableId tableId = TableId.of(DATASET, destinationTableName); |
913 | 885 | WriteChannelConfiguration configuration = WriteChannelConfiguration.builder(tableId) |
914 | 886 | .formatOptions(FormatOptions.json()) |
915 | 887 | .createDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED) |
916 | 888 | .schema(TABLE_SCHEMA) |
917 | 889 | .build(); |
918 | | - try (WriteChannel channel = bigquery.writer(configuration)) { |
| 890 | + try (TableDataWriteChannel channel = bigquery.writer(configuration)) { |
919 | 891 | channel.write(ByteBuffer.wrap(JSON_CONTENT.getBytes(StandardCharsets.UTF_8))); |
920 | 892 | } catch (IOException e) { |
921 | 893 | fail("IOException was not expected"); |
|
0 commit comments