44
44
import org .apache .kafka .connect .storage .OffsetStorageReader ;
45
45
import org .junit .After ;
46
46
import org .junit .Before ;
47
+ import org .junit .Rule ;
47
48
import org .junit .Test ;
49
+ import org .junit .rules .ExpectedException ;
48
50
49
51
import static org .junit .Assert .assertEquals ;
50
52
import static org .junit .Assert .assertNotEquals ;
@@ -61,6 +63,9 @@ public class DatagenTaskTest {
61
63
62
64
private static final AvroData AVRO_DATA = new AvroData (20 );
63
65
66
+ @ Rule
67
+ public ExpectedException expectedException = ExpectedException .none ();
68
+
64
69
private Map <String , String > config ;
65
70
private DatagenTask task ;
66
71
private List <SourceRecord > records ;
@@ -223,6 +228,36 @@ public void shouldFailToGenerateMoreRecordsThanSpecified() throws Exception {
223
228
}
224
229
}
225
230
231
+ /**
232
+ * <p>
233
+ * This test is non-deterministic. This test might fail in case avro-random-generator library
234
+ * updates/changes its underlying implementation.
235
+ * </p>
236
+ * @throws Exception
237
+ */
238
+ @ Test
239
+ public void shouldFailToGenerateComplexRegexWithTimeout () throws Exception {
240
+ createTaskWithSchemaAndTimeout ("regex_schema_timeout.avro" , "regex_key" , "100" );
241
+ expectedException .expect (ConnectException .class );
242
+ expectedException .expectMessage ("Record generation timed out" );
243
+ generateRecords ();
244
+ }
245
+
246
+ /**
247
+ * <p>
248
+ * This test is non-deterministic. This test might fail in case avro-random-generator library
249
+ * updates/changes its underlying implementation.
250
+ * </p>
251
+ * @throws Exception
252
+ */
253
+ @ Test
254
+ public void shouldFailToGenerateComplexRegexWithStackOverflow () throws Exception {
255
+ createTaskWithSchemaAndTimeout ("regex_schema_stackoverflow.avro" , "regex_key" , "100" );
256
+ expectedException .expect (ConnectException .class );
257
+ expectedException .expectMessage ("Unable to generate random record" );
258
+ generateRecords ();
259
+ }
260
+
226
261
private void generateAndValidateRecordsFor (DatagenTask .Quickstart quickstart ) throws Exception {
227
262
createTaskWith (quickstart );
228
263
generateRecords ();
@@ -337,6 +372,17 @@ private void createTaskWithSchema(String schemaResourceFilename, String idFieldN
337
372
loadKeyAndValueSchemas (schemaResourceFilename , idFieldName );
338
373
}
339
374
375
+ private void createTaskWithSchemaAndTimeout (String schemaResourceFile , String idFieldName ,
376
+ String timeout ) {
377
+ dropSchemaSourceConfigs ();
378
+ config .put (DatagenConnectorConfig .SCHEMA_FILENAME_CONF , schemaResourceFile );
379
+ config .put (DatagenConnectorConfig .SCHEMA_KEYFIELD_CONF , idFieldName );
380
+ config .put (DatagenConnectorConfig .GENERATE_TIMEOUT_CONF , timeout );
381
+ createTask ();
382
+ loadKeyAndValueSchemas (schemaResourceFile , idFieldName );
383
+
384
+ }
385
+
340
386
private void createTaskWithSchemaText (String schemaText , String keyField ) {
341
387
dropSchemaSourceConfigs ();
342
388
config .put (DatagenConnectorConfig .SCHEMA_STRING_CONF , schemaText );
0 commit comments