From 1d0731d6b3d56e24c2bb2655436da688271585b5 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Fri, 25 Aug 2023 17:06:45 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=B8=BB=E9=94=AE=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/coretest/IdGenTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IdGenTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IdGenTest.java index 3db21473..2d075d5a 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IdGenTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/IdGenTest.java @@ -18,6 +18,7 @@ package com.mybatisflex.coretest; import com.mybatisflex.core.keygen.IKeyGenerator; import com.mybatisflex.core.keygen.KeyGeneratorFactory; +import com.mybatisflex.core.keygen.KeyGenerators; import org.junit.Assert; import org.junit.Test; @@ -33,9 +34,20 @@ public class IdGenTest { @Test public void snowFlakeID() { - int size = 10; + int size = 10_0000; long[] ids = new long[size]; - IKeyGenerator keyGenerator = KeyGeneratorFactory.getKeyGenerator("snowFlakeId"); + IKeyGenerator keyGenerator = KeyGeneratorFactory.getKeyGenerator(KeyGenerators.snowFlakeId); + for (int i = 0; i < size; i++) { + ids[i] = (Long) keyGenerator.generate(null, null); + } + Assert.assertEquals(size, LongStream.of(ids).distinct().count()); + } + + @Test + public void flexID() { + int size = 100_0000; + long[] ids = new long[size]; + IKeyGenerator keyGenerator = KeyGeneratorFactory.getKeyGenerator(KeyGenerators.flexId); for (int i = 0; i < size; i++) { ids[i] = (Long) keyGenerator.generate(null, null); }