Beispiel #1
0
  @Test
  public void scheduleJob() throws Exception {
    // 等待任务延时1秒启动并执行完毕
    Threads.sleep(3000);

    // 验证任务已执行
    assertThat(appender.getLogsCount()).isEqualTo(1);
    assertThat(appender.getFirstMessage()).isEqualTo("There are 6 user in database.");
  }
Beispiel #2
0
  @Test
  public void topicMessage() {
    Threads.sleep(1000);
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(NotifyMessageListener.class);

    User user = new User();
    user.setName("calvin");
    user.setEmail("*****@*****.**");

    notifyMessageProducer.sendTopic(user);
    logger.info("sended message");

    Threads.sleep(1000);
    assertEquals("UserName:calvin, Email:[email protected]", appender.getFirstMessage());
  }
Beispiel #3
0
 @AfterClass
 public static void removeLogger() {
   appender.removeFromLogger(UserCountScanner.class);
 }
Beispiel #4
0
 @BeforeClass
 public static void initLogger() {
   // 加载测试用logger appender
   appender = new LogbackListAppender();
   appender.addToLogger(UserCountScanner.class.getName() + ".jdk timer job");
 }