@@ -267,6 +267,67 @@ public void testPutWhenPartitioningOnMessageTime() {
267
267
verify (bigQuery , times (1 )).insertAll (argument .capture ());
268
268
assertEquals ("test-topic$20171026" , argument .getValue ().getTable ().getTable ());
269
269
}
270
+
271
+ @ Test
272
+ public void testPutWhenPartitioningIsSetToTrue () {
273
+ final String topic = "test-topic" ;
274
+
275
+ Map <String , String > properties = propertiesFactory .getProperties ();
276
+ properties .put (BigQuerySinkConfig .TOPICS_CONFIG , topic );
277
+ properties .put (BigQuerySinkConfig .DATASETS_CONFIG , ".*=scratch" );
278
+ properties .put (BigQuerySinkTaskConfig .BIGQUERY_PARTITION_DECORATOR_CONFIG , "true" );
279
+ properties .put (BigQuerySinkTaskConfig .BIGQUERY_MESSAGE_TIME_PARTITIONING_CONFIG , "true" );
280
+
281
+ BigQuery bigQuery = mock (BigQuery .class );
282
+ Storage storage = mock (Storage .class );
283
+ SinkTaskContext sinkTaskContext = mock (SinkTaskContext .class );
284
+ InsertAllResponse insertAllResponse = mock (InsertAllResponse .class );
285
+
286
+ when (bigQuery .insertAll (anyObject ())).thenReturn (insertAllResponse );
287
+ when (insertAllResponse .hasErrors ()).thenReturn (false );
288
+
289
+ BigQuerySinkTask testTask = new BigQuerySinkTask (bigQuery , null , storage , null );
290
+ testTask .initialize (sinkTaskContext );
291
+ testTask .start (properties );
292
+
293
+ testTask .put (Collections .singletonList (spoofSinkRecord (topic , "value" , "message text" ,
294
+ TimestampType .CREATE_TIME , 1509007584334L )));
295
+ testTask .flush (Collections .emptyMap ());
296
+ ArgumentCaptor <InsertAllRequest > argument = ArgumentCaptor .forClass (InsertAllRequest .class );
297
+
298
+ verify (bigQuery , times (1 )).insertAll (argument .capture ());
299
+ assertEquals ("test-topic$20171026" , argument .getValue ().getTable ().getTable ());
300
+ }
301
+
302
+ @ Test
303
+ public void testPutWhenPartitioningIsSetToFalse () {
304
+ final String topic = "test-topic" ;
305
+
306
+ Map <String , String > properties = propertiesFactory .getProperties ();
307
+ properties .put (BigQuerySinkConfig .TOPICS_CONFIG , topic );
308
+ properties .put (BigQuerySinkConfig .DATASETS_CONFIG , ".*=scratch" );
309
+ properties .put (BigQuerySinkTaskConfig .BIGQUERY_PARTITION_DECORATOR_CONFIG , "false" );
310
+
311
+ BigQuery bigQuery = mock (BigQuery .class );
312
+ Storage storage = mock (Storage .class );
313
+ SinkTaskContext sinkTaskContext = mock (SinkTaskContext .class );
314
+ InsertAllResponse insertAllResponse = mock (InsertAllResponse .class );
315
+
316
+ when (bigQuery .insertAll (anyObject ())).thenReturn (insertAllResponse );
317
+ when (insertAllResponse .hasErrors ()).thenReturn (false );
318
+
319
+ BigQuerySinkTask testTask = new BigQuerySinkTask (bigQuery , null , storage , null );
320
+ testTask .initialize (sinkTaskContext );
321
+ testTask .start (properties );
322
+
323
+ testTask .put (Collections .singletonList (spoofSinkRecord (topic , "value" , "message text" ,
324
+ TimestampType .CREATE_TIME , 1509007584334L )));
325
+ testTask .flush (Collections .emptyMap ());
326
+ ArgumentCaptor <InsertAllRequest > argument = ArgumentCaptor .forClass (InsertAllRequest .class );
327
+
328
+ verify (bigQuery , times (1 )).insertAll (argument .capture ());
329
+ assertEquals ("test-topic" , argument .getValue ().getTable ().getTable ());
330
+ }
270
331
271
332
// Make sure a connect exception is thrown when the message has no timestamp type
272
333
@ Test (expected = ConnectException .class )
0 commit comments