一 利用工具包:

  <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.databene</groupId>
<artifactId>contiperf</artifactId>
<version>2.3.</version>
<scope>test</scope>
</dependency>

引入者两个依赖:

就可以进行测试了,看测试代码:

package com.cxy.springs;

import com.cxy.springs.entity.TUser;
import com.cxy.springs.service.TUserService;
import org.databene.contiperf.PerfTest;
import org.databene.contiperf.junit.ContiPerfRule;
import org.junit.Rule;
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 SpringsApplicationTests {
@Autowired
public TUserService userService;
@Test
public void contextLoads() {
}
//引入 ContiPerf 进行性能测试
@Rule
public ContiPerfRule contiPerfRule = new ContiPerfRule(); @Test
//10个线程 执行10次
@PerfTest(invocations = ,threads = )
public void test() { TUser load = userService.load();
System.out.println(load.getPhone()); }
}

结果:

不知道为什么我的图片挂了

第二种方式:

利用concurrent包下列进行测试,不过他们没有具体的相应时间:

package com.cxy.springs;

import com.cxy.springs.entity.TUser;
import com.cxy.springs.service.TUserService;
import org.databene.contiperf.PerfTest;
import org.databene.contiperf.junit.ContiPerfRule;
import org.junit.Rule;
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; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore; @RunWith(SpringRunner.class)
@SpringBootTest
public class SpringsApplicationTests {
@Autowired
public TUserService userService;
@Test
public void contextLoads() {
}
//引入 ContiPerf 进行性能测试
@Rule
public ContiPerfRule contiPerfRule = new ContiPerfRule(); @Test
//10个线程 执行10次
@PerfTest(invocations = ,threads = )
public void test() { TUser load = userService.load();
System.out.println(load.getPhone()); }
@Test
public void test2()throws Exception{
ExecutorService executorService = Executors.newCachedThreadPool();
final Semaphore semaphore = new Semaphore();
final CountDownLatch countDownLatch = new CountDownLatch();
long l = System.currentTimeMillis();
for (int i = ; i < ; i++) {
final int count = i;
executorService.execute(() -> {
try {
semaphore.acquire();
TUser load = userService.load();
System.out.println(load.getPhone());
semaphore.release();
} catch (Exception e) {
// log.error("exception" , e);
}
countDownLatch.countDown();
});
}
countDownLatch.await();
long a = System.currentTimeMillis();
System.out.println(a-l); executorService.shutdown(); //log.info("size:{}" , map.size());
}
}

这个开始时候给了5000个,直接把我数据库搞炸了,

后来改了,也还是可以测试的,如果需要使用这个那么需要整合线程池了,不然那么多的连接夯在那里会一直不走

最新文章

  1. ashx中Response.ContentType的常用类型
  2. Nodejs事件引擎libuv源码剖析之:高效队列(queue)的实现
  3. git上传到阿里云code
  4. Device eth0 does not seem to be present, delaying initialization.转载
  5. Xcode_5
  6. Compare_Connect_Letter
  7. canvas绘制百分比圆环进度条
  8. iOS 开发之内存泄漏问题
  9. 在Apache中运行Python WSGI应用
  10. 【AIM Tech Round 4 (Div. 2) D Prob】
  11. vue2.0 事件处理常用修饰符-----------------记录,加强记忆。
  12. python django基础二URL路由系统
  13. TCP/IP 笔记 - 地址解析协议
  14. devexpress gridview 添加按钮
  15. 分页用到的子查询sql语句
  16. 信息学奥赛(NOIP)复赛学习方法推荐
  17. HDU 1242 Rescue (BFS+优先队列)
  18. Linux操作系统(一)
  19. markdown入门语法
  20. C if 判断 else 否则

热门文章

  1. c++11 Thread库写多线程程序
  2. cvErode和cvDilate腐蚀和膨胀函数
  3. 7.ICMP与ping
  4. Java Collection - HashMap
  5. Tool Zip 破解
  6. JS预解析与变量提升
  7. 线性dp,后缀处理——cf1016C好题
  8. java——万年历
  9. 1.RCC of STM32F103
  10. 17.splash_case01