Skip to content

Commit

Permalink
Merge pull request #33 from MoYu-zc/main
Browse files Browse the repository at this point in the history
SpringEventApplicationListener 由 ApplicationListener 修改为 SmartInitializingSingleton…
  • Loading branch information
iMouseWu authored Dec 27, 2024
2 parents f8ecfd3 + 6c589c8 commit ceea006
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.alibaba.easyretry.extension.mybatis.access;

import java.util.Date;
import java.util.List;
import java.util.Objects;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import com.alibaba.easyretry.common.constant.enums.RetryTaskStatusEnum;
import com.alibaba.easyretry.common.entity.RetryTask;
import com.alibaba.easyretry.extension.mybatis.MyBatisConfig;
import com.alibaba.easyretry.extension.mybatis.dao.RetryTaskDAOImpl;
import org.junit.jupiter.api.*;

import java.util.Date;
import java.util.List;
import java.util.Objects;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class MybatisRetryTaskAccessTest {
Expand Down Expand Up @@ -39,7 +45,7 @@ void saveTask() {
@Test
@Order(2)
void handle() {
ACCESS.saveRetryTask(task);
// ACCESS.saveRetryTask(task);
Assertions.assertTrue(ACCESS.handlingRetryTask(task));
List<RetryTask> retryTasks = ACCESS.listAvailableTasks(1L);
Assertions.assertTrue(Objects.nonNull(retryTasks) && !retryTasks.isEmpty());
Expand All @@ -49,7 +55,7 @@ void handle() {
@Test
@Order(3)
void stop() {
ACCESS.saveRetryTask(task);
// ACCESS.saveRetryTask(task);
boolean b = ACCESS.stopRetryTask(task);
Assertions.assertTrue(b);
List<RetryTask> retryTasks = ACCESS.listAvailableTasks(1L);
Expand All @@ -59,7 +65,7 @@ void stop() {
@Test
@Order(4)
void finish(){
ACCESS.saveRetryTask(task);
// ACCESS.saveRetryTask(task);
Assertions.assertTrue(ACCESS.finishRetryTask(task));
List<RetryTask> retryTasks = ACCESS.listAvailableTasks(1L);
Assertions.assertTrue(Objects.isNull(retryTasks) || retryTasks.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.alibaba.easyretry.extension.mybatis.dao;

import com.alibaba.easyretry.common.constant.enums.RetryTaskStatusEnum;
import com.alibaba.easyretry.extension.mybatis.MyBatisConfig;
import com.alibaba.easyretry.extension.mybatis.po.RetryTaskPO;
import com.alibaba.easyretry.extension.mybatis.query.RetryTaskQuery;
import org.junit.jupiter.api.*;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;

import com.alibaba.easyretry.common.constant.enums.RetryTaskStatusEnum;
import com.alibaba.easyretry.extension.mybatis.MyBatisConfig;
import com.alibaba.easyretry.extension.mybatis.po.RetryTaskPO;
import com.alibaba.easyretry.extension.mybatis.query.RetryTaskQuery;

class RetryTaskDAOImplTest {

private static RetryTaskDAO retryTaskDAO;
Expand Down Expand Up @@ -38,9 +42,9 @@ void saveTask() {
@Order(2)
void listRetryTask() {
final RetryTaskPO retryTaskPO = new RetryTaskPO()
.setId(1L)
.setId(2L)
.setGmtCreate(new Date())
.setBizId("1")
.setBizId("2")
.setRetryStatus(RetryTaskStatusEnum.HANDLING.getCode())
.setGmtModified(new Date());

Expand Down Expand Up @@ -77,9 +81,9 @@ void updateRetryTask() {
@Order(4)
void deleteRetryTask() {
final RetryTaskPO retryTaskPO = new RetryTaskPO()
.setId(1L)
.setId(3L)
.setGmtCreate(new Date())
.setBizId("1")
.setBizId("3")
.setRetryStatus(RetryTaskStatusEnum.HANDLING.getCode())
.setGmtModified(new Date());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
package com.alibaba.easyretry.extension.spring;

import org.springframework.beans.factory.SmartInitializingSingleton;

import com.alibaba.easyretry.common.filter.RetryFilterInvocationHandler;
import com.alibaba.easyretry.common.filter.RetryFilterRegisterHandler;

import lombok.Setter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

/**
* @author Created by wuhao on 2021/4/9.
*/
public class SpringEventApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
public class SpringEventApplicationListener implements SmartInitializingSingleton {

@Setter
private RetryFilterInvocationHandler retryFilterInvocationHandler;

@Setter
private RetryFilterRegisterHandler retryFilterRegisterHandler;


@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
//防止父子容器场景
if (applicationContext.getParent() != null) {
return;
}
public void afterSingletonsInstantiated() {
retryFilterRegisterHandler.handle();
retryFilterInvocationHandler.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;

import com.alibaba.easyretry.common.RetryConfiguration;
Expand Down Expand Up @@ -164,7 +163,7 @@ public RetryFilterRegisterHandler retryFilterRegisterHandler(RetryFilterDiscover
}

@Bean
public ApplicationListener easyRetryApplicationListener(RetryFilterInvocationHandler retryFilterInvocationHandler,
public SpringEventApplicationListener easyRetryApplicationListener(RetryFilterInvocationHandler retryFilterInvocationHandler,
RetryFilterRegisterHandler retryFilterRegisterHandler) {
SpringEventApplicationListener springEventApplicationListener = new SpringEventApplicationListener();
springEventApplicationListener.setRetryFilterRegisterHandler(retryFilterRegisterHandler);
Expand Down

0 comments on commit ceea006

Please sign in to comment.