3535import java .io .File ;
3636import java .time .Duration ;
3737import java .util .HashMap ;
38+ import java .util .UUID ;
3839import java .util .concurrent .CompletableFuture ;
3940import java .util .concurrent .ExecutionException ;
4041import java .util .concurrent .TimeUnit ;
5960@ DirtiesContext (classMode = ClassMode .AFTER_EACH_TEST_METHOD )
6061class BigQueryFileMessageHandlerIntegrationTests {
6162
62- private static final String TABLE_NAME = "test_table" ;
63+ private String tableName ;
6364
64- @ Autowired private ThreadPoolTaskScheduler taskScheduler ;
65+ @ Autowired
66+ private ThreadPoolTaskScheduler taskScheduler ;
6567
66- @ Autowired private BigQuery bigquery ;
68+ @ Autowired
69+ private BigQuery bigquery ;
6770
68- @ Autowired private BigQueryFileMessageHandler messageHandler ;
71+ @ Autowired
72+ private BigQueryFileMessageHandler messageHandler ;
6973
7074 @ BeforeEach
7175 @ AfterEach
7276 void setup () {
77+ if (tableName == null ) {
78+ tableName = "test_table_" + UUID .randomUUID ().toString ().replace ('-' , '_' );
79+ }
7380 // Clear the previous dataset before beginning the test.
74- this .bigquery .delete (TableId .of (DATASET_NAME , TABLE_NAME ));
81+ this .bigquery .delete (TableId .of (DATASET_NAME , tableName ));
7582 }
7683
7784 @ Test
@@ -83,7 +90,7 @@ void testLoadFileWithSchema() throws InterruptedException, ExecutionException {
8390 Field .newBuilder ("County" , StandardSQLTypeName .STRING ).setMode (Mode .NULLABLE ).build ());
8491
8592 HashMap <String , Object > messageHeaders = new HashMap <>();
86- messageHeaders .put (BigQuerySpringMessageHeaders .TABLE_NAME , TABLE_NAME );
93+ messageHeaders .put (BigQuerySpringMessageHeaders .TABLE_NAME , tableName );
8794 messageHeaders .put (BigQuerySpringMessageHeaders .FORMAT_OPTIONS , FormatOptions .csv ());
8895 messageHeaders .put (BigQuerySpringMessageHeaders .TABLE_SCHEMA , schema );
8996
@@ -104,7 +111,8 @@ void testLoadFileWithSchema() throws InterruptedException, ExecutionException {
104111 jobFuture .get ();
105112
106113 QueryJobConfiguration queryJobConfiguration =
107- QueryJobConfiguration .newBuilder ("SELECT * FROM test_dataset.test_table" ).build ();
114+ QueryJobConfiguration .newBuilder (String .format ("SELECT * FROM test_dataset.%s" , tableName ))
115+ .build ();
108116 TableResult result = this .bigquery .query (queryJobConfiguration );
109117
110118 assertThat (result .getTotalRows ()).isEqualTo (1 );
@@ -119,7 +127,7 @@ void testLoadFileWithSchema() throws InterruptedException, ExecutionException {
119127 @ Test
120128 void testLoadFile () throws InterruptedException , ExecutionException {
121129 HashMap <String , Object > messageHeaders = new HashMap <>();
122- this .messageHandler .setTableName (TABLE_NAME );
130+ this .messageHandler .setTableName (tableName );
123131 this .messageHandler .setFormatOptions (FormatOptions .csv ());
124132
125133 Message <File > message =
@@ -139,7 +147,8 @@ void testLoadFile() throws InterruptedException, ExecutionException {
139147 jobFuture .get ();
140148
141149 QueryJobConfiguration queryJobConfiguration =
142- QueryJobConfiguration .newBuilder ("SELECT * FROM test_dataset.test_table" ).build ();
150+ QueryJobConfiguration .newBuilder (String .format ("SELECT * FROM test_dataset.%s" , tableName ))
151+ .build ();
143152 TableResult result = this .bigquery .query (queryJobConfiguration );
144153
145154 assertThat (result .getTotalRows ()).isEqualTo (1 );
@@ -155,7 +164,7 @@ void testLoadFile_sync() throws InterruptedException {
155164 this .messageHandler .setSync (true );
156165
157166 HashMap <String , Object > messageHeaders = new HashMap <>();
158- messageHeaders .put (BigQuerySpringMessageHeaders .TABLE_NAME , TABLE_NAME );
167+ messageHeaders .put (BigQuerySpringMessageHeaders .TABLE_NAME , tableName );
159168 messageHeaders .put (BigQuerySpringMessageHeaders .FORMAT_OPTIONS , FormatOptions .csv ());
160169
161170 Message <File > message =
@@ -166,15 +175,16 @@ void testLoadFile_sync() throws InterruptedException {
166175 assertThat (job ).isNotNull ();
167176
168177 QueryJobConfiguration queryJobConfiguration =
169- QueryJobConfiguration .newBuilder ("SELECT * FROM test_dataset.test_table" ).build ();
178+ QueryJobConfiguration .newBuilder (String .format ("SELECT * FROM test_dataset.%s" , tableName ))
179+ .build ();
170180 TableResult result = this .bigquery .query (queryJobConfiguration );
171181 assertThat (result .getTotalRows ()).isEqualTo (1 );
172182 }
173183
174184 @ Test
175185 void testLoadFile_cancel () {
176186 HashMap <String , Object > messageHeaders = new HashMap <>();
177- messageHeaders .put (BigQuerySpringMessageHeaders .TABLE_NAME , TABLE_NAME );
187+ messageHeaders .put (BigQuerySpringMessageHeaders .TABLE_NAME , tableName );
178188 messageHeaders .put (BigQuerySpringMessageHeaders .FORMAT_OPTIONS , FormatOptions .csv ());
179189
180190 Message <File > message =
0 commit comments