Esempio n. 1
0
 @Test
 public void testImpleTraced() {
   int oldLogsCount = this.countRowsInTable(LOG_TABLE_NAME);
   try {
     dbLogger.info("测试第1次");
   } catch (IllegalStateException e) {
     Assert.assertTrue(e.getMessage().startsWith("This log"));
   }
   ThreadUtils.sleep(1000);
   logConfigs.setEnvironment(Environment.DEVELOP.name());
   String c = "123";
   proposalService.testParam(1, '2');
   // 生产环境拦截一条
   proposalService.testProductTraced();
   // 开发环境拦截一条
   proposalService.testDevelopTraced();
   // 测试环境拦截一条
   proposalService.testTestTraced();
   // 未拦截测试
   proposalService.notTracedService();
   ThreadUtils.sleep(1000 * 3);
   Assert.assertEquals(oldLogsCount + 4, this.countRowsInTable(LOG_TABLE_NAME));
 }
Esempio n. 2
0
  @Test
  public void interfaceTraced() throws IOException {

    Resource resource = new ClassPathResource("/application.test.properties");
    Properties props = PropertiesLoaderUtils.loadProperties(resource);
    LogTraceAspect traceAspect = super.applicationContext.getBean(LogTraceAspect.class);
    logConfigs.setEnvironment(props.get("log.environment").toString());
    // 所谓接口拦截是拦截所有非接口类后分析是否有接口拦截注解,造成所有非实现类可能被拦截两次。因此不适合拦截应用
    int oldLogsCount = this.countRowsInTable(LOG_TABLE_NAME);
    proposalService.testInterfaceTraced();
    // proposalService.save();
    ThreadUtils.sleep(1000 * 3);

    Assert.assertEquals(oldLogsCount + 1, this.countRowsInTable(LOG_TABLE_NAME));
  }
Esempio n. 3
0
 /** 生产环境测试 */
 @Test
 public void productEnv() {
   LogTraceAspect implTraceAspect = super.applicationContext.getBean(LogTraceAspect.class);
   logConfigs.setEnvironment(Environment.PRODUCT.name());
   int oldLogsCount = this.countRowsInTable(LOG_TABLE_NAME);
   // 生产环境拦截一条
   proposalService.testProductTraced();
   // 开发环境拦截一条
   proposalService.testDevelopTraced();
   // 测试环境拦截一条
   proposalService.testTestTraced();
   // 未拦截测试
   proposalService.notTracedService();
   ThreadUtils.sleep(1000 * 3);
   Assert.assertEquals(oldLogsCount + 1, this.countRowsInTable(LOG_TABLE_NAME));
 }