From 74c20efdd25f9a1ee6a4fcc1c1837d8dd83e39d2 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 31 May 2023 19:08:13 +0800 Subject: [PATCH] build: id generate demo --- .../system/controller/TestRIdGenerator.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestRIdGenerator.java diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestRIdGenerator.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestRIdGenerator.java new file mode 100644 index 0000000000..ad06b97732 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestRIdGenerator.java @@ -0,0 +1,33 @@ +package io.metersphere.system.controller; + +import jakarta.annotation.Resource; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.redisson.Redisson; +import org.redisson.api.RIdGenerator; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +@AutoConfigureMockMvc +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class TestRIdGenerator { + @Resource + private Redisson redisson; + + @Test + public void testId1() throws Exception { + String projectId = "projectId"; + RIdGenerator idGenerator = redisson.getIdGenerator(projectId); + long capacity = 1000000; // 容量,代表每个项目最多可以生成多少个id + long init = 1000000_1000001L; // 代表从100_0000_100_0001开始,项目的num + idGenerator.tryInit(init, capacity); + long nextId = idGenerator.nextId(); + Assertions.assertEquals(nextId, init); +// for (int i = 0; i < capacity; i++) { +// long nextId = idGenerator.nextId(); +// } + } +}