Skip to content

Commit adb4e35

Browse files
committed
Added Unit Tests for timeout and stackoverflow error
1 parent 47d95e9 commit adb4e35

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/main/java/io/confluent/kafka/connect/datagen/DatagenConnectorConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class DatagenConnectorConfig extends AbstractConfig {
4949
private static final String RANDOM_SEED_DOC = "Numeric seed for generating random data. "
5050
+ "Two connectors started with the same seed will deterministically produce the same data. "
5151
+ "Each task will generate different data than the other tasks in the same connector.";
52-
private static final String GENERATE_TIMEOUT_CONF = "generate.timeout";
52+
public static final String GENERATE_TIMEOUT_CONF = "generate.timeout";
5353
private static final String GENERATE_TIMEOUT_DOC = "Timeout in milliseconds for random message "
5454
+ "generation";
5555

src/test/java/io/confluent/kafka/connect/datagen/DatagenTaskTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
import org.apache.kafka.connect.storage.OffsetStorageReader;
4545
import org.junit.After;
4646
import org.junit.Before;
47+
import org.junit.Rule;
4748
import org.junit.Test;
49+
import org.junit.rules.ExpectedException;
4850

4951
import static org.junit.Assert.assertEquals;
5052
import static org.junit.Assert.assertNotEquals;
@@ -61,6 +63,9 @@ public class DatagenTaskTest {
6163

6264
private static final AvroData AVRO_DATA = new AvroData(20);
6365

66+
@Rule
67+
public ExpectedException expectedException = ExpectedException.none();
68+
6469
private Map<String, String> config;
6570
private DatagenTask task;
6671
private List<SourceRecord> records;
@@ -223,6 +228,36 @@ public void shouldFailToGenerateMoreRecordsThanSpecified() throws Exception {
223228
}
224229
}
225230

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+
226261
private void generateAndValidateRecordsFor(DatagenTask.Quickstart quickstart) throws Exception {
227262
createTaskWith(quickstart);
228263
generateRecords();
@@ -337,6 +372,17 @@ private void createTaskWithSchema(String schemaResourceFilename, String idFieldN
337372
loadKeyAndValueSchemas(schemaResourceFilename, idFieldName);
338373
}
339374

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+
340386
private void createTaskWithSchemaText(String schemaText, String keyField) {
341387
dropSchemaSourceConfigs();
342388
config.put(DatagenConnectorConfig.SCHEMA_STRING_CONF, schemaText);

0 commit comments

Comments
 (0)