feat: 1.2.0
1. 添加测试用例
This commit is contained in:
parent
669dde1588
commit
f23ad83b6d
@ -71,6 +71,7 @@ CREATE TABLE `retry_task_0`
|
||||
KEY `idx_group_name_scene_name` (`group_name`, `scene_name`),
|
||||
KEY `idx_retry_status` (`retry_status`),
|
||||
KEY `idx_idempotent_id` (`idempotent_id`),
|
||||
KEY `idx_biz_no` (`biz_no`),
|
||||
UNIQUE KEY `uk_name_unique_id` (`group_name`, `unique_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='重试表'
|
||||
;
|
||||
@ -93,7 +94,9 @@ CREATE TABLE `retry_task_log`
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_group_name_scene_name` (`group_name`, `scene_name`),
|
||||
KEY `idx_retry_status` (`retry_status`),
|
||||
KEY `idx_idempotent_id` (`idempotent_id`)
|
||||
KEY `idx_idempotent_id` (`idempotent_id`),
|
||||
KEY `idx_unique_id` (`unique_id`),
|
||||
KEY `idx_biz_no` (`biz_no`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='重试日志表'
|
||||
;
|
||||
|
||||
|
@ -20,11 +20,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -173,7 +171,7 @@ public class SegmentIdGenerator implements IdGenerator, Lifecycle {
|
||||
if (!buffer.isInitOk()) {
|
||||
try {
|
||||
updateSegmentFromDb(key, buffer.getCurrent());
|
||||
LogUtils.info(log, "Init buffer. Update leafkey {} {} from db", key, buffer.getCurrent());
|
||||
LogUtils.info(log, "Init buffer. Update key {} {} from db", key, buffer.getCurrent());
|
||||
buffer.setInitOk(true);
|
||||
} catch (Exception e) {
|
||||
LogUtils.warn(log, "Init buffer {} exception", buffer.getCurrent(), e);
|
||||
@ -293,7 +291,7 @@ public class SegmentIdGenerator implements IdGenerator, Lifecycle {
|
||||
roll += 1;
|
||||
if(roll > 10000) {
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(2);
|
||||
TimeUnit.MILLISECONDS.sleep(20);
|
||||
break;
|
||||
} catch (InterruptedException e) {
|
||||
LogUtils.warn(log,"Thread {} Interrupted",Thread.currentThread().getName());
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.aizuda.easy.retry.server.support.generator.id;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.log.LogUtils;
|
||||
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
|
||||
import com.aizuda.easy.retry.server.support.generator.IdGenerator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* 测试多线程情况下号段模式的运行情况
|
||||
*
|
||||
* @author: shuguang.zhang
|
||||
* @date : 2023-05-06 09:16
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class SegmentIdGeneratorTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("segmentIdGenerator")
|
||||
private IdGenerator idGenerator;
|
||||
|
||||
@Test
|
||||
public void idGeneratorTest() throws InterruptedException {
|
||||
|
||||
// step: 100, cpu: 4 memory: 16G, 线程1-150之间出现异常id:-3的情况较少。
|
||||
// 如果有特殊需求可以提高step, 可通过系统配置: SystemProperties#step属性进行配置
|
||||
Set<String> idSet = new HashSet<>();
|
||||
int size = 500;
|
||||
CountDownLatch count = new CountDownLatch(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
count.countDown();
|
||||
|
||||
String id = idGenerator.idGenerator("example_group");
|
||||
LogUtils.info(log, "id:[{}]", id);
|
||||
if (Long.parseLong(id) < 0) {
|
||||
throw new EasyRetryServerException("exception id");
|
||||
} else if (idSet.contains(id)) {
|
||||
throw new EasyRetryServerException("duplicate id [{}]", id);
|
||||
} else {
|
||||
idSet.add(id);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
count.await();
|
||||
}
|
||||
}
|
@ -102,6 +102,10 @@ export default {
|
||||
title: '分区',
|
||||
dataIndex: 'groupPartition',
|
||||
needTotal: true
|
||||
},
|
||||
{
|
||||
title: 'ID生成模式',
|
||||
dataIndex: 'idGeneratorModeName'
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
|
Loading…
Reference in New Issue
Block a user