From dc3c38b513710f6f65737b9c5f8aaaf892645235 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Tue, 9 Apr 2019 14:48:42 +0530 Subject: [PATCH] Fix integration test --- .../cloud/bigquery/it/ITBigQueryTest.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 25ce3a7928a1..0ed59061442d 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-clients/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -644,21 +644,20 @@ public void testListTablesWithPartitioning() { } @Test - public void testListPartitions() { + public void testListPartitions() throws InterruptedException { String tableName = "test_table_partitions"; Date date = Date.fromJavaUtilDate(new java.util.Date()); String partitionDate = date.toString().replaceAll("-", ""); TableId tableId = TableId.of(DATASET, tableName + "$" + partitionDate); - TimePartitioning timePartitioning = TimePartitioning.of(Type.DAY, EXPIRATION_MS); - Schema schema = Schema.of(Field.of("StringField", LegacySQLTypeName.STRING)); - StandardTableDefinition tableDefinition = - StandardTableDefinition.newBuilder() - .setSchema(schema) - .setTimePartitioning(timePartitioning) - .build(); - TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); - Table partitionedTable = bigquery.create(tableInfo); - assertNotNull(partitionedTable); + String query = + String.format( + "CREATE OR REPLACE TABLE %s.%s ( StringField STRING )" + + " PARTITION BY DATE(_PARTITIONTIME) " + + "OPTIONS( partition_expiration_days=1)", + DATASET, tableName); + Job job = bigquery.create(JobInfo.of(QueryJobConfiguration.newBuilder(query).build())); + job.waitFor(); + assertTrue(job.isDone()); try { Map row = new HashMap(); row.put("StringField", "StringValue"); @@ -669,7 +668,7 @@ public void testListPartitions() { List partitions = bigquery.listPartitions(TableId.of(DATASET, tableName)); assertEquals(1, partitions.size()); } finally { - partitionedTable.delete(); + bigquery.delete(DATASET, tableName); } }