Add a wait to a test that uses a database generated timestamp
This commit is contained in:
parent
97dd838954
commit
3704dad923
|
@ -11,6 +11,7 @@ import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateError;
|
||||||
import org.hibernate.annotations.CurrentTimestamp;
|
import org.hibernate.annotations.CurrentTimestamp;
|
||||||
import org.hibernate.dialect.SybaseASEDialect;
|
import org.hibernate.dialect.SybaseASEDialect;
|
||||||
import org.hibernate.tuple.GenerationTiming;
|
import org.hibernate.tuple.GenerationTiming;
|
||||||
|
@ -53,6 +54,9 @@ public class MultipleGeneratedValuesTests {
|
||||||
|
|
||||||
created.name = "first";
|
created.name = "first";
|
||||||
|
|
||||||
|
//We need to wait a little to make sure the timestamps produced are different
|
||||||
|
waitALittle();
|
||||||
|
|
||||||
// then changing
|
// then changing
|
||||||
final GeneratedInstantEntity merged = scope.fromTransaction( (session) -> {
|
final GeneratedInstantEntity merged = scope.fromTransaction( (session) -> {
|
||||||
return (GeneratedInstantEntity) session.merge( created );
|
return (GeneratedInstantEntity) session.merge( created );
|
||||||
|
@ -70,6 +74,9 @@ public class MultipleGeneratedValuesTests {
|
||||||
assertThat( merged.createdAt2 ).isEqualTo( created.createdAt2 );
|
assertThat( merged.createdAt2 ).isEqualTo( created.createdAt2 );
|
||||||
assertThat( merged.updatedAt2 ).isNotEqualTo( created.updatedAt2 );
|
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..
|
// lastly, make sure we can load it..
|
||||||
final GeneratedInstantEntity loaded = scope.fromTransaction( (session) -> {
|
final GeneratedInstantEntity loaded = scope.fromTransaction( (session) -> {
|
||||||
return session.get( GeneratedInstantEntity.class, 1 );
|
return session.get( GeneratedInstantEntity.class, 1 );
|
||||||
|
@ -116,4 +123,13 @@ public class MultipleGeneratedValuesTests {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void waitALittle() {
|
||||||
|
try {
|
||||||
|
Thread.sleep( 10 );
|
||||||
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
|
throw new HibernateError( "Unexpected wakeup from test sleep" );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue