Skip to content

Commit 07eb300

Browse files
committed
ULID sequence guarantee test
1 parent 538554b commit 07eb300

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

projects/java/build.gradle

+11-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@ repositories {
1919
}
2020

2121
dependencies {
22+
// Lombok
23+
compileOnly 'org.projectlombok:lombok:1.18.20'
24+
annotationProcessor 'org.projectlombok:lombok'
25+
26+
// Spring Boot
2227
implementation 'org.springframework.boot:spring-boot-starter'
2328
implementation 'org.springframework.boot:spring-boot-starter-web'
24-
implementation 'org.apache.commons:commons-text:1.9'
25-
implementation group: 'com.opencsv', name: 'opencsv', version: '5.5.2'
2629
implementation 'org.springframework.boot:spring-boot-starter-test'
27-
compileOnly 'org.projectlombok:lombok:1.18.20'
28-
annotationProcessor 'org.projectlombok:lombok'
2930
implementation 'org.springframework.boot:spring-boot-starter-test'
3031
testImplementation 'org.springframework.boot:spring-boot-starter-test'
32+
33+
// Utils
34+
implementation 'org.apache.commons:commons-text:1.9'
35+
implementation group: 'com.opencsv', name: 'opencsv', version: '5.5.2'
36+
implementation 'com.github.f4b6a3:ulid-creator:5.2.3'
37+
3138
}
3239

3340
test {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.tistory.shanepark.uuid;
2+
3+
import com.github.f4b6a3.ulid.Ulid;
4+
import com.github.f4b6a3.ulid.UlidCreator;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.UUID;
9+
10+
public class UlidTest {
11+
static final int LOOP_COUNT = 100;
12+
13+
public static void main(String[] args) throws InterruptedException {
14+
List<String> ulids = new ArrayList<>();
15+
List<String> uuids = new ArrayList<>();
16+
for (int i = 0; i < LOOP_COUNT; i++) {
17+
Ulid ulid = createUlid();
18+
UUID uuid = ulid.toUuid();
19+
ulids.add(ulid.toString());
20+
uuids.add(uuid.toString());
21+
System.out.printf("ulid = %s, uuid = %s LOOP : %d/%d\n", ulid, uuid, i, LOOP_COUNT);
22+
Thread.sleep(200);
23+
}
24+
25+
// check whether those two lists are sorted
26+
for (int i = 0; i < LOOP_COUNT - 1; i++) {
27+
if (ulids.get(i).compareTo(ulids.get(i + 1)) > 0) {
28+
throw new RuntimeException("ulid is not sorted");
29+
}
30+
if (uuids.get(i).compareTo(uuids.get(i + 1)) > 0) {
31+
throw new RuntimeException("uuid is not sorted");
32+
}
33+
}
34+
}
35+
36+
private static Ulid createUlid() {
37+
return UlidCreator.getMonotonicUlid();
38+
}
39+
40+
}

0 commit comments

Comments
 (0)