Skip to content

Commit

Permalink
Captures assertion site and message in PAssert
Browse files Browse the repository at this point in the history
This makes PAssert failures quite a bit easier to debug.
Example message after this commit:

java.lang.AssertionError: Some message

	at org.apache.beam.sdk.testing.PAssert$PAssertionSite.capture(PAssert.java:384)
	at org.apache.beam.sdk.testing.PAssert.that(PAssert.java:279)
	at org.apache.beam.sdk.transforms.SplittableDoFnTest.testPairWithIndexWindowedTimestamped(SplittableDoFnTest.java:234)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        ...
Caused by: java.lang.AssertionError:
Expected: iterable over [<TimestampedValue(KV{z, 0}, 2017-01-10T00:38:28.000Z)>, <TimestampedValue(KV{bb, 0}, 2017-01-10T00:38:29.000Z)>, <TimestampedValue(KV{bb, 1}, 2017-01-10T00:38:29.000Z)>, <TimestampedValue(KV{ccccc, 0}, 2017-01-10T00:38:30.000Z)>, <TimestampedValue(KV{ccccc, 1}, 2017-01-10T00:38:30.000Z)>, <TimestampedValue(KV{ccccc, 2}, 2017-01-10T00:38:30.000Z)>, <TimestampedValue(KV{ccccc, 3}, 2017-01-10T00:38:30.000Z)>, <TimestampedValue(KV{ccccc, 4}, 2017-01-10T00:38:30.000Z)>] in any order
     but: Not matched: <TimestampedValue(KV{a, 0}, 2017-01-10T00:38:28.000Z)>
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at org.junit.Assert.assertThat(Assert.java:956)
	at org.junit.Assert.assertThat(Assert.java:923)
	at org.apache.beam.sdk.testing.PAssert$AssertContainsInAnyOrder.apply(PAssert.java:1270)
	at org.apache.beam.sdk.testing.PAssert$AssertContainsInAnyOrder.apply(PAssert.java:1)
        ...

(as opposed to, basically, just the "Caused by" part)
  • Loading branch information
jkff authored and kennknowles committed Jan 11, 2017
1 parent b81bd25 commit c62611c
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 33 deletions.
Loading

0 comments on commit c62611c

Please sign in to comment.