修改
This commit is contained in:
parent
41f8e9c342
commit
70a51c9d92
24
src/test/java/io/linfeng/ApiTest.java
Normal file
24
src/test/java/io/linfeng/ApiTest.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package io.linfeng;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author linfeng
|
||||||
|
* @date 2022/11/9 13:02
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class ApiTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
log.info("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
package io.linfeng;
|
|
||||||
|
|
||||||
import io.linfeng.service.DynamicDataSourceTestService;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 多数据源测试
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class DynamicDataSourceTest {
|
|
||||||
@Autowired
|
|
||||||
private DynamicDataSourceTestService dynamicDataSourceTestService;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test(){
|
|
||||||
Long id = 1L;
|
|
||||||
|
|
||||||
dynamicDataSourceTestService.updateUser(id);
|
|
||||||
dynamicDataSourceTestService.updateUserBySlave1(id);
|
|
||||||
dynamicDataSourceTestService.updateUserBySlave2(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package io.linfeng;
|
|
||||||
|
|
||||||
import io.linfeng.common.utils.RedisUtils;
|
|
||||||
import io.linfeng.modules.sys.entity.SysUserEntity;
|
|
||||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class RedisTest {
|
|
||||||
@Autowired
|
|
||||||
private RedisUtils redisUtils;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void contextLoads() {
|
|
||||||
SysUserEntity user = new SysUserEntity();
|
|
||||||
user.setEmail("qqq@qq.com");
|
|
||||||
redisUtils.set("user", user);
|
|
||||||
|
|
||||||
System.out.println(ToStringBuilder.reflectionToString(redisUtils.get("user", SysUserEntity.class)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
|
|
||||||
package io.linfeng.service;
|
|
||||||
|
|
||||||
import io.linfeng.datasource.annotation.DataSource;
|
|
||||||
import io.linfeng.modules.sys.dao.SysUserDao;
|
|
||||||
import io.linfeng.modules.sys.entity.SysUserEntity;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试多数据源
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
//@DataSource("slave1")
|
|
||||||
public class DynamicDataSourceTestService {
|
|
||||||
@Autowired
|
|
||||||
private SysUserDao sysUserDao;
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void updateUser(Long id){
|
|
||||||
SysUserEntity user = new SysUserEntity();
|
|
||||||
user.setUserId(id);
|
|
||||||
user.setMobile("13500000000");
|
|
||||||
sysUserDao.updateById(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
@DataSource("slave1")
|
|
||||||
public void updateUserBySlave1(Long id){
|
|
||||||
SysUserEntity user = new SysUserEntity();
|
|
||||||
user.setUserId(id);
|
|
||||||
user.setMobile("13500000001");
|
|
||||||
sysUserDao.updateById(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DataSource("slave2")
|
|
||||||
@Transactional
|
|
||||||
public void updateUserBySlave2(Long id){
|
|
||||||
SysUserEntity user = new SysUserEntity();
|
|
||||||
user.setUserId(id);
|
|
||||||
user.setMobile("13500000002");
|
|
||||||
sysUserDao.updateById(user);
|
|
||||||
|
|
||||||
//测试事物
|
|
||||||
int i = 1/0;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user