HHH-18109 Remove executionTime from JFR events and clear JFR events before test

This commit is contained in:
Christian Beikov 2024-06-04 16:09:22 +02:00
parent 78cf552065
commit 04d86a8160
1 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package org.hibernate.event.jfr; package org.hibernate.event.jfr;
import java.time.Duration;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -33,6 +34,7 @@ public class JdbcPreparedStatementEventTests {
@EnableEvent(JdbcPreparedStatementCreationEvent.NAME) @EnableEvent(JdbcPreparedStatementCreationEvent.NAME)
@EnableEvent(JdbcPreparedStatementExecutionEvent.NAME) @EnableEvent(JdbcPreparedStatementExecutionEvent.NAME)
public void testJdbcPreparedStatementEvent(SessionFactoryScope scope) { public void testJdbcPreparedStatementEvent(SessionFactoryScope scope) {
jfrEvents.reset();
scope.inTransaction( scope.inTransaction(
session -> { session -> {
session.createQuery( "select t from TestEntity t" ).list(); session.createQuery( "select t from TestEntity t" ).list();
@ -72,7 +74,7 @@ public class JdbcPreparedStatementEventTests {
jfrEvents.reset(); jfrEvents.reset();
scope.inTransaction( scope.inTransaction(
session -> { session -> {
// No-op
} }
); );
final List<RecordedEvent> events = jfrEvents.events() final List<RecordedEvent> events = jfrEvents.events()
@ -93,6 +95,7 @@ public class JdbcPreparedStatementEventTests {
@EnableEvent(JdbcPreparedStatementCreationEvent.NAME) @EnableEvent(JdbcPreparedStatementCreationEvent.NAME)
@EnableEvent(JdbcPreparedStatementExecutionEvent.NAME) @EnableEvent(JdbcPreparedStatementExecutionEvent.NAME)
public void testJdbcPreparedStatementEventStoredProcedure(SessionFactoryScope scope) { public void testJdbcPreparedStatementEventStoredProcedure(SessionFactoryScope scope) {
jfrEvents.reset();
scope.inTransaction( scope.inTransaction(
session -> { session -> {
ProcedureCall call = session.createStoredProcedureCall("DB_OBJECT_SQL", String.class) ProcedureCall call = session.createStoredProcedureCall("DB_OBJECT_SQL", String.class)
@ -120,14 +123,14 @@ public class JdbcPreparedStatementEventTests {
RecordedEvent preparedStatementCreationEvent = events.get( 0 ); RecordedEvent preparedStatementCreationEvent = events.get( 0 );
assertThat( preparedStatementCreationEvent.getEventType().getName() ) assertThat( preparedStatementCreationEvent.getEventType().getName() )
.isEqualTo( JdbcPreparedStatementCreationEvent.NAME ); .isEqualTo( JdbcPreparedStatementCreationEvent.NAME );
assertThat( preparedStatementCreationEvent.getLong( "executionTime" ) ).isGreaterThan( 0 ); assertThat( preparedStatementCreationEvent.getDuration() ).isGreaterThan( Duration.ZERO );
assertThat( preparedStatementCreationEvent.getString( "sql" ).toLowerCase( Locale.ROOT ) ) assertThat( preparedStatementCreationEvent.getString( "sql" ).toLowerCase( Locale.ROOT ) )
.contains( "{call " ); .contains( "{call " );
RecordedEvent preparedStatementExecutionEvent = events.get( 1 ); RecordedEvent preparedStatementExecutionEvent = events.get( 1 );
assertThat( preparedStatementExecutionEvent.getEventType().getName() ) assertThat( preparedStatementExecutionEvent.getEventType().getName() )
.isEqualTo( JdbcPreparedStatementExecutionEvent.NAME ); .isEqualTo( JdbcPreparedStatementExecutionEvent.NAME );
assertThat( preparedStatementExecutionEvent.getLong( "executionTime" ) ).isGreaterThan( 0 ); assertThat( preparedStatementExecutionEvent.getDuration() ).isGreaterThan( Duration.ZERO );
assertThat( preparedStatementExecutionEvent.getString( "sql" ) ) assertThat( preparedStatementExecutionEvent.getString( "sql" ) )
.isEqualTo( preparedStatementCreationEvent.getString( "sql" ) ); .isEqualTo( preparedStatementCreationEvent.getString( "sql" ) );
} }