改进单元测试类配置
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
*/
|
||||
package com.jeesite.test;
|
||||
|
||||
import com.jeesite.common.collect.ListUtils;
|
||||
import com.jeesite.common.tests.BaseSpringContextTests;
|
||||
import com.jeesite.modules.Application;
|
||||
import com.jeesite.modules.test.dao.TestDataDao;
|
||||
import com.jeesite.modules.test.entity.TestData;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量插入测试
|
||||
* @author ThinkGem
|
||||
* @version 2019年10月28日
|
||||
*/
|
||||
@ActiveProfiles("test")
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class InsertBatchTest extends BaseSpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private TestDataDao testDataDao;
|
||||
|
||||
@Test
|
||||
public void testData1() throws Exception{
|
||||
List<TestData> list = ListUtils.newArrayList();
|
||||
for(int i=0; i<5000; i++){
|
||||
TestData testData = new TestData();
|
||||
testData.setTestInput("test"+i);
|
||||
list.add(testData);
|
||||
}
|
||||
testDataDao.insertBatch(list);
|
||||
list = testDataDao.findList(new TestData());
|
||||
System.out.println("insert: " + list.size());
|
||||
long count = testDataDao.updateBatch(list);
|
||||
System.out.println("update: " + count);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
* No deletion without permission, or be held responsible to law.
|
||||
*/
|
||||
package com.jeesite.test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import com.jeesite.common.collect.ListUtils;
|
||||
import com.jeesite.common.idgen.IdGen;
|
||||
import com.jeesite.common.tests.BaseSpringContextTests;
|
||||
import com.jeesite.modules.Application;
|
||||
import com.jeesite.modules.test.entity.TestData;
|
||||
import com.jeesite.modules.test.entity.TestDataChild;
|
||||
import com.jeesite.modules.test.service.TestDataService;
|
||||
|
||||
/**
|
||||
* 多数据源并发测试<br>
|
||||
* 1、将 TestDataChildDao 的数据源设置为 ds2<br>
|
||||
* 2、将 TestDataChild 的表名设置为 test_data_child2<br>
|
||||
* 3、配置 ds2 数据源,并创建 test_data_child2 表
|
||||
* @author ThinkGem
|
||||
* @version 2019-6-26
|
||||
*/
|
||||
@ActiveProfiles("test")
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class MultiDataSourceTest extends BaseSpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private TestDataService testDataService;
|
||||
|
||||
@Test
|
||||
public void testData() throws Exception{
|
||||
ExecutorService pool = Executors.newCachedThreadPool();
|
||||
CountDownLatch latch = new CountDownLatch(10);
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
Thread.sleep(IdGen.randomInt(1000, 3000));
|
||||
TestData testData = new TestData();
|
||||
testData.setTestDataChildList(ListUtils.newArrayList(
|
||||
new TestDataChild(), new TestDataChild(), new TestDataChild()));
|
||||
testDataService.save(testData);
|
||||
List<TestData> list = testDataService.findList(new TestData());
|
||||
System.out.println("size: " + list.size());
|
||||
list.forEach(e -> {
|
||||
System.out.println("get: " + testDataService.get(e));
|
||||
});
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
};
|
||||
for (int i = 0; i < latch.getCount(); i++) {
|
||||
pool.execute(runnable);
|
||||
}
|
||||
latch.await();
|
||||
pool.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false" scan="false">
|
||||
|
||||
<!-- Logger level setting -->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
|
||||
<include resource="config/logger-core.xml"/>
|
||||
|
||||
<!-- Console log output -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} %clr(%-5p) %clr([%-39logger{39}]){cyan} - %m%n%wEx</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="WARN">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user