Search in sources :

Example 36 with Category

use of org.junit.experimental.categories.Category in project beam by apache.

the class CombineTest method testGlobalCombineWithDefaultsAndTriggers.

@Test
@Category(ValidatesRunner.class)
public void testGlobalCombineWithDefaultsAndTriggers() {
    PCollection<Integer> input = pipeline.apply(Create.of(1, 1));
    PCollection<String> output = input.apply(Window.<Integer>into(new GlobalWindows()).triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(1))).accumulatingFiredPanes().withAllowedLateness(new Duration(0))).apply(Sum.integersGlobally()).apply(ParDo.of(new FormatPaneInfo()));
    // The actual elements produced are nondeterministic. Could be one, could be two.
    // But it should certainly have a final element with the correct final sum.
    PAssert.that(output).satisfies(new SerializableFunction<Iterable<String>, Void>() {

        @Override
        public Void apply(Iterable<String> input) {
            assertThat(input, hasItem("2: true"));
            return null;
        }
    });
    pipeline.run();
}
Also used : GlobalWindows(org.apache.beam.sdk.transforms.windowing.GlobalWindows) Duration(org.joda.time.Duration) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 37 with Category

use of org.junit.experimental.categories.Category in project beam by apache.

the class TriggerExampleTest method testTotalFlow.

@Test
@Category(ValidatesRunner.class)
public void testTotalFlow() {
    PCollection<KV<String, Integer>> flow = pipeline.apply(Create.timestamped(TIME_STAMPED_INPUT)).apply(ParDo.of(new ExtractFlowInfo()));
    PCollection<TableRow> totalFlow = flow.apply(Window.<KV<String, Integer>>into(FixedWindows.of(Duration.standardMinutes(1)))).apply(new TotalFlow("default"));
    PCollection<String> results = totalFlow.apply(ParDo.of(new FormatResults()));
    PAssert.that(results).containsInAnyOrder(canonicalFormat(OUT_ROW_1), canonicalFormat(OUT_ROW_2));
    pipeline.run().waitUntilFinish();
}
Also used : TotalFlow(org.apache.beam.examples.cookbook.TriggerExample.TotalFlow) TableRow(com.google.api.services.bigquery.model.TableRow) KV(org.apache.beam.sdk.values.KV) ExtractFlowInfo(org.apache.beam.examples.cookbook.TriggerExample.ExtractFlowInfo) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 38 with Category

use of org.junit.experimental.categories.Category in project beam by apache.

the class WindowingTest method testTextIoInput.

@Test
@Category(NeedsRunner.class)
public void testTextIoInput() throws Exception {
    File tmpFile = tmpFolder.newFile("file.txt");
    String filename = tmpFile.getPath();
    try (PrintStream writer = new PrintStream(new FileOutputStream(tmpFile))) {
        writer.println("a 1");
        writer.println("b 2");
        writer.println("b 3");
        writer.println("c 11");
        writer.println("d 11");
    }
    PCollection<String> output = p.begin().apply("ReadLines", TextIO.read().from(filename)).apply(ParDo.of(new ExtractWordsWithTimestampsFn())).apply(new WindowedCount(FixedWindows.of(Duration.millis(10))));
    PAssert.that(output).containsInAnyOrder(output("a", 1, 1, 0, 10), output("b", 2, 2, 0, 10), output("c", 1, 11, 10, 20), output("d", 1, 11, 10, 20));
    p.run();
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 39 with Category

use of org.junit.experimental.categories.Category in project beam by apache.

the class WindowingTest method testMergingWindowing.

@Test
@Category(ValidatesRunner.class)
public void testMergingWindowing() {
    PCollection<String> input = p.apply(Create.timestamped(TimestampedValue.of("a", new Instant(1)), TimestampedValue.of("a", new Instant(5)), TimestampedValue.of("a", new Instant(20))));
    PCollection<String> output = input.apply(new WindowedCount(Sessions.withGapDuration(new Duration(10))));
    PAssert.that(output).containsInAnyOrder(output("a", 2, 1, 1, 15), output("a", 1, 20, 20, 30));
    p.run();
}
Also used : Instant(org.joda.time.Instant) Duration(org.joda.time.Duration) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 40 with Category

use of org.junit.experimental.categories.Category in project beam by apache.

the class WindowingTest method testPartitioningWindowing.

@Test
@Category(ValidatesRunner.class)
public void testPartitioningWindowing() {
    PCollection<String> input = p.apply(Create.timestamped(TimestampedValue.of("a", new Instant(1)), TimestampedValue.of("b", new Instant(2)), TimestampedValue.of("b", new Instant(3)), TimestampedValue.of("c", new Instant(11)), TimestampedValue.of("d", new Instant(11))));
    PCollection<String> output = input.apply(new WindowedCount(FixedWindows.of(new Duration(10))));
    PAssert.that(output).containsInAnyOrder(output("a", 1, 1, 0, 10), output("b", 2, 2, 0, 10), output("c", 1, 11, 10, 20), output("d", 1, 11, 10, 20));
    p.run();
}
Also used : Instant(org.joda.time.Instant) Duration(org.joda.time.Duration) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

Category (org.junit.experimental.categories.Category)499 Test (org.junit.Test)496 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)148 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)121 File (java.io.File)68 VM (org.apache.geode.test.dunit.VM)65 KV (org.apache.beam.sdk.values.KV)62 Instant (org.joda.time.Instant)60 ArrayList (java.util.ArrayList)55 Matchers.containsString (org.hamcrest.Matchers.containsString)49 StringUtils.byteArrayToJsonString (org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString)41 Region (org.apache.geode.cache.Region)35 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)34 Host (org.apache.geode.test.dunit.Host)34 Properties (java.util.Properties)32 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)31 Cache (org.apache.geode.cache.Cache)26 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)25 IOException (java.io.IOException)24 CacheException (org.apache.geode.cache.CacheException)24