Exemplo n.º 1
0
 /** 单线程压力测试 */
 @Test
 public void testGetTraceId_SingleTreand() throws Exception {
   long counts = 100000; // 每轮方法调用次数
   int rounds = 3; // 跑n轮,求平均值
   long[] results = new long[rounds];
   for (int i = 0; i < rounds; i++) {
     long startTime = System.currentTimeMillis();
     for (long j = 0; j < counts; j++) {
       generater.getTraceId();
     }
     long endTime = System.currentTimeMillis();
     results[i] = (endTime - startTime);
   }
   long sum = 0;
   for (int i = 0; i < rounds; i++) {
     sum += results[i];
   }
   System.out.println("单线程测试");
   System.out.println("轮数=" + rounds);
   System.out.println("每轮提交量=" + counts);
   System.out.println("平均耗时=" + sum / rounds + " ms");
   System.out.printf("Tps=%.1f 次/ms\n", 1.0 * counts / (sum / rounds));
   System.out.println("------------------------");
   Thread.sleep(10);
 }
Exemplo n.º 2
0
 /** 功能性测试 */
 @Test
 public void testGetTraceId_BasicFunction() throws Exception {
   System.out.println("基本功能测试");
   for (int i = 0; i < 3; i++) {
     System.out.println(generater.getTraceId());
   }
   System.out.println("------------------------");
   Thread.sleep(10);
 }
Exemplo n.º 3
0
 /** 数据重复性测试 */
 @Test
 public void testGetTraceId_CompleteFunction() throws Exception {
   System.out.println("数据重复性测试");
   long counts = 100000; // 100w次跟踪
   BinaryReadWrite readWriter = new BinaryReadWrite();
   Long old = 0L;
   for (int i = 0; i < counts; i++) {
     Long buildData = generater.getTraceId();
     Assert.assertTrue(old < buildData);
     readWriter.writeLong(buildData);
     old = buildData;
   }
   readWriter.flushWrite();
   System.out.println("-->没有重复数据");
   System.out.println("ID存储到" + readWriter.getS_FilePath() + "下");
   System.out.println("------------------------");
   Thread.sleep(10);
 }