提交 d8b1514b 编写于 作者: S sean.wang

bugfix

上级 223b917f
......@@ -131,6 +131,11 @@ public class DefaultMessageProducer implements MessageProducer {
}
public Transaction newTransaction(Transaction parent, String type, String name) {
// this enable CAT client logging cat message without explicit setup
if (!m_manager.hasContext()) {
m_manager.setup();
}
if (m_manager.isCatEnabled() && parent != null) {
DefaultTransaction transaction = new DefaultTransaction(type, name, m_manager);
......
......@@ -77,6 +77,7 @@ public abstract class BaseCompositeModelService<T> extends ModelServiceWithCalSu
t.setStatus(Message.SUCCESS);
t.addData("request", request);
t.addData("thread",Thread.currentThread());
for (final ModelService<T> service : m_allServices) {
if (!service.isEligable(request)) {
......
......@@ -37,6 +37,7 @@ public abstract class BaseHistoricalModelService<T> extends ModelServiceWithCalS
public ModelResponse<T> invoke(ModelRequest request) {
ModelResponse<T> response = new ModelResponse<T>();
Transaction t = newTransaction("ModelService", getClass().getSimpleName());
t.addData("thread",Thread.currentThread());
try {
T model = buildModel(request);
......
......@@ -10,8 +10,10 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Event;
import com.dianping.cat.message.MessageProducer;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.internal.DefaultMessageProducer;
import com.site.lookup.ComponentTestCase;
@RunWith(JUnit4.class)
......@@ -36,7 +38,7 @@ public class Demo extends ComponentTestCase {
}
@Test
public void demo() throws Exception {
public void testSingleTransaction() throws Exception {
MessageProducer cat = lookup(MessageProducer.class);
Transaction t = cat.newTransaction("URL", "FailureReportPage");
......@@ -51,11 +53,27 @@ public class Demo extends ComponentTestCase {
}
@Test
public void demo2() throws Exception {
MessageProducer cat = lookup(MessageProducer.class);
Transaction t = cat.newTransaction("SQL3", "update-user");
Thread.sleep(10);
t.setStatus("error");
public void testNestTransaction() throws Exception {
DefaultMessageProducer cat = (DefaultMessageProducer) Cat.getProducer();
final Transaction f = cat.newTransaction("demo", "father");
Thread child = new Thread(new Runnable() {
@Override
public void run() {
DefaultMessageProducer cat = (DefaultMessageProducer) Cat.getProducer();
Transaction t = cat.newTransaction(f, "demo", "child");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t.setStatus("child");
t.complete();
}
});
child.start();
child.join();
f.setStatus("father");
f.complete();
}
}
<config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd">
<app domain="Review" />
<domain id="Cat-demo" enabled="true"/>
<servers>
<server ip="127.0.0.1" port="2280" />
<server ip="192.168.7.43" port="2280" />
</servers>
</config>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册