File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/rfc9562 Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .hibernate .orm .test .id .uuid .rfc9562 ;
2+
3+ import java .util .UUID ;
4+
5+ import org .hibernate .engine .spi .SharedSessionContractImplementor ;
6+ import org .hibernate .id .uuid .UuidV6ValueGenerator ;
7+ import org .hibernate .id .uuid .UuidV7ValueGenerator ;
8+ import org .hibernate .id .uuid .UuidValueGenerator ;
9+
10+ import org .junit .jupiter .api .Test ;
11+
12+ import static org .assertj .core .api .Assertions .assertThat ;
13+ import static org .mockito .Mockito .mock ;
14+
15+ public class UUidV6V7GenetartorTest {
16+
17+ private static final UUID NIL_UUID = new UUID ( 0L , 0L );
18+ private static final int ITERATIONS = 1_000_000 ;
19+
20+ @ Test
21+ void testMonotonicityUuid6 () {
22+ testMonotonicity ( new UuidV6ValueGenerator () );
23+ }
24+
25+ @ Test
26+ void testMonotonicityUuid7 () {
27+ testMonotonicity ( new UuidV7ValueGenerator () );
28+ }
29+
30+ private static void testMonotonicity (UuidValueGenerator generator ) {
31+ final SharedSessionContractImplementor session = mock ( SharedSessionContractImplementor .class );
32+ final UUID [] uuids = new UUID [ITERATIONS + 1 ];
33+ uuids [0 ] = NIL_UUID ;
34+ for ( int n = 1 ; n <= ITERATIONS ; ++n ) {
35+ uuids [n ] = generator .generateUuid ( session );
36+ }
37+
38+ for ( var n = 0 ; n < ITERATIONS ; ++n ) {
39+ assertThat ( uuids [n + 1 ].toString () ).isGreaterThan ( uuids [n ].toString () );
40+ assertThat ( uuids [n + 1 ] ).isGreaterThan ( uuids [n ] );
41+ }
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments