feat:2.3.0
修复回调执行器获取的错误问题
This commit is contained in:
parent
8e5d3e76f5
commit
bea842178f
@ -127,13 +127,14 @@ public class ExecCallbackUnitActor extends AbstractActor {
|
||||
|
||||
// 回调参数
|
||||
RetryCallbackDTO retryCallbackDTO = new RetryCallbackDTO();
|
||||
retryCallbackDTO.setIdempotentId(retryTask.getIdempotentId());
|
||||
retryCallbackDTO.setIdempotentId(callbackTask.getIdempotentId());
|
||||
// 重试任务的状态
|
||||
retryCallbackDTO.setRetryStatus(retryTask.getRetryStatus());
|
||||
retryCallbackDTO.setArgsStr(retryTask.getArgsStr());
|
||||
retryCallbackDTO.setScene(retryTask.getSceneName());
|
||||
retryCallbackDTO.setGroup(retryTask.getGroupName());
|
||||
retryCallbackDTO.setExecutorName(retryTask.getExecutorName());
|
||||
retryCallbackDTO.setUniqueId(retryTask.getUniqueId());
|
||||
retryCallbackDTO.setArgsStr(callbackTask.getArgsStr());
|
||||
retryCallbackDTO.setScene(callbackTask.getSceneName());
|
||||
retryCallbackDTO.setGroup(callbackTask.getGroupName());
|
||||
retryCallbackDTO.setExecutorName(callbackTask.getExecutorName());
|
||||
retryCallbackDTO.setUniqueId(callbackTask.getUniqueId());
|
||||
|
||||
RpcClient rpcClient = RequestBuilder.<RpcClient, Result>newBuilder()
|
||||
.hostPort(serverNode.getHostPort())
|
||||
|
@ -2,6 +2,7 @@ package com.aizuda.easy.retry.server.support.generator.task;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
|
||||
import com.aizuda.easy.retry.common.core.log.LogUtils;
|
||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
@ -120,6 +121,7 @@ public abstract class AbstractGenerator implements TaskGenerator {
|
||||
retryTask.setGroupName(taskContext.getGroupName());
|
||||
retryTask.setSceneName(taskContext.getSceneName());
|
||||
retryTask.setRetryStatus(initStatus(taskContext));
|
||||
retryTask.setBizNo(Optional.ofNullable(retryTask.getBizNo()).orElse(StrUtil.EMPTY));
|
||||
retryTask.setCreateDt(now);
|
||||
retryTask.setUpdateDt(now);
|
||||
|
||||
|
@ -38,8 +38,8 @@ import java.util.List;
|
||||
public class RetryTaskMoreThresholdAlarmSchedule extends AbstractSchedule implements Lifecycle {
|
||||
private static String retryTaskMoreThresholdTextMessageFormatter =
|
||||
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试数据监控</font> \n" +
|
||||
"> 名称:{} \n" +
|
||||
"> 时间:{} \n" +
|
||||
"> 组名称:{} \n" +
|
||||
"> 告警时间:{} \n" +
|
||||
"> **共计:{}** \n";
|
||||
|
||||
private final EasyRetryAlarmFactory easyRetryAlarmFactory;
|
||||
|
31
example/.gitignore
vendored
31
example/.gitignore
vendored
@ -1,31 +0,0 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
.flattened-pom.xml
|
@ -1,13 +0,0 @@
|
||||
FROM openjdk:8-jdk-alpine
|
||||
MAINTAINER www.byteblogs.com
|
||||
|
||||
ADD ./target/easy-retry-example.jar easy-retry-example.jar
|
||||
|
||||
#对外暴漏的端口号
|
||||
EXPOSE 8088
|
||||
|
||||
WORKDIR /
|
||||
|
||||
#开机启动
|
||||
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /easy-retry-example.jar $PARAMS"]
|
||||
|
100
example/pom.xml
100
example/pom.xml
@ -1,100 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.5.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>example</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<name>example</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>easy-retry-client-starter</artifactId>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.28</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.46</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>4.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>easy-retry-example</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,42 +0,0 @@
|
||||
create database demo;
|
||||
|
||||
CREATE TABLE `school`
|
||||
(
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(64) NOT NULL COMMENT '名称',
|
||||
`address` varchar(128) NOT NULL COMMENT '密码',
|
||||
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学校';
|
||||
|
||||
CREATE TABLE `student`
|
||||
(
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(64) NOT NULL COMMENT '姓名',
|
||||
`age` tinyint NOT NULL COMMENT '年龄',
|
||||
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学生';
|
||||
|
||||
CREATE TABLE `teacher`
|
||||
(
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`name` varchar(64) NOT NULL COMMENT '姓名',
|
||||
`age` tinyint NOT NULL COMMENT '年龄',
|
||||
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='教师';
|
||||
|
||||
CREATE TABLE `school_student_teacher`
|
||||
(
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`school_id` bigint(20) NOT NULL COMMENT '学校id',
|
||||
`teacher_id` bigint(20) NOT NULL COMMENT '教师id',
|
||||
`student_id` bigint(20) NOT NULL COMMENT '学生id',
|
||||
`create_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学校学生老师表';
|
@ -1,24 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.aizuda.easy.retry.client.starter.EnableEasyRetry;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
//import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients(basePackages = "com.example.client")
|
||||
@EnableEasyRetry(group = "example_group")
|
||||
@EnableAspectJAutoProxy
|
||||
//@EnableTransactionManagement(order = Ordered.LOWEST_PRECEDENCE - 10)
|
||||
@EnableTransactionManagement
|
||||
public class ExampleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExampleApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.plugin.RequestHeaderPlugins;
|
||||
import com.aizuda.easy.retry.client.core.plugin.ResponseHeaderPlugins;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* RestTemplate 拦截器
|
||||
*
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-04-17 15:22
|
||||
*/
|
||||
public class ExampleClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
|
||||
|
||||
before(request);
|
||||
|
||||
ClientHttpResponse execute = execution.execute(request, body);
|
||||
|
||||
after(execute);
|
||||
|
||||
return execute;
|
||||
}
|
||||
|
||||
private void after(ClientHttpResponse execute) {
|
||||
ResponseHeaderPlugins.responseHeader(execute.getHeaders());
|
||||
}
|
||||
|
||||
private void before(HttpRequest request) {
|
||||
|
||||
Map<String, String> header = RequestHeaderPlugins.requestHeader();
|
||||
HttpHeaders headers = request.getHeaders();
|
||||
header.forEach((key, value) -> headers.add(key, value));
|
||||
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.plugin.RequestHeaderPlugins;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-05-16 15:05
|
||||
*/
|
||||
@Component
|
||||
public class ExampleFeignRequestInterceptor implements RequestInterceptor {
|
||||
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
|
||||
Map<String, String> header = RequestHeaderPlugins.requestHeader();
|
||||
header.forEach((key, value) -> requestTemplate.header(key, value));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.example.client;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-05-16 15:32
|
||||
*/
|
||||
@FeignClient(name = "daemoClient", url = "http://127.0.0.1:8089")
|
||||
public interface DemoClient {
|
||||
|
||||
@GetMapping("/school/id")
|
||||
Result get();
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.example.client;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.plugin.ResponseHeaderPlugins;
|
||||
import feign.FeignException;
|
||||
import feign.Response;
|
||||
import feign.codec.DecodeException;
|
||||
import feign.codec.Decoder;
|
||||
import feign.codec.StringDecoder;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.cloud.openfeign.support.SpringDecoder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-05-17 08:03
|
||||
*/
|
||||
@Configuration
|
||||
public class FeignConfig {
|
||||
|
||||
@Bean
|
||||
public Decoder decoder(@Autowired HttpMessageConverters httpMessageConverters) {
|
||||
|
||||
ObjectFactory<HttpMessageConverters> objectFactory = () -> httpMessageConverters;
|
||||
|
||||
return new SpringDecoder(objectFactory) {
|
||||
@Override
|
||||
public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
|
||||
|
||||
Map<String, Collection<String>> headers = response.headers();
|
||||
|
||||
Map<String, List<String>> header = new HashMap<>();
|
||||
headers.forEach((key, value)-> {
|
||||
header.put(key, (List<String>) value);
|
||||
});
|
||||
|
||||
ResponseHeaderPlugins.responseHeader(header);
|
||||
return super.decode(response, type);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.example.config;
|
||||
|
||||
import com.example.ExampleClientHttpRequestInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-09 14:19
|
||||
*/
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
|
||||
RestTemplate restTemplate = new RestTemplate(factory);
|
||||
restTemplate.setInterceptors(Collections.singletonList(new ExampleClientHttpRequestInterceptor()));
|
||||
return restTemplate;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHttpRequestFactory okHttp3ClientHttpRequestFactory(){
|
||||
OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory();
|
||||
factory.setReadTimeout(5000);
|
||||
factory.setConnectTimeout(5000);
|
||||
factory.setConnectTimeout(3000);
|
||||
factory.setWriteTimeout(5000);
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学校 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/school")
|
||||
public class SchoolController {
|
||||
|
||||
@GetMapping("/id")
|
||||
public Result getSchool(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
String header = request.getHeader(SystemConstants.EASY_RETRY_HEAD_KEY);
|
||||
System.out.println(header);
|
||||
|
||||
if (RetrySiteSnapshot.isRetryFlow()) {
|
||||
response.addHeader(SystemConstants.EASY_RETRY_STATUS_CODE_KEY, SystemConstants.EASY_RETRY_STATUS_CODE);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
throw new UnsupportedOperationException("异常测试");
|
||||
}
|
||||
|
||||
return new Result(0, "school");
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.example.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学校学生老师表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/school-student-teacher")
|
||||
public class SchoolStudentTeacherController {
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.example.controller;
|
||||
|
||||
|
||||
import com.aizuda.easy.retry.common.core.annotation.OriginalControllerReturnValue;
|
||||
import com.example.demo.TestExistsTransactionalRetryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学生 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/student")
|
||||
public class StudentController {
|
||||
|
||||
@Autowired
|
||||
private TestExistsTransactionalRetryService testExistsTransactionalRetryService;
|
||||
|
||||
@GetMapping("query")
|
||||
@OriginalControllerReturnValue
|
||||
public String get() {
|
||||
return testExistsTransactionalRetryService.testSimpleInsert(UUID.randomUUID().toString());
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 教师 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/teacher")
|
||||
public class TeacherController {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@GetMapping("test-ddl")
|
||||
public Result testDDL() {
|
||||
Result result = restTemplate.getForObject("http://127.0.0.1:8088/school/id", Result.class);
|
||||
result = restTemplate.getForObject("http://127.0.0.1:8088/school/id", Result.class);
|
||||
result = restTemplate.getForObject("http://127.0.0.1:8088/school/id", Result.class);
|
||||
result = restTemplate.getForObject("http://127.0.0.1:8088/school/id", Result.class);
|
||||
|
||||
if (result.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException(result.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("test-status-code")
|
||||
@Retryable(scene = "testStatusCode", isThrowException = false)
|
||||
public Result testStatusCode() {
|
||||
Result result = restTemplate.getForObject("http://127.0.0.1:8088/school/id", Result.class);
|
||||
|
||||
if (result.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException(result.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.client.DemoClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-05-19 08:21
|
||||
*/
|
||||
@RequestMapping("/ddl")
|
||||
@RestController
|
||||
public class TestDdlController {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private DemoClient demoClient;
|
||||
|
||||
@GetMapping("rest-template")
|
||||
public Result testDDL() {
|
||||
Result result = restTemplate.getForObject("http://127.0.0.1:8088/school/id", Result.class);
|
||||
|
||||
if (result.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException(result.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("test-feign")
|
||||
public Result feign() {
|
||||
Result result = demoClient.get();
|
||||
if (result.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException(result.getMessage());
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("test-retry-header-controller-transfer")
|
||||
@Retryable(scene = "testRetryHeaderControllerTransfer", retryStrategy = RetryType.ONLY_LOCAL)
|
||||
public Result testRetryHeaderTransfer() {
|
||||
Result result = demoClient.get();
|
||||
if (result.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException(result.getMessage());
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.client.DemoClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-05-19 08:24
|
||||
*/
|
||||
@RequestMapping("/status-code")
|
||||
@RestController
|
||||
public class TestStatusCodeController {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private DemoClient demoClient;
|
||||
|
||||
@GetMapping("rest-template")
|
||||
@Retryable(scene = "testRestTemplateStatusCode")
|
||||
public Result testRestTemplateStatusCode() {
|
||||
Result result = restTemplate.getForObject("http://127.0.0.1:8088/school/id", Result.class);
|
||||
|
||||
if (result.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException(result.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("feign")
|
||||
@Retryable(scene = "testFeignStatusCode")
|
||||
public Result testFeignStatusCode() {
|
||||
Result result = demoClient.get();
|
||||
|
||||
if (result.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException(result.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.ExecutorMethodRegister;
|
||||
import com.aizuda.easy.retry.client.core.strategy.ExecutorMethod;
|
||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 测试手动重试并同步上报任务
|
||||
*
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:07
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ExecutorMethodRegister(scene = CustomAsyncCreateTask.SCENE, async = true, forceReport = true)
|
||||
@Slf4j
|
||||
public class CustomAsyncCreateTask implements ExecutorMethod {
|
||||
|
||||
public static final String SCENE = "customAsyncCreateTask";
|
||||
|
||||
@Override
|
||||
public Object doExecute(Object obj) {
|
||||
log.info(SCENE + " params:[{}]", JsonUtil.toJsonString(obj));
|
||||
return "测试成功";
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.ExecutorMethodRegister;
|
||||
import com.aizuda.easy.retry.client.core.strategy.ExecutorMethod;
|
||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 测试手动重试并同步上报任务
|
||||
*
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:07
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ExecutorMethodRegister(scene = CustomSyncCreateTask.SCENE, async = false, timeout = 10000, unit = TimeUnit.MILLISECONDS, forceReport = true)
|
||||
@Slf4j
|
||||
public class CustomSyncCreateTask implements ExecutorMethod {
|
||||
|
||||
public static final String SCENE = "customSyncCreateTask";
|
||||
|
||||
@Override
|
||||
public Object doExecute(Object obj) {
|
||||
log.info(SCENE + " params:[{}]", JsonUtil.toJsonString(obj));
|
||||
return "测试成功";
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.strategy.ExecutorMethod;
|
||||
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:07
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MyExecutorMethod implements ExecutorMethod {
|
||||
|
||||
@Override
|
||||
public Object doExecute(Object params) {
|
||||
log.info("测试自定义重试方法 MyExecutorMethod params:[{}]", JsonUtil.toJsonString(params));
|
||||
return "测试成功";
|
||||
}
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.client.core.exception.EasyRetryClientException;
|
||||
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot;
|
||||
import com.aizuda.easy.retry.client.core.intercepter.RetrySiteSnapshot.EnumStage;
|
||||
import com.aizuda.easy.retry.client.core.retryer.EasyRetryTemplate;
|
||||
import com.aizuda.easy.retry.client.core.retryer.RetryTaskTemplateBuilder;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.model.Zoo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-27 22:37
|
||||
*/
|
||||
@Component
|
||||
public class NestMethodService {
|
||||
|
||||
@Autowired
|
||||
private TestExistsTransactionalRetryService testExistsTransactionalRetryService;
|
||||
@Autowired
|
||||
private RemoteService remoteService;
|
||||
|
||||
@Retryable(scene = "testNestMethod" , isThrowException = false)
|
||||
@Transactional
|
||||
public void testNestMethod() {
|
||||
testExistsTransactionalRetryService.testSimpleInsert(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@Retryable(scene = "testNestMethodForCustomSyncCreateTask" , isThrowException = false)
|
||||
@Transactional
|
||||
public void testNestMethodForCustomSyncCreateTask() {
|
||||
|
||||
if (RetrySiteSnapshot.getStage() == null || RetrySiteSnapshot.getStage() == EnumStage.LOCAL.getStage()) {
|
||||
throw new EasyRetryClientException("测试注解重试和手动重试");
|
||||
}
|
||||
|
||||
// 同步强制上报
|
||||
Zoo zoo = new Zoo();
|
||||
zoo.setNow(LocalDateTime.now());
|
||||
EasyRetryTemplate retryTemplate = RetryTaskTemplateBuilder.newBuilder()
|
||||
.withExecutorMethod(CustomSyncCreateTask.class)
|
||||
.withParam(zoo)
|
||||
.withScene(CustomSyncCreateTask.SCENE)
|
||||
.build();
|
||||
|
||||
retryTemplate.executeRetry();
|
||||
|
||||
// 异步强制上报
|
||||
zoo.setNow(LocalDateTime.now());
|
||||
retryTemplate = RetryTaskTemplateBuilder.newBuilder()
|
||||
.withExecutorMethod(CustomAsyncCreateTask.class)
|
||||
.withParam(zoo)
|
||||
.withScene(CustomAsyncCreateTask.SCENE)
|
||||
.build();
|
||||
retryTemplate.executeRetry();
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-26 10:14
|
||||
*/
|
||||
@Component
|
||||
public class RemoteService {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
public Result call() {
|
||||
return restTemplate.getForObject("http://127.0.0.1:8089/school/id", Result.class);
|
||||
// return new Result();
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
||||
import com.example.model.Cat;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-04 16:07
|
||||
*/
|
||||
@Service
|
||||
public class RetryRegisterService {
|
||||
|
||||
/**
|
||||
* 测试简单的异常情况
|
||||
*/
|
||||
@Retryable(scene = "errorMethod1")
|
||||
public String errorMethod1(List<Cat> name) {
|
||||
|
||||
double i = 1 / 0;
|
||||
|
||||
return "这是一个简单的异常方法";
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.example.model.TransactionalEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.event.TransactionPhase;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2023-04-25 22:46
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TestEventListener {
|
||||
|
||||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
|
||||
public void beforeConfirmSell(TransactionalEvent<String> event) {
|
||||
log.info("触发beforeConfirmSell事件 [{}]", event);
|
||||
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.common.core.context.SpringContext;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.mapper.SchoolMapper;
|
||||
import com.example.mapper.StudentMapper;
|
||||
import com.example.model.TransactionalEvent;
|
||||
import com.example.po.School;
|
||||
import com.example.po.Student;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-26 09:08
|
||||
*/
|
||||
@Component
|
||||
public class TestExistsTransactionalRetryService {
|
||||
|
||||
@Autowired
|
||||
private SchoolMapper schoolMapper;
|
||||
|
||||
@Autowired
|
||||
private StudentMapper studentMapper;
|
||||
|
||||
@Autowired
|
||||
private RemoteService remoteService;
|
||||
|
||||
@Retryable(scene = "testSimpleInsert", bizNo = "#name", localTimes = 3, isThrowException = false)
|
||||
@Transactional
|
||||
public String testSimpleInsert(String name) {
|
||||
|
||||
School school = new School();
|
||||
school.setName(name);
|
||||
school.setAddress(UUID.randomUUID().toString());
|
||||
school.setCreateDt(LocalDateTime.now());
|
||||
school.setUpdateDt(LocalDateTime.now());
|
||||
schoolMapper.insert(school);
|
||||
|
||||
Student student = new Student();
|
||||
student.setName(name);
|
||||
student.setAge(1);
|
||||
student.setCreateDt(LocalDateTime.now());
|
||||
student.setUpdateDt(LocalDateTime.now());
|
||||
studentMapper.insert(student);
|
||||
|
||||
Result call = remoteService.call();
|
||||
System.out.println("-------------->"+call.getMessage());
|
||||
if (call.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException("调用远程失败" + school.getAddress());
|
||||
}
|
||||
|
||||
// TransactionalEvent<String> event = new TransactionalEvent<>("123");
|
||||
// SpringContext.CONTEXT.publishEvent(event);
|
||||
|
||||
return "testSimpleInsert"+school.getAddress();
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.common.core.context.SpringContext;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.example.mapper.SchoolMapper;
|
||||
import com.example.mapper.StudentMapper;
|
||||
import com.example.model.TransactionalEvent;
|
||||
import com.example.po.School;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-26 09:08
|
||||
*/
|
||||
@Component
|
||||
public class TestExistsTransactionalRetryService2 {
|
||||
|
||||
@Autowired
|
||||
private SchoolMapper schoolMapper;
|
||||
|
||||
@Autowired
|
||||
private StudentMapper studentMapper;
|
||||
|
||||
@Autowired
|
||||
private RemoteService remoteService;
|
||||
|
||||
@Retryable(scene = "testSimpleUpdate", bizNo = "#name", localTimes = 5)
|
||||
@Transactional
|
||||
public String testSimpleUpdate(Long id) {
|
||||
|
||||
School school = new School();
|
||||
school.setAddress(UUID.randomUUID().toString());
|
||||
school.setCreateDt(LocalDateTime.now());
|
||||
school.setUpdateDt(LocalDateTime.now());
|
||||
schoolMapper.update(school, new LambdaQueryWrapper<School>()
|
||||
.eq(School::getId, id));
|
||||
|
||||
|
||||
Result call = remoteService.call();
|
||||
System.out.println("-------------->"+call.getMessage());
|
||||
if (call.getStatus() == 0) {
|
||||
throw new UnsupportedOperationException("调用远程失败");
|
||||
}
|
||||
|
||||
TransactionalEvent<String> event = new TransactionalEvent<>("123");
|
||||
SpringContext.CONTEXT.publishEvent(event);
|
||||
|
||||
return "testSimpleInsert"+school.getAddress();
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.common.core.log.LogUtils;
|
||||
import com.example.model.Dog;
|
||||
import com.example.model.Zoo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:06
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TestRetryMethodComplexParamaterService {
|
||||
|
||||
@Retryable(scene = "testRetryMethodForZoo")
|
||||
public String testRetryMethod(Zoo zoo) {
|
||||
LogUtils.debug(log,"testRetryMethodForZoo zoo:[{}]", zoo);
|
||||
double i = 1 / 0;
|
||||
|
||||
return "测试自定义重试方法";
|
||||
}
|
||||
|
||||
@Retryable(scene = "testRetryMethodForZooList")
|
||||
public String testRetryMethod(List<Zoo> zoo, Dog dog) {
|
||||
LogUtils.debug(log, "testRetryMethodForZooList zoo:[{}] dog:[{}]", zoo, dog);
|
||||
double i = 1 / 0;
|
||||
return "测试自定义重试方法";
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
||||
import com.example.client.DemoClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:06
|
||||
*/
|
||||
@Component
|
||||
public class TestRetryMethodService {
|
||||
|
||||
@Autowired
|
||||
private DemoClient demoClient;
|
||||
|
||||
@Retryable(scene = "testRetryMethod", retryMethod = MyExecutorMethod.class, retryStrategy = RetryType.ONLY_REMOTE)
|
||||
public String testRetryMethod(String p) {
|
||||
double i = 1 / 0;
|
||||
return "测试自定义重试方法";
|
||||
}
|
||||
|
||||
@Retryable(scene = "testRetryHeaderTransfer", retryStrategy = RetryType.ONLY_LOCAL, localTimes = 1)
|
||||
public String testRetryHeaderTransfer(String p) {
|
||||
demoClient.get();
|
||||
demoClient.get();
|
||||
demoClient.get();
|
||||
double i = 1 / 0;
|
||||
return "测试重试流量标识服务间传递";
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.annotation.Retryable;
|
||||
import com.aizuda.easy.retry.client.core.retryer.RetryType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:03
|
||||
*/
|
||||
@Component
|
||||
public class TestRetryStrategyService {
|
||||
|
||||
/**
|
||||
* 测试仅内存重试和远程重试
|
||||
*/
|
||||
@Retryable(scene = "errorMethodForLocalAndRemote", localTimes = 3, retryStrategy = RetryType.LOCAL_REMOTE)
|
||||
public String errorMethodForLocalAndRemote(String name) {
|
||||
|
||||
double i = 1 / 0;
|
||||
|
||||
return "这是一个简单的异常方法";
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试仅内存重试
|
||||
*/
|
||||
@Retryable(scene = "errorMethodForOnlyLocal", localTimes = 3, retryStrategy = RetryType.ONLY_LOCAL)
|
||||
public String errorMethodForOnlyLocal(String name) {
|
||||
|
||||
double i = 1 / 0;
|
||||
|
||||
return "测试仅内存重试";
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试仅内存重试
|
||||
*/
|
||||
@Retryable(scene = "errorMethodForOnlyRemote", bizNo = "#name", localTimes = 3, retryStrategy = RetryType.ONLY_REMOTE)
|
||||
public String errorMethodForOnlyRemote(String name) {
|
||||
|
||||
double i = 1 / 0;
|
||||
|
||||
return "测试仅内存重试";
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.po.School;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学校 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Mapper
|
||||
public interface SchoolMapper extends BaseMapper<School> {
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.po.SchoolStudentTeacher;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学校学生老师表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Mapper
|
||||
public interface SchoolStudentTeacherMapper extends BaseMapper<SchoolStudentTeacher> {
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.po.Student;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学生 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Mapper
|
||||
public interface StudentMapper extends BaseMapper<Student> {
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.example.mapper;
|
||||
|
||||
import com.example.po.Teacher;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 教师 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Mapper
|
||||
public interface TeacherMapper extends BaseMapper<Teacher> {
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.example.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-21 11:17
|
||||
*/
|
||||
@Data
|
||||
public class Cat {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.example.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-21 11:17
|
||||
*/
|
||||
@Data
|
||||
public class Dog {
|
||||
private String name;
|
||||
private int age;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.example.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2023-04-25 22:48
|
||||
*/
|
||||
@Getter
|
||||
public class TransactionalEvent<T> extends ApplicationEvent {
|
||||
|
||||
private T data;
|
||||
|
||||
public TransactionalEvent(final T source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.example.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-21 11:17
|
||||
*/
|
||||
@Data
|
||||
public class Zoo {
|
||||
private Dog dog;
|
||||
private List<Cat> list;
|
||||
private LocalDateTime now;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.example.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学校
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Data
|
||||
public class School implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String address;
|
||||
|
||||
private LocalDateTime createDt;
|
||||
|
||||
private LocalDateTime updateDt;
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.example.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学校学生老师表
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@TableName("school_student_teacher")
|
||||
@Data
|
||||
public class SchoolStudentTeacher implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Long schoolId;
|
||||
|
||||
private Long teacherId;
|
||||
|
||||
private Long studentId;
|
||||
|
||||
private LocalDateTime createDt;
|
||||
|
||||
private LocalDateTime updateDt;
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.example.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 学生
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Data
|
||||
public class Student implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer age;
|
||||
|
||||
private LocalDateTime createDt;
|
||||
|
||||
private LocalDateTime updateDt;
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.example.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 教师
|
||||
* </p>
|
||||
*
|
||||
* @author www.byteblogs.com
|
||||
* @since 2022-03-24
|
||||
*/
|
||||
@Data
|
||||
public class Teacher implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer age;
|
||||
|
||||
private LocalDateTime createDt;
|
||||
|
||||
private LocalDateTime updateDt;
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
server:
|
||||
port: 8088
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
datasource:
|
||||
name: x_retry
|
||||
url: jdbc:mysql://localhost:3306/demo?useSSL=false&characterEncoding=utf8&useUnicode=true
|
||||
username: root
|
||||
password: root
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
hikari:
|
||||
connection-timeout: 30000
|
||||
minimum-idle: 5
|
||||
maximum-pool-size: 20
|
||||
auto-commit: true
|
||||
idle-timeout: 30000
|
||||
pool-name: demo
|
||||
max-lifetime: 1800000
|
||||
connection-test-query: SELECT 1
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*.xml
|
||||
typeAliasesPackage: com.x.retry.server.persistence.mybatis.po
|
||||
global-config:
|
||||
db-config:
|
||||
field-strategy: NOT_EMPTY
|
||||
capital-mode: false
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: true
|
||||
|
||||
logging:
|
||||
config: classpath:logback-boot.xml
|
||||
|
||||
easy-retry:
|
||||
server:
|
||||
host: 127.0.0.1
|
||||
port: 1788
|
@ -1,51 +0,0 @@
|
||||
<configuration>
|
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,%i索引【从数字0开始递增】,,, -->
|
||||
<!-- appender是configuration的子节点,是负责写日志的组件。 -->
|
||||
<!-- ConsoleAppender:把日志输出到控制台 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
||||
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是sys.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过1KB时,对当前日志进行分割 重命名-->
|
||||
<appender name="syslog"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>log/sys.log</File>
|
||||
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
||||
<!-- TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||
<!-- 文件名:log/sys.2017-12-05.0.log -->
|
||||
<fileNamePattern>log/sys.%d.%i.log</fileNamePattern>
|
||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
||||
<maxHistory>30</maxHistory>
|
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,本篇设置为1KB,只是为了演示 -->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<!-- pattern节点,用来设置日志的输入格式 -->
|
||||
<pattern>
|
||||
%d %p (%file:%line\)- %m%n
|
||||
</pattern>
|
||||
<!-- 记录日志的编码 -->
|
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- 控制台输出日志级别 -->
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||
<!-- com.appley为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
||||
<logger name="com" level="DEBUG">
|
||||
<appender-ref ref="syslog" />
|
||||
</logger>
|
||||
</configuration>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.SchoolMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.example.po.School">
|
||||
<id column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="address" property="address" />
|
||||
<result column="create_dt" property="createDt" />
|
||||
<result column="update_dt" property="updateDt" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.SchoolStudentTeacherMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.example.po.SchoolStudentTeacher">
|
||||
<id column="id" property="id" />
|
||||
<result column="school_id" property="schoolId" />
|
||||
<result column="teacher_id" property="teacherId" />
|
||||
<result column="student_id" property="studentId" />
|
||||
<result column="create_dt" property="createDt" />
|
||||
<result column="update_dt" property="updateDt" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.StudentMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.example.po.Student">
|
||||
<id column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="age" property="age" />
|
||||
<result column="create_dt" property="createDt" />
|
||||
<result column="update_dt" property="updateDt" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.example.mapper.TeacherMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.example.po.Teacher">
|
||||
<id column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="age" property="age" />
|
||||
<result column="create_dt" property="createDt" />
|
||||
<result column="update_dt" property="updateDt" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
@ -1,75 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.aizuda.easy.retry.client.core.retryer.EasyRetryTemplate;
|
||||
import com.aizuda.easy.retry.client.core.retryer.RetryTaskTemplateBuilder;
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.demo.CustomAsyncCreateTask;
|
||||
import com.example.demo.CustomSyncCreateTask;
|
||||
import com.example.demo.NestMethodService;
|
||||
import com.example.demo.RemoteService;
|
||||
import com.example.model.Cat;
|
||||
import com.example.model.Zoo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2023-05-10 13:47
|
||||
*/
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class EasyRetryTemplateTest {
|
||||
|
||||
@Autowired
|
||||
private NestMethodService nestMethodService;
|
||||
@MockBean
|
||||
private RemoteService remoteService;
|
||||
|
||||
@Test
|
||||
public void generateAsyncTaskTest() throws InterruptedException {
|
||||
|
||||
Cat cat = new Cat();
|
||||
cat.setName("zsd");
|
||||
Zoo zoo = new Zoo();
|
||||
zoo.setNow(LocalDateTime.now());
|
||||
EasyRetryTemplate retryTemplate = RetryTaskTemplateBuilder.newBuilder()
|
||||
.withExecutorMethod(CustomAsyncCreateTask.class)
|
||||
.withParam(zoo)
|
||||
.withScene(CustomAsyncCreateTask.SCENE)
|
||||
.build();
|
||||
|
||||
retryTemplate.executeRetry();
|
||||
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateSyncTask() {
|
||||
|
||||
Zoo zoo = new Zoo();
|
||||
zoo.setNow(LocalDateTime.now());
|
||||
EasyRetryTemplate retryTemplate = RetryTaskTemplateBuilder.newBuilder()
|
||||
.withExecutorMethod(CustomSyncCreateTask.class)
|
||||
.withParam(zoo)
|
||||
.withScene(CustomSyncCreateTask.SCENE)
|
||||
.build();
|
||||
|
||||
retryTemplate.executeRetry();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestMethodForCustomSyncCreateTask() throws InterruptedException {
|
||||
nestMethodService.testNestMethodForCustomSyncCreateTask();
|
||||
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.client.DemoClient;
|
||||
import com.example.mapper.SchoolMapper;
|
||||
import com.example.po.School;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class ExampleApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private SchoolMapper schoolMapper;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Autowired(required = false)
|
||||
private DemoClient demoClient;
|
||||
|
||||
@Test
|
||||
public void demoClient() {
|
||||
Result s = demoClient.get();
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
School school = new School();
|
||||
school.setAddress("上海");
|
||||
school.setName("复旦");
|
||||
schoolMapper.insert(school);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
String template = restTemplate.getForObject("http://127.0.0.1:8088/school/id", String.class);
|
||||
System.out.println(template);
|
||||
}
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.demo.RemoteService;
|
||||
import com.example.demo.TestExistsTransactionalRetryService;
|
||||
import com.example.demo.TestExistsTransactionalRetryService2;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-26 09:12
|
||||
*/
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
public class ExistsTransactionalRetryServiceTest {
|
||||
|
||||
@Autowired
|
||||
private TestExistsTransactionalRetryService testExistsTransactionalRetryService;
|
||||
@MockBean
|
||||
private RemoteService remoteService;
|
||||
@Autowired
|
||||
private TestExistsTransactionalRetryService2 testExistsTransactionalRetryService2;
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void testSimpleInsert() {
|
||||
|
||||
Mockito.when(remoteService.call())
|
||||
.thenReturn(new Result(0, "1"))
|
||||
.thenReturn(new Result(0, "2"))
|
||||
.thenReturn(new Result(0, "3"))
|
||||
.thenReturn(new Result(0, "4"))
|
||||
.thenReturn(new Result(0, "5"))
|
||||
;
|
||||
try {
|
||||
String s = testExistsTransactionalRetryService.testSimpleInsert(UUID.randomUUID().toString());
|
||||
System.out.println(s);
|
||||
} catch (Exception e) {
|
||||
log.error("重试未成功", e);
|
||||
}
|
||||
|
||||
Thread.sleep(90000);
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void testSimpleUpdate() {
|
||||
|
||||
Mockito.when(remoteService.call())
|
||||
.thenReturn(new Result(0, "1"))
|
||||
.thenReturn(new Result(0, "2"))
|
||||
.thenReturn(new Result(0, "3"))
|
||||
.thenReturn(new Result(0, "4"))
|
||||
.thenReturn(new Result(1, "5"))
|
||||
;
|
||||
try {
|
||||
String s = testExistsTransactionalRetryService2.testSimpleUpdate(5651L);
|
||||
System.out.println(s);
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
Thread.sleep(90000);
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void syncTestSimpleInsert() {
|
||||
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 50, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
|
||||
|
||||
Mockito.when(remoteService.call())
|
||||
.thenReturn(new Result(0, "1"))
|
||||
.thenReturn(new Result(0, "2"))
|
||||
.thenReturn(new Result(0, "3"))
|
||||
.thenReturn(new Result(0, "4"))
|
||||
.thenReturn(new Result(5, "5"))
|
||||
;
|
||||
try {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
threadPoolExecutor.execute(() -> testExistsTransactionalRetryService.testSimpleInsert(UUID.randomUUID().toString()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
Thread.sleep(900000);
|
||||
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.aizuda.easy.retry.common.core.model.Result;
|
||||
import com.example.demo.NestMethodService;
|
||||
import com.example.demo.RemoteService;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-27 22:40
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class NestMethodServiceTest {
|
||||
|
||||
@Autowired
|
||||
private NestMethodService nestMethodService;
|
||||
@MockBean
|
||||
private RemoteService remoteService;
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void testNestMethod() {
|
||||
Mockito.when(remoteService.call())
|
||||
.thenReturn(new Result(0, "1"))
|
||||
.thenReturn(new Result(0, "2"))
|
||||
.thenReturn(new Result(0, "3"))
|
||||
.thenReturn(new Result(0, "4"))
|
||||
.thenReturn(new Result(1, "5"))
|
||||
;
|
||||
try {
|
||||
nestMethodService.testNestMethod();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.example.demo.TestRetryMethodComplexParamaterService;
|
||||
import com.example.model.Cat;
|
||||
import com.example.model.Dog;
|
||||
import com.example.model.Zoo;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-21 11:32
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class RetryMethodComplexParamaterServiceTest {
|
||||
|
||||
@Autowired
|
||||
private TestRetryMethodComplexParamaterService testRetryMethodComplexParamaterService;
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void testRetryMethodForZoo() {
|
||||
Zoo zoo = new Zoo();
|
||||
|
||||
Dog dog = new Dog();
|
||||
dog.setName(UUID.randomUUID().toString());
|
||||
dog.setAge(10);
|
||||
zoo.setDog(dog);
|
||||
|
||||
Cat cat = new Cat();
|
||||
cat.setAge(1);
|
||||
cat.setName(UUID.randomUUID().toString());
|
||||
zoo.setList(Arrays.asList(cat));
|
||||
|
||||
try {
|
||||
testRetryMethodComplexParamaterService.testRetryMethod(zoo);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void testRetryMethodForZooList() {
|
||||
Zoo zoo = new Zoo();
|
||||
|
||||
Dog dog = new Dog();
|
||||
dog.setName(UUID.randomUUID().toString());
|
||||
dog.setAge(10);
|
||||
zoo.setDog(dog);
|
||||
|
||||
Cat cat = new Cat();
|
||||
cat.setAge(1);
|
||||
cat.setName(UUID.randomUUID().toString());
|
||||
zoo.setList(Arrays.asList(cat));
|
||||
|
||||
try {
|
||||
testRetryMethodComplexParamaterService.testRetryMethod(Arrays.asList(zoo), dog);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.example.demo.RetryRegisterService;
|
||||
import com.example.model.Cat;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-04 17:29
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class RetryRegisterServiceTest {
|
||||
|
||||
@Autowired
|
||||
private RetryRegisterService retryRegisterService;
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void errorMethod1() {
|
||||
|
||||
try {
|
||||
List<Cat> list = new ArrayList<>();
|
||||
Cat cat = new Cat();
|
||||
cat.setName(UUID.randomUUID().toString());
|
||||
list.add(cat);
|
||||
retryRegisterService.errorMethod1(list);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
Thread.sleep(90000);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.example.demo.TestRetryMethodService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:09
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class TestRetryMethodServiceTest {
|
||||
|
||||
@Autowired
|
||||
public TestRetryMethodService retryMethodService;
|
||||
|
||||
@Test
|
||||
public void testRetryMethod() throws InterruptedException {
|
||||
try {
|
||||
retryMethodService.testRetryMethod(UUID.randomUUID().toString());
|
||||
}catch (Exception e) {
|
||||
|
||||
}
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetryHeaderTransfer() throws InterruptedException {
|
||||
try {
|
||||
retryMethodService.testRetryHeaderTransfer(UUID.randomUUID().toString());
|
||||
}catch (Exception e) {
|
||||
|
||||
}
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
import com.example.demo.TestRetryStrategyService;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author: www.byteblogs.com
|
||||
* @date : 2022-03-07 14:03
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class TestRetryStrategyServiceTest {
|
||||
|
||||
@Autowired
|
||||
private TestRetryStrategyService testRetryStrategyService;
|
||||
|
||||
@Test
|
||||
public void errorMethodForOnlyLocal() {
|
||||
testRetryStrategyService.errorMethodForOnlyLocal(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void errorMethodForOnlyRemote() {
|
||||
testRetryStrategyService.errorMethodForOnlyRemote(UUID.randomUUID().toString());
|
||||
Thread.sleep(90000);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user