Search in sources :

Example 1 with GeneratorCheckpoint

use of org.apache.beam.sdk.nexmark.sources.generator.GeneratorCheckpoint in project beam by apache.

the class UnboundedEventSourceTest method resumeFromCheckpoint.

/**
 * Check aggressively checkpointing and resuming a reader gives us exactly the same event stream
 * as reading directly.
 */
@Ignore("TODO(BEAM-5070) Test is flaky. Fix before reenabling.")
@Test
public void resumeFromCheckpoint() throws IOException {
    Random random = new Random(297);
    int n = 47293;
    GeneratorConfig config = makeConfig(n);
    Generator modelGenerator = new Generator(config);
    EventIdChecker checker = new EventIdChecker();
    PipelineOptions options = TestPipeline.testingPipelineOptions();
    UnboundedEventSource source = new UnboundedEventSource(config, 1, 0, false);
    UnboundedReader<Event> reader = source.createReader(options, null);
    while (n > 0) {
        int m = Math.min(459 + random.nextInt(455), n);
        System.out.printf("reading %d...%n", m);
        checker.add(m, reader, modelGenerator);
        n -= m;
        System.out.printf("splitting with %d remaining...%n", n);
        CheckpointMark checkpointMark = reader.getCheckpointMark();
        reader = source.createReader(options, (GeneratorCheckpoint) checkpointMark);
    }
    assertFalse(reader.advance());
}
Also used : Random(java.util.Random) GeneratorCheckpoint(org.apache.beam.sdk.nexmark.sources.generator.GeneratorCheckpoint) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) CheckpointMark(org.apache.beam.sdk.io.UnboundedSource.CheckpointMark) Event(org.apache.beam.sdk.nexmark.model.Event) GeneratorConfig(org.apache.beam.sdk.nexmark.sources.generator.GeneratorConfig) GeneratorCheckpoint(org.apache.beam.sdk.nexmark.sources.generator.GeneratorCheckpoint) Generator(org.apache.beam.sdk.nexmark.sources.generator.Generator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Random (java.util.Random)1 CheckpointMark (org.apache.beam.sdk.io.UnboundedSource.CheckpointMark)1 Event (org.apache.beam.sdk.nexmark.model.Event)1 Generator (org.apache.beam.sdk.nexmark.sources.generator.Generator)1 GeneratorCheckpoint (org.apache.beam.sdk.nexmark.sources.generator.GeneratorCheckpoint)1 GeneratorConfig (org.apache.beam.sdk.nexmark.sources.generator.GeneratorConfig)1 PipelineOptions (org.apache.beam.sdk.options.PipelineOptions)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1