Search in sources :

Example 6 with NamedTestResult

use of org.apache.beam.sdk.testutils.NamedTestResult in project beam by apache.

the class KafkaIOIT method testKafkaIOReadsAndWritesCorrectlyInBatch.

@Test
public void testKafkaIOReadsAndWritesCorrectlyInBatch() throws IOException {
    // Map of hashes of set size collections with 100b records - 10b key, 90b values.
    Map<Long, String> expectedHashes = ImmutableMap.of(1000L, "4507649971ee7c51abbb446e65a5c660", 100_000_000L, "0f12c27c9a7672e14775594be66cad9a");
    expectedHashcode = getHashForRecordCount(sourceOptions.numRecords, expectedHashes);
    writePipeline.apply("Generate records", Read.from(new SyntheticBoundedSource(sourceOptions))).apply("Measure write time", ParDo.of(new TimeMonitor<>(NAMESPACE, WRITE_TIME_METRIC_NAME))).apply("Write to Kafka", writeToKafka());
    PCollection<String> hashcode = readPipeline.apply("Read from bounded Kafka", readFromBoundedKafka()).apply("Measure read time", ParDo.of(new TimeMonitor<>(NAMESPACE, READ_TIME_METRIC_NAME))).apply("Map records to strings", MapElements.via(new MapKafkaRecordsToStrings())).apply("Calculate hashcode", Combine.globally(new HashingFn()).withoutDefaults());
    PAssert.thatSingleton(hashcode).isEqualTo(expectedHashcode);
    PipelineResult writeResult = writePipeline.run();
    writeResult.waitUntilFinish();
    PipelineResult readResult = readPipeline.run();
    PipelineResult.State readState = readResult.waitUntilFinish(Duration.standardSeconds(options.getReadTimeout()));
    cancelIfTimeouted(readResult, readState);
    if (!options.isWithTestcontainers()) {
        Set<NamedTestResult> metrics = readMetrics(writeResult, readResult);
        IOITMetrics.publishToInflux(TEST_ID, TIMESTAMP, metrics, settings);
    }
}
Also used : TimeMonitor(org.apache.beam.sdk.testutils.metrics.TimeMonitor) PipelineResult(org.apache.beam.sdk.PipelineResult) SyntheticOptions.fromJsonString(org.apache.beam.sdk.io.synthetic.SyntheticOptions.fromJsonString) HashingFn(org.apache.beam.sdk.io.common.HashingFn) SyntheticBoundedSource(org.apache.beam.sdk.io.synthetic.SyntheticBoundedSource) NamedTestResult(org.apache.beam.sdk.testutils.NamedTestResult) Test(org.junit.Test)

Aggregations

NamedTestResult (org.apache.beam.sdk.testutils.NamedTestResult)6 PipelineResult (org.apache.beam.sdk.PipelineResult)4 SyntheticBoundedSource (org.apache.beam.sdk.io.synthetic.SyntheticBoundedSource)3 SyntheticOptions.fromJsonString (org.apache.beam.sdk.io.synthetic.SyntheticOptions.fromJsonString)3 MetricsReader (org.apache.beam.sdk.testutils.metrics.MetricsReader)3 TimeMonitor (org.apache.beam.sdk.testutils.metrics.TimeMonitor)3 Test (org.junit.Test)3 Timestamp (com.google.cloud.Timestamp)2 HashingFn (org.apache.beam.sdk.io.common.HashingFn)2 IOTestPipelineOptions (org.apache.beam.sdk.io.common.IOTestPipelineOptions)2 SyntheticSourceOptions (org.apache.beam.sdk.io.synthetic.SyntheticSourceOptions)2 StreamingOptions (org.apache.beam.sdk.options.StreamingOptions)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 BiFunction (java.util.function.BiFunction)1 Read (org.apache.beam.sdk.io.Read)1 IOITHelper (org.apache.beam.sdk.io.common.IOITHelper)1