Search in sources :

Example 26 with Category

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

the class AvroIOTest method testAvroIOCompressedWriteAndReadASingleFile.

@Test
@SuppressWarnings("unchecked")
@Category(NeedsRunner.class)
public void testAvroIOCompressedWriteAndReadASingleFile() throws Throwable {
    List<GenericClass> values = ImmutableList.of(new GenericClass(3, "hi"), new GenericClass(5, "bar"));
    File outputFile = tmpFolder.newFile("output.avro");
    p.apply(Create.of(values)).apply(AvroIO.write(GenericClass.class).to(outputFile.getAbsolutePath()).withoutSharding().withCodec(CodecFactory.deflateCodec(9)));
    p.run();
    PCollection<GenericClass> input = p.apply(AvroIO.read(GenericClass.class).from(outputFile.getAbsolutePath()));
    PAssert.that(input).containsInAnyOrder(values);
    p.run();
    DataFileStream dataFileStream = new DataFileStream(new FileInputStream(outputFile), new GenericDatumReader());
    assertEquals("deflate", dataFileStream.getMetaString("avro.codec"));
}
Also used : GenericDatumReader(org.apache.avro.generic.GenericDatumReader) DataFileStream(org.apache.avro.file.DataFileStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 27 with Category

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

the class CompressedSourceTest method testCompressedAccordingToFilepatternGzip.

/**
   * Test reading according to filepattern when the file is bzipped.
   */
@Test
@Category(NeedsRunner.class)
public void testCompressedAccordingToFilepatternGzip() throws Exception {
    byte[] input = generateInput(100);
    File tmpFile = tmpFolder.newFile("test.gz");
    writeFile(tmpFile, input, CompressionMode.GZIP);
    verifyReadContents(input, tmpFile, null);
}
Also used : File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 28 with Category

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

the class CompressedSourceTest method testFalseBzip2Stream.

/**
   * Test reading an uncompressed file with {@link CompressionMode#BZIP2}, and show that
   * we fail.
   */
@Test
@Category(NeedsRunner.class)
public void testFalseBzip2Stream() throws Exception {
    byte[] input = generateInput(1000);
    File tmpFile = tmpFolder.newFile("test.bz2");
    Files.write(input, tmpFile);
    thrown.expectCause(Matchers.allOf(instanceOf(IOException.class), ThrowableMessageMatcher.hasMessage(containsString("Stream is not in the BZip2 format"))));
    verifyReadContents(input, tmpFile, CompressionMode.BZIP2);
}
Also used : File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 29 with Category

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

the class GatherAllPanesTest method singlePaneSingleReifiedPane.

@Test
@Category(NeedsRunner.class)
public void singlePaneSingleReifiedPane() {
    PCollection<Iterable<ValueInSingleWindow<Iterable<Long>>>> accumulatedPanes = p.apply(GenerateSequence.from(0).to(20000)).apply(WithTimestamps.of(new SerializableFunction<Long, Instant>() {

        @Override
        public Instant apply(Long input) {
            return new Instant(input * 10);
        }
    })).apply(Window.<Long>into(FixedWindows.of(Duration.standardMinutes(1))).triggering(AfterWatermark.pastEndOfWindow()).withAllowedLateness(Duration.ZERO).discardingFiredPanes()).apply(WithKeys.<Void, Long>of((Void) null).withKeyType(new TypeDescriptor<Void>() {
    })).apply(GroupByKey.<Void, Long>create()).apply(Values.<Iterable<Long>>create()).apply(GatherAllPanes.<Iterable<Long>>globally());
    PAssert.that(accumulatedPanes).satisfies(new SerializableFunction<Iterable<Iterable<ValueInSingleWindow<Iterable<Long>>>>, Void>() {

        @Override
        public Void apply(Iterable<Iterable<ValueInSingleWindow<Iterable<Long>>>> input) {
            for (Iterable<ValueInSingleWindow<Iterable<Long>>> windowedInput : input) {
                if (Iterables.size(windowedInput) > 1) {
                    fail("Expected all windows to have exactly one pane, got " + windowedInput);
                    return null;
                }
            }
            return null;
        }
    });
    p.run();
}
Also used : Instant(org.joda.time.Instant) ValueInSingleWindow(org.apache.beam.sdk.values.ValueInSingleWindow) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 30 with Category

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

the class DistinctTest method testTriggeredDistinct.

@Test
@Category({ ValidatesRunner.class, UsesTestStream.class })
public void testTriggeredDistinct() {
    Instant base = new Instant(0);
    TestStream<String> values = TestStream.create(StringUtf8Coder.of()).advanceWatermarkTo(base).addElements(TimestampedValue.of("k1", base), TimestampedValue.of("k2", base.plus(Duration.standardSeconds(10))), TimestampedValue.of("k3", base.plus(Duration.standardSeconds(20)))).advanceProcessingTime(Duration.standardMinutes(1)).addElements(TimestampedValue.of("k1", base.plus(Duration.standardSeconds(30))), TimestampedValue.of("k2", base.plus(Duration.standardSeconds(40))), TimestampedValue.of("k3", base.plus(Duration.standardSeconds(50)))).advanceWatermarkToInfinity();
    PCollection<String> distinctValues = triggeredDistinctPipeline.apply(values).apply(Window.<String>into(FixedWindows.of(Duration.standardMinutes(1))).triggering(Repeatedly.forever(AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardSeconds(30)))).withAllowedLateness(Duration.ZERO).accumulatingFiredPanes()).apply(Distinct.<String>create());
    PAssert.that(distinctValues).containsInAnyOrder("k1", "k2", "k3");
    triggeredDistinctPipeline.run();
}
Also used : Instant(org.joda.time.Instant) 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