use of org.junit.experimental.categories.Category in project beam by apache.
the class TestStreamTest method testFirstElementLate.
@Test
@Category({ NeedsRunner.class, UsesTestStream.class })
public void testFirstElementLate() {
Instant lateElementTimestamp = new Instant(-1_000_000);
TestStream<String> stream = TestStream.create(StringUtf8Coder.of()).advanceWatermarkTo(new Instant(0)).addElements(TimestampedValue.of("late", lateElementTimestamp)).addElements(TimestampedValue.of("onTime", new Instant(100))).advanceWatermarkToInfinity();
FixedWindows windowFn = FixedWindows.of(Duration.millis(1000L));
Duration allowedLateness = Duration.millis(5000L);
PCollection<String> values = p.apply(stream).apply(Window.<String>into(windowFn).triggering(DefaultTrigger.of()).discardingFiredPanes().withAllowedLateness(allowedLateness)).apply(WithKeys.<Integer, String>of(1)).apply(GroupByKey.<Integer, String>create()).apply(Values.<Iterable<String>>create()).apply(Flatten.<String>iterables());
PAssert.that(values).inWindow(windowFn.assignWindow(lateElementTimestamp)).empty();
PAssert.that(values).inWindow(windowFn.assignWindow(new Instant(100))).containsInAnyOrder("onTime");
p.run();
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class PAssertTest method testEmptyFalseDefaultReasonString.
@Test
@Category(ValidatesRunner.class)
public void testEmptyFalseDefaultReasonString() throws Exception {
PCollection<Long> vals = pipeline.apply(GenerateSequence.from(0).to(5));
PAssert.that(vals).empty();
Throwable thrown = runExpectingAssertionFailure(pipeline);
String message = thrown.getMessage();
assertThat(message, containsString("GenerateSequence/Read(BoundedCountingSource).out"));
assertThat(message, containsString("Expected: iterable over [] in any order"));
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class PAssertTest method testPAssertEqualsSingletonFalse.
/**
* Test that we throw an error for false assertion on singleton.
*/
@Test
@Category(ValidatesRunner.class)
public void testPAssertEqualsSingletonFalse() throws Exception {
PCollection<Integer> pcollection = pipeline.apply(Create.of(42));
PAssert.thatSingleton("The value was not equal to 44", pcollection).isEqualTo(44);
Throwable thrown = runExpectingAssertionFailure(pipeline);
String message = thrown.getMessage();
assertThat(message, containsString("The value was not equal to 44"));
assertThat(message, containsString("Expected: <44>"));
assertThat(message, containsString("but: was <42>"));
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class PAssertTest method testAssertionSiteIsCapturedWithoutMessage.
@Test
@Category(ValidatesRunner.class)
public void testAssertionSiteIsCapturedWithoutMessage() throws Exception {
PCollection<Long> vals = pipeline.apply(GenerateSequence.from(0).to(5));
assertThatCollectionIsEmptyWithoutMessage(vals);
Throwable thrown = runExpectingAssertionFailure(pipeline);
assertThat(thrown.getMessage(), containsString("Expected: iterable over [] in any order"));
String stacktrace = Throwables.getStackTraceAsString(thrown);
assertThat(stacktrace, containsString("testAssertionSiteIsCapturedWithoutMessage"));
assertThat(stacktrace, containsString("assertThatCollectionIsEmptyWithoutMessage"));
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class PAssertTest method testAssertionSiteIsCapturedWithMessage.
@Test
@Category(ValidatesRunner.class)
public void testAssertionSiteIsCapturedWithMessage() throws Exception {
PCollection<Long> vals = pipeline.apply(GenerateSequence.from(0).to(5));
assertThatCollectionIsEmptyWithMessage(vals);
Throwable thrown = runExpectingAssertionFailure(pipeline);
assertThat(thrown.getMessage(), containsString("Should be empty"));
assertThat(thrown.getMessage(), containsString("Expected: iterable over [] in any order"));
String stacktrace = Throwables.getStackTraceAsString(thrown);
assertThat(stacktrace, containsString("testAssertionSiteIsCapturedWithMessage"));
assertThat(stacktrace, containsString("assertThatCollectionIsEmptyWithMessage"));
}
Aggregations