m_queue = Reflects.forField().getDeclaredFieldValue(queue.getClass(), "m_queue", queue);
}
public void testNormal() throws Exception {
MessageProducer producer = Cat.getProducer();
Transaction t = producer.newTransaction("URL", "MyPage");
try {
// do your business here
t.addData("k1", "v1");
t.addData("k2", "v2");
t.addData("k3", "v3");
Thread.sleep(20);
producer.logEvent("URL", "Payload", Message.SUCCESS, "host=my-host&ip=127.0.0.1&agent=...");
t.setStatus(Message.SUCCESS);
} catch (Exception e) {
t.setStatus(e);
} finally {
t.complete();
}
// please stop CAT server when you run this test case
Assert.assertEquals("One message should be in the queue.", 1, m_queue.size());
MessageTree tree = m_queue.poll();
Message m = tree.getMessage();
Assert.assertTrue(Transaction.class.isAssignableFrom(m.getClass()));
Transaction trans = (Transaction) m;
Assert.assertEquals("URL", trans.getType());
Assert.assertEquals("MyPage", trans.getName());
Assert.assertEquals("0", trans.getStatus());
Assert.assertTrue(trans.getDurationInMillis() > 0);
Assert.assertEquals("k1=v1&k2=v2&k3=v3", trans.getData().toString());
Assert.assertEquals(1, trans.getChildren().size());
Message c = trans.getChildren().get(0);
Assert.assertEquals("URL", c.getType());
Assert.assertEquals("Payload", c.getName());
Assert.assertEquals("0", c.getStatus());
Assert.assertEquals("host=my-host&ip=127.0.0.1&agent=...", c.getData().toString());