Search in sources :

Example 16 with Firehose

use of org.apache.druid.data.input.Firehose in project druid by druid-io.

the class PrefetchableTextFilesFirehoseFactoryTest method testReconnectWithCache.

@Test
public void testReconnectWithCache() throws IOException {
    final TestPrefetchableTextFilesFirehoseFactory factory = TestPrefetchableTextFilesFirehoseFactory.with(TEST_DIR, 2048, 0);
    final File firehoseTmpDir = createFirehoseTmpDir("testReconnectWithCache");
    for (int i = 0; i < 5; i++) {
        final List<Row> rows = new ArrayList<>();
        try (Firehose firehose = factory.connect(PARSER, firehoseTmpDir)) {
            if (i > 0) {
                Assert.assertEquals(FILE_SIZE * 2, factory.getCacheManager().getTotalCachedBytes());
            }
            while (firehose.hasMore()) {
                rows.add(firehose.nextRow());
            }
        }
        assertResult(rows);
        assertNumRemainingCacheFiles(firehoseTmpDir, 2);
    }
}
Also used : Firehose(org.apache.druid.data.input.Firehose) ArrayList(java.util.ArrayList) Row(org.apache.druid.data.input.Row) File(java.io.File) Test(org.junit.Test)

Example 17 with Firehose

use of org.apache.druid.data.input.Firehose in project druid by druid-io.

the class PrefetchableTextFilesFirehoseFactoryTest method testWithSmallCacheAndLargeFetch.

@Test
public void testWithSmallCacheAndLargeFetch() throws IOException {
    final TestPrefetchableTextFilesFirehoseFactory factory = TestPrefetchableTextFilesFirehoseFactory.with(TEST_DIR, 1024, 2048);
    final List<Row> rows = new ArrayList<>();
    final File firehoseTmpDir = createFirehoseTmpDir("testWithSmallCacheAndLargeFetch");
    try (Firehose firehose = factory.connect(PARSER, firehoseTmpDir)) {
        while (firehose.hasMore()) {
            rows.add(firehose.nextRow());
        }
    }
    assertResult(rows);
    assertNumRemainingCacheFiles(firehoseTmpDir, 1);
}
Also used : Firehose(org.apache.druid.data.input.Firehose) ArrayList(java.util.ArrayList) Row(org.apache.druid.data.input.Row) File(java.io.File) Test(org.junit.Test)

Example 18 with Firehose

use of org.apache.druid.data.input.Firehose in project druid by druid-io.

the class PrefetchableTextFilesFirehoseFactoryTest method testTimeout.

@Test
public void testTimeout() throws IOException {
    expectedException.expect(RuntimeException.class);
    expectedException.expectCause(CoreMatchers.instanceOf(TimeoutException.class));
    final TestPrefetchableTextFilesFirehoseFactory factory = TestPrefetchableTextFilesFirehoseFactory.withSleepMillis(TEST_DIR, 1000);
    try (Firehose firehose = factory.connect(PARSER, createFirehoseTmpDir("testTimeout"))) {
        while (firehose.hasMore()) {
            firehose.nextRow();
        }
    }
}
Also used : Firehose(org.apache.druid.data.input.Firehose) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 19 with Firehose

use of org.apache.druid.data.input.Firehose in project druid by druid-io.

the class NoopTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    if (firehoseFactory != null) {
        log.info("Connecting firehose");
    }
    try (Firehose firehose = firehoseFactory != null ? firehoseFactory.connect(null, null) : null) {
        log.info("Running noop task[%s]", getId());
        log.info("Sleeping for %,d millis.", runTime);
        Thread.sleep(runTime);
        log.info("Woke up!");
        return TaskStatus.success(getId());
    }
}
Also used : Firehose(org.apache.druid.data.input.Firehose)

Example 20 with Firehose

use of org.apache.druid.data.input.Firehose in project druid by druid-io.

the class IngestSegmentFirehoseFactoryTimelineTest method testSplit.

private void testSplit() throws Exception {
    Assert.assertTrue(factory.isSplittable());
    final int numSplits = factory.getNumSplits(null);
    // We set maxInputSegmentBytesPerSplit to 2 so each segment should become a byte.
    Assert.assertEquals(segmentCount, numSplits);
    final List<InputSplit<List<WindowedSegmentId>>> splits = factory.getSplits(null).collect(Collectors.toList());
    Assert.assertEquals(numSplits, splits.size());
    int count = 0;
    long sum = 0;
    for (InputSplit<List<WindowedSegmentId>> split : splits) {
        final FiniteFirehoseFactory<InputRowParser, List<WindowedSegmentId>> splitFactory = factory.withSplit(split);
        try (final Firehose firehose = splitFactory.connect(ROW_PARSER, tmpDir)) {
            while (firehose.hasMore()) {
                final InputRow row = firehose.nextRow();
                count++;
                sum += row.getMetric(METRICS[0]).longValue();
            }
        }
    }
    Assert.assertEquals("count", expectedCount, count);
    Assert.assertEquals("sum", expectedSum, sum);
}
Also used : Firehose(org.apache.druid.data.input.Firehose) InputRow(org.apache.druid.data.input.InputRow) MapBasedInputRow(org.apache.druid.data.input.MapBasedInputRow) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) InputRowParser(org.apache.druid.data.input.impl.InputRowParser) MapInputRowParser(org.apache.druid.data.input.impl.MapInputRowParser) InputSplit(org.apache.druid.data.input.InputSplit)

Aggregations

Firehose (org.apache.druid.data.input.Firehose)30 Test (org.junit.Test)25 File (java.io.File)19 ArrayList (java.util.ArrayList)16 Row (org.apache.druid.data.input.Row)14 InputRow (org.apache.druid.data.input.InputRow)13 List (java.util.List)7 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 IOException (java.io.IOException)6 Map (java.util.Map)6 InputRowParser (org.apache.druid.data.input.impl.InputRowParser)6 MapInputRowParser (org.apache.druid.data.input.impl.MapInputRowParser)6 DataSchema (org.apache.druid.segment.indexing.DataSchema)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 Iterables (com.google.common.collect.Iterables)4 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)4 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)4