Add a wait to a test that uses a database generated timestamp

This commit is contained in:
Christian Beikov 2022-01-05 10:33:38 +01:00
parent 97dd838954
commit 3704dad923
1 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.HibernateError;
import org.hibernate.annotations.CurrentTimestamp;
import org.hibernate.dialect.SybaseASEDialect;
import org.hibernate.tuple.GenerationTiming;
@ -53,6 +54,9 @@ public class MultipleGeneratedValuesTests {
created.name = "first";
//We need to wait a little to make sure the timestamps produced are different
waitALittle();
// then changing
final GeneratedInstantEntity merged = scope.fromTransaction( (session) -> {
return (GeneratedInstantEntity) session.merge( created );
@ -70,6 +74,9 @@ public class MultipleGeneratedValuesTests {
assertThat( merged.createdAt2 ).isEqualTo( created.createdAt2 );
assertThat( merged.updatedAt2 ).isNotEqualTo( created.updatedAt2 );
//We need to wait a little to make sure the timestamps produced are different
waitALittle();
// lastly, make sure we can load it..
final GeneratedInstantEntity loaded = scope.fromTransaction( (session) -> {
return session.get( GeneratedInstantEntity.class, 1 );
@ -116,4 +123,13 @@ public class MultipleGeneratedValuesTests {
this.name = name;
}
}
private static void waitALittle() {
try {
Thread.sleep( 10 );
}
catch (InterruptedException e) {
throw new HibernateError( "Unexpected wakeup from test sleep" );
}
}
}