use of org.apache.druid.data.input.Firehose in project druid by druid-io.
the class LocalFirehoseFactoryTest method testConnect.
@Test
public void testConnect() throws IOException {
try (final Firehose firehose = factory.connect(new StringInputRowParser(new CSVParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("timestamp", "a"))), ",", Arrays.asList("timestamp", "a"), false, 0), StandardCharsets.UTF_8.name()), null)) {
final List<Row> rows = new ArrayList<>();
while (firehose.hasMore()) {
rows.add(firehose.nextRow());
}
Assert.assertEquals(5, rows.size());
rows.sort(Comparator.comparing(Row::getTimestamp));
for (int i = 0; i < 5; i++) {
final List<String> dimVals = rows.get(i).getDimension("a");
Assert.assertEquals(1, dimVals.size());
Assert.assertEquals(i + "th test file", dimVals.get(0));
}
}
}
use of org.apache.druid.data.input.Firehose in project druid by druid-io.
the class SqlFirehoseFactoryTest method testWithoutCacheAndFetch.
@Test
public void testWithoutCacheAndFetch() throws Exception {
derbyConnector = derbyConnectorRule.getConnector();
SqlTestUtils testUtils = new SqlTestUtils(derbyConnector);
testUtils.createAndUpdateTable(TABLE_NAME_1, 10);
final SqlFirehoseFactory factory = new SqlFirehoseFactory(SQLLIST1, 0L, 0L, 0L, 0L, true, testUtils.getDerbyFirehoseConnector(), mapper);
final List<Row> rows = new ArrayList<>();
final File firehoseTmpDir = createFirehoseTmpDir("testWithoutCacheAndFetch");
try (Firehose firehose = factory.connect(parser, firehoseTmpDir)) {
while (firehose.hasMore()) {
rows.add(firehose.nextRow());
}
}
assertResult(rows, SQLLIST1);
assertNumRemainingCacheFiles(firehoseTmpDir, 0);
testUtils.dropTable(TABLE_NAME_1);
}
use of org.apache.druid.data.input.Firehose in project druid by druid-io.
the class AppenderatorDriverRealtimeIndexTaskTest method testReportParseExceptionsOnBadMetric.
@Test(timeout = 60_000L)
public void testReportParseExceptionsOnBadMetric() throws Exception {
expectPublishedSegments(0);
final AppenderatorDriverRealtimeIndexTask task = makeRealtimeTask(null, true);
final ListenableFuture<TaskStatus> statusFuture = runTask(task);
// Wait for firehose to show up, it starts off null.
while (task.getFirehose() == null) {
Thread.sleep(50);
}
final TestFirehose firehose = (TestFirehose) task.getFirehose();
firehose.addRows(ImmutableList.of(ImmutableMap.of("t", 2000000L, "dim1", "foo", "met1", "1"), ImmutableMap.of("t", 3000000L, "dim1", "foo", "met1", "foo"), ImmutableMap.of("t", now.minus(new Period("P1D")).getMillis(), "dim1", "foo", "met1", "foo"), ImmutableMap.of("t", 4000000L, "dim2", "bar", "met1", 2.0)));
// Stop the firehose, this will drain out existing events.
firehose.close();
// Wait for the task to finish.
TaskStatus status = statusFuture.get();
Assert.assertTrue(status.getErrorMsg().contains("org.apache.druid.java.util.common.RE: Max parse exceptions[0] exceeded"));
IngestionStatsAndErrorsTaskReportData reportData = getTaskReportData();
List<LinkedHashMap> parseExceptionReports = (List<LinkedHashMap>) reportData.getUnparseableEvents().get(RowIngestionMeters.BUILD_SEGMENTS);
List<String> expectedMessages = ImmutableList.of("Unable to parse value[foo] for field[met1]");
List<String> actualMessages = parseExceptionReports.stream().map((r) -> {
return ((List<String>) r.get("details")).get(0);
}).collect(Collectors.toList());
Assert.assertEquals(expectedMessages, actualMessages);
List<String> expectedInputs = ImmutableList.of("{t=3000000, dim1=foo, met1=foo}");
List<String> actualInputs = parseExceptionReports.stream().map((r) -> {
return (String) r.get("input");
}).collect(Collectors.toList());
Assert.assertEquals(expectedInputs, actualInputs);
}
use of org.apache.druid.data.input.Firehose in project druid by druid-io.
the class AppenderatorDriverRealtimeIndexTaskTest method testRestoreCorruptData.
@Test(timeout = 60_000L)
public void testRestoreCorruptData() throws Exception {
final AppenderatorDriverRealtimeIndexTask task1 = makeRealtimeTask(null);
// First run:
{
expectPublishedSegments(0);
final ListenableFuture<TaskStatus> statusFuture = runTask(task1);
// Wait for firehose to show up, it starts off null.
while (task1.getFirehose() == null) {
Thread.sleep(50);
}
final TestFirehose firehose = (TestFirehose) task1.getFirehose();
firehose.addRows(ImmutableList.of(ImmutableMap.of("t", now.getMillis(), "dim1", "foo")));
// Trigger graceful shutdown.
task1.stopGracefully(taskToolboxFactory.build(task1).getConfig());
// Wait for the task to finish. The status doesn't really matter, but we'll check it anyway.
final TaskStatus taskStatus = statusFuture.get();
Assert.assertEquals(TaskState.SUCCESS, taskStatus.getStatusCode());
// Nothing should be published.
Assert.assertTrue(publishedSegments.isEmpty());
}
Optional<File> optional = FileUtils.listFiles(baseDir, null, true).stream().filter(f -> f.getName().equals("00000.smoosh")).findFirst();
Assert.assertTrue("Could not find smoosh file", optional.isPresent());
// Corrupt the data:
final File smooshFile = optional.get();
Files.write(smooshFile.toPath(), StringUtils.toUtf8("oops!"));
// Second run:
{
expectPublishedSegments(0);
final AppenderatorDriverRealtimeIndexTask task2 = makeRealtimeTask(task1.getId());
final ListenableFuture<TaskStatus> statusFuture = runTask(task2);
// Wait for the task to finish.
TaskStatus status = statusFuture.get();
Map<String, Object> expectedMetrics = ImmutableMap.of(RowIngestionMeters.BUILD_SEGMENTS, ImmutableMap.of(RowIngestionMeters.PROCESSED_WITH_ERROR, 0, RowIngestionMeters.PROCESSED, 0, RowIngestionMeters.UNPARSEABLE, 0, RowIngestionMeters.THROWN_AWAY, 0));
IngestionStatsAndErrorsTaskReportData reportData = getTaskReportData();
Assert.assertEquals(expectedMetrics, reportData.getRowStats());
Pattern errorPattern = Pattern.compile("(?s)java\\.lang\\.IllegalArgumentException.*\n" + "\tat (java\\.base/)?java\\.nio\\.Buffer\\..*");
Assert.assertTrue(errorPattern.matcher(status.getErrorMsg()).matches());
}
}
use of org.apache.druid.data.input.Firehose in project druid by druid-io.
the class IngestSegmentFirehoseFactoryTest method testTransformSpec.
@Test
public void testTransformSpec() throws IOException {
Assert.assertEquals(MAX_SHARD_NUMBER.longValue(), SEGMENT_SET.size());
Integer rowcount = 0;
final TransformSpec transformSpec = new TransformSpec(new SelectorDimFilter(ColumnHolder.TIME_COLUMN_NAME, "1", null), ImmutableList.of(new ExpressionTransform(METRIC_FLOAT_NAME, METRIC_FLOAT_NAME + " * 10", ExprMacroTable.nil())));
int skipped = 0;
try (final Firehose firehose = factory.connect(transformSpec.decorate(rowParser), TMP_DIR)) {
while (firehose.hasMore()) {
InputRow row = firehose.nextRow();
if (row == null) {
skipped++;
continue;
}
Assert.assertArrayEquals(new String[] { DIM_NAME }, row.getDimensions().toArray());
Assert.assertArrayEquals(new String[] { DIM_VALUE }, row.getDimension(DIM_NAME).toArray());
Assert.assertEquals(METRIC_LONG_VALUE.longValue(), row.getMetric(METRIC_LONG_NAME).longValue());
Assert.assertEquals(METRIC_FLOAT_VALUE * 10, row.getMetric(METRIC_FLOAT_NAME).floatValue(), METRIC_FLOAT_VALUE * 0.0001);
++rowcount;
}
}
Assert.assertEquals(90, skipped);
Assert.assertEquals((int) MAX_ROWS, (int) rowcount);
}
Aggregations