Package com.dianping.cat.demo

Source Code of com.dianping.cat.demo.TestCode

package com.dianping.cat.demo;


import org.junit.Test;

import com.dianping.cat.Cat;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;

public class TestCode {
 
  public void logError(Throwable able){
      Transaction t = Cat.newTransaction("Neocortex", "Error");
     
      Cat.logError(able);
     

        MessageTree tree = Cat.getManager().getThreadLocalMessageTree();

        ((DefaultMessageTree) tree).setDomain("NeoCortex");
      t.complete();
  }

    @Test
    public void test1() throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            test();
        }

        Thread.sleep(1000 * 10);
    }

    public void test() throws InterruptedException {
        Transaction t = Cat.newTransaction("Neocortex", "function1");
        try {
            int a = functionA();

            if (a < 0) {
                Cat.logError(new RuntimeException("sdsf"));
            }

            MessageTree tree = Cat.getManager().getThreadLocalMessageTree();

            ((DefaultMessageTree) tree).setDomain("NeoCortex");
            t.setStatus(Transaction.SUCCESS);
        } catch (Exception e) {

            Cat.logError(e);
            t.setStatus(e);

        } finally {
            t.complete();
        }


    }

    private int functionA() {

        return (int) (Math.random() * 100) - 50;
    }

}
TOP

Related Classes of com.dianping.cat.demo.TestCode

TOP
Copyright © 2018 www.massapi.com. 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.