@@ -35,20 +35,19 @@ class GuidTest {
3535 @ Resource
3636 private Guid guid ;
3737
38- @ Disabled ("very slow " )
38+ @ Disabled ("调整sequence的配置,12bit可达到50w/s " )
3939 @ Test
4040 void benchmarkNextId () throws InterruptedException {
41- Set <Long > rst = Collections .synchronizedSet (new HashSet <>());
4241 CountDownLatch c = new CountDownLatch (3 );
4342
4443 Thread t1 = new Thread (() -> {
45- consumeGuid (rst , c );
44+ consumeGuid (c );
4645 });
4746 Thread t2 = new Thread (() -> {
48- consumeGuid (rst , c );
47+ consumeGuid (c );
4948 });
5049 Thread t3 = new Thread (() -> {
51- consumeGuid (rst , c );
50+ consumeGuid (c );
5251 });
5352 t1 .start ();
5453 t2 .start ();
@@ -58,19 +57,26 @@ void benchmarkNextId() throws InterruptedException {
5857 log .info ("done!" );
5958 }
6059
61- private void consumeGuid (Set < Long > rst , CountDownLatch c ) {
60+ private void consumeGuid (CountDownLatch c ) {
6261 for (int i = 0 ; i < 10000000 ; i ++) {
63- long id = guid .nextId ();
64- assertFalse (rst .contains (id ));
65- rst .add (id );
62+ assertDoesNotThrow (() -> guid .nextId ());
6663 }
6764 c .countDown ();
6865 }
6966
7067 @ Test
7168 void nextId () {
72- assertTrue (guid .nextId () > 0 );
73- assertTrue (guid .nextId () > 0 );
69+ Set <Long > rst = Collections .synchronizedSet (new HashSet <>());
70+ long last = 0 ;
71+
72+ for (int i = 0 ; i < 100 ; i ++) {
73+ // 加速消耗直到一个时间片內序号都耗尽
74+ long id = guid .nextId ();
75+ assertTrue (id > last );
76+ assertFalse (rst .contains (id ));
77+ rst .add (id );
78+ last = id ;
79+ }
7480 }
7581
7682 @ Test
@@ -80,7 +86,7 @@ void nextId2() {
8086
8187 @ Test
8288 void parseDateTime () {
83- assertEquals (LocalDateTime .parse ("2075-04-23T11:50:00.727 " ), guid .parseDateTime (3484645589754769408L ));
89+ assertEquals (LocalDateTime .parse ("2022-08-28T00:22:33.251 " ), guid .parseDateTime (13611969357836288L ));
8490 }
8591
8692}
0 commit comments