Package org.springside.modules.test.log

Examples of org.springside.modules.test.log.LogbackListAppender


  @Test
  public void gracefulShutdown() throws InterruptedException {

    Logger logger = LoggerFactory.getLogger("test");
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger("test");

    // time enough to shutdown
    ExecutorService pool = Executors.newSingleThreadExecutor();
    Runnable task = new Task(logger, 500, 0);
    pool.execute(task);
    Threads.gracefulShutdown(pool, 1000, 1000, TimeUnit.MILLISECONDS);
    assertThat(pool.isTerminated()).isTrue();
    assertThat(appender.getFirstLog()).isNull();

    // time not enough to shutdown,call shutdownNow
    appender.clearLogs();
    pool = Executors.newSingleThreadExecutor();
    task = new Task(logger, 1000, 0);
    pool.execute(task);
    Threads.gracefulShutdown(pool, 500, 1000, TimeUnit.MILLISECONDS);
    assertThat(pool.isTerminated()).isTrue();
    assertThat(appender.getFirstLog().getMessage()).isEqualTo("InterruptedException");

    // self thread interrupt while calling gracefulShutdown
    appender.clearLogs();

    final ExecutorService self = Executors.newSingleThreadExecutor();
    task = new Task(logger, 100000, 0);
    self.execute(task);

    final CountDownLatch lock = new CountDownLatch(1);
    Thread thread = new Thread(new Runnable() {

      @Override
      public void run() {
        lock.countDown();
        Threads.gracefulShutdown(self, 200000, 200000, TimeUnit.MILLISECONDS);
      }
    });
    thread.start();
    lock.await();
    thread.interrupt();
    Threads.sleep(500);
    assertThat(appender.getFirstLog().getMessage()).isEqualTo("InterruptedException");
  }
View Full Code Here


  @Test
  public void normalShutdown() throws InterruptedException {

    Logger logger = LoggerFactory.getLogger("test");
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger("test");

    // time not enough to shutdown,write error log.
    appender.clearLogs();
    ExecutorService pool = Executors.newSingleThreadExecutor();
    Runnable task = new Task(logger, 1000, 0);
    pool.execute(task);
    Threads.normalShutdown(pool, 500, TimeUnit.MILLISECONDS);
    assertThat(pool.isTerminated()).isTrue();
    assertThat(appender.getFirstMessage()).isEqualTo("InterruptedException");
  }
View Full Code Here

    // 初始化数据
    DataFixtures.executeScript(dataSource, "classpath:data/h2/cleanup-data.sql",
        "classpath:data/h2/import-data.sql");

    // 插入appender用于assert。
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(GuavaCacheDemo.class);

    // 第一次加载会查数据库
    User user = cache.get(1L);
    assertThat(user.getLoginName()).isEqualTo("admin");
    assertThat(appender.isEmpty()).isFalse();
    appender.clearLogs();

    // 第二次加载时直接从缓存里取
    User user2 = cache.get(1L);
    assertThat(user2.getLoginName()).isEqualTo("admin");
    assertThat(appender.isEmpty()).isTrue();

    // 第三次加载时,因为缓存已经过期所以会查数据库
    Threads.sleep(10, TimeUnit.SECONDS);
    User user3 = cache.get(1L);
    assertThat(user3.getLoginName()).isEqualTo("admin");
    assertThat(appender.isEmpty()).isFalse();
  }
View Full Code Here

  private NotifyMessageProducer notifyMessageProducer;

  @Test
  public void queueMessage() {
    Threads.sleep(1000);
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(NotifyMessageListener.class);

    User user = new User();
    user.setName("calvin");
    user.setEmail("calvin@sringside.org.cn");

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

    Threads.sleep(1000);
    assertThat(appender.getFirstMessage()).isEqualTo("UserName:calvin, Email:calvin@sringside.org.cn");
  }
View Full Code Here

  }

  @Test
  public void topicMessage() {
    Threads.sleep(1000);
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(NotifyMessageListener.class);

    User user = new User();
    user.setName("calvin");
    user.setEmail("calvin@sringside.org.cn");

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

    Threads.sleep(1000);
    assertThat(appender.getFirstMessage()).isEqualTo("UserName:calvin, Email:calvin@sringside.org.cn");
  }
View Full Code Here

  private static LogbackListAppender appender;

  @BeforeClass
  public static void initLogger() {
    // 加载测试用logger appender
    appender = new LogbackListAppender();
    appender.addToLogger(UserCountScanner.class.getName() + ".spring timer job by xml");
  }
View Full Code Here

  private static LogbackListAppender appender;

  @BeforeClass
  public static void initLogger() {
    // 加载测试用logger appender
    appender = new LogbackListAppender();
    appender.addToLogger(QuartzClusterableJob.class.getName() + ".quartz cluster job");
  }
View Full Code Here

  private static LogbackListAppender appender;

  @BeforeClass
  public static void initLogger() {
    // 加载测试用logger appender
    appender = new LogbackListAppender();
    appender.addToLogger(UserCountScanner.class.getName() + ".jdk timer job");
  }
View Full Code Here

  private Destination advancedNotifyTopic;

  @Test
  public void queueMessage() {
    Threads.sleep(1000);
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(AdvancedNotifyMessageListener.class);

    User user = new User();
    user.setName("calvin");
    user.setEmail("calvin@sringside.org.cn");

    notifyMessageProducer.sendQueue(user);
    Threads.sleep(1000);
    assertThat(appender.getFirstMessage()).isEqualTo(
        "UserName:calvin, Email:calvin@sringside.org.cn, ObjectType:user");
  }
View Full Code Here

  }

  @Test
  public void topicMessage() {
    Threads.sleep(1000);
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(AdvancedNotifyMessageListener.class);

    User user = new User();
    user.setName("calvin");
    user.setEmail("calvin@sringside.org.cn");

    notifyMessageProducer.sendTopic(user);
    Threads.sleep(1000);
    assertThat(appender.getFirstMessage()).isEqualTo(
        "UserName:calvin, Email:calvin@sringside.org.cn, ObjectType:user");
  }
View Full Code Here

TOP

Related Classes of org.springside.modules.test.log.LogbackListAppender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.