You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For my testing purposes, I wish to limit certain IO events and prevent regression against these metrics. Consider the following example:
@Test
@EnableEvent("jdk.FileRead", threshold = 0)
fun `file is buffered no more than 10 times`() {
operateOnFile(file)
jfrEvents.awaitEvents()
val readCount = jfrEvents.filter(JfrEventTypes.FILE_READ).count()
assertThat(readCount).isAtMost(10)
}
Every FILE_READ event will be counted, including IO triggered by class loading. This is probably desired from jfrunit’s perspective but can make writing tests a bit cumbersome.
Filtering by jfrEvents by class is possible but the test should probably remain agnostic as to where the IO originates, especially when reads are delegated to an external dependency.
This forces a workaround like the following:
@BeforeAll
fun setup() {
operateOnFile(dummyFile)
}
@Test
@EnableEvent("jdk.FileRead", threshold = 0)
fun `file is buffered no more than 10 times`() {
operateOnFile(file)
jfrEvents.awaitEvents()
}
@AfterAll
fun doActualAssertions() {
val readCount = jfrEvents.filter(JfrEventTypes.FILE_READ).count()
assertThat(readCount).isAtMost(10)
}
The alternative is handling the boilerplate warmup and jfrEvents.reset() calls in the test itself, a process that would be better handled by an annotation (especially once #126 comes to fruition).
The text was updated successfully, but these errors were encountered:
Hey, that's an interesting proposal. Instead of adding a new annotation like @WarmUp, how about we add support for @EnableEvent() to the existing @Before/@BeforeAll annotations? A PR for implementing this (as for #126) would be more than welcome.
After this discussion, I definitely did not seek out enough alternative solutions within the API. The withPath filter combined with jfrEvents.reset() definitely gives me everything I need.
For my testing purposes, I wish to limit certain IO events and prevent regression against these metrics. Consider the following example:
Every
FILE_READ
event will be counted, including IO triggered by class loading. This is probably desired from jfrunit’s perspective but can make writing tests a bit cumbersome.Filtering by
jfrEvents
by class is possible but the test should probably remain agnostic as to where the IO originates, especially when reads are delegated to an external dependency.This forces a workaround like the following:
The alternative is handling the boilerplate warmup and
jfrEvents.reset()
calls in the test itself, a process that would be better handled by an annotation (especially once #126 comes to fruition).The text was updated successfully, but these errors were encountered: