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"));
}
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);
}
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);
}
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();
}
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();
}
Aggregations