MockTracerContextListenerTestCase.java 2.5 KB
Newer Older
P
pengys5 已提交
1
package org.skywalking.apm.sniffer.mock;
wu-sheng's avatar
wu-sheng 已提交
2 3

import org.junit.Assert;
4
import org.junit.BeforeClass;
wu-sheng's avatar
wu-sheng 已提交
5
import org.junit.Test;
6
import org.skywalking.apm.agent.core.boot.ServiceManager;
P
pengys5 已提交
7 8 9 10
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
import org.skywalking.apm.sniffer.mock.context.SegmentAssert;
import org.skywalking.apm.sniffer.mock.trace.TraceSegmentBuilderFactory;
import org.skywalking.apm.trace.TraceSegment;
wu-sheng's avatar
wu-sheng 已提交
11 12 13 14

/**
 * Created by wusheng on 2017/2/21.
 */
15
public class MockTracerContextListenerTestCase {
16
    @BeforeClass
17
    public static void setup() {
18
        ServiceManager.INSTANCE.boot();
19 20
    }

wu-sheng's avatar
wu-sheng 已提交
21
    @Test
22
    public void testAfterFinished() {
wu-sheng's avatar
wu-sheng 已提交
23 24 25 26 27
        MockTracerContextListener listener = new MockTracerContextListener();
        listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat200Trace());

        Assert.assertNotNull(listener.getFinished(0));
    }
wu-sheng's avatar
wu-sheng 已提交
28 29

    @Test(expected = AssertionError.class)
30
    public void testAssertSize() {
wu-sheng's avatar
wu-sheng 已提交
31 32 33 34 35 36 37
        MockTracerContextListener listener = new MockTracerContextListener();
        listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat404Trace());

        listener.assertSize(0);
    }

    @Test
38
    public void testAssertTraceSegment() {
wu-sheng's avatar
wu-sheng 已提交
39 40 41 42 43
        MockTracerContextListener listener = new MockTracerContextListener();
        listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat404Trace());
        listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat500Trace());

        listener.assertTraceSegment(0, new SegmentAssert() {
P
pengys5 已提交
44 45
            @Override
            public void call(TraceSegment finishedSegment) {
wu-sheng's avatar
wu-sheng 已提交
46 47 48 49 50 51
                Assert.assertNotNull(finishedSegment);
            }
        });
    }

    @Test(expected = AssertionError.class)
52
    public void testClear() {
wu-sheng's avatar
wu-sheng 已提交
53 54 55 56 57 58 59
        MockTracerContextListener listener = new MockTracerContextListener();
        listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat404Trace());
        listener.afterFinished(TraceSegmentBuilderFactory.INSTANCE.singleTomcat500Trace());

        listener.clear();
        listener.assertValidIndex(0);
    }
60 61

    @Test
62
    public void testTraceOf_Tomcat_DubboClient() {
63 64 65 66 67 68
        TraceSegment segment = TraceSegmentBuilderFactory.INSTANCE.traceOf_Tomcat_DubboClient();

        Assert.assertEquals(2, segment.getSpans().size());
    }

    @Test
69
    public void testTraceOf_DubboServer_MySQL() {
70 71 72 73
        TraceSegment segment = TraceSegmentBuilderFactory.INSTANCE.traceOf_DubboServer_MySQL();

        Assert.assertEquals(2, segment.getSpans().size());
    }
wu-sheng's avatar
wu-sheng 已提交
74
}