Skip to content

Commit d7e79db

Browse files
committed
HHH-18377 Test cases to check monofonicity of generated version 6 & version 7 UUID's
1 parent 1021b14 commit d7e79db

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)