Search in sources :

Example 1 with SegmentImpl

use of com.amazonaws.xray.entities.SegmentImpl in project aws-xray-sdk-java by aws.

the class EntityTest method testSegmentWithSubsegment.

@Test
public void testSegmentWithSubsegment() throws JSONException {
    TraceID traceId = new TraceID();
    Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceId);
    Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
    segment.addSubsegment(subsegment);
    segment.setStartTime(1.0);
    subsegment.setStartTime(1.0);
    subsegment.end();
    segment.end();
    String expected = expectedCompletedSegmentWithSubsegment(traceId, segment.getId(), subsegment.getId(), 1.0, subsegment.getEndTime(), segment.getEndTime()).toString();
    JSONAssert.assertEquals(expected, segment.serialize(), JSONCompareMode.NON_EXTENSIBLE);
}
Also used : TraceID(com.amazonaws.xray.entities.TraceID) SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 2 with SegmentImpl

use of com.amazonaws.xray.entities.SegmentImpl in project aws-xray-sdk-java by aws.

the class EntityTest method testEndingSubsegmentImplAfterStreamingThrowsAlreadyEmittedException.

@Test(expected = AlreadyEmittedException.class)
public void testEndingSubsegmentImplAfterStreamingThrowsAlreadyEmittedException() {
    SegmentImpl segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test");
    SubsegmentImpl firstSubsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
    firstSubsegment.end();
    for (int i = 0; i < 100; i++) {
        // add enough subsegments to trigger the DefaultStreamingStrategy and stream subsegments
        SubsegmentImpl current = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
        current.end();
    }
    segment.end();
    firstSubsegment.end();
}
Also used : SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Test(org.junit.Test)

Example 3 with SegmentImpl

use of com.amazonaws.xray.entities.SegmentImpl in project aws-xray-sdk-java by aws.

the class EntityTest method testEndingSegmentImplTwiceThrowsAlreadyEmittedException.

@Test(expected = AlreadyEmittedException.class)
public void testEndingSegmentImplTwiceThrowsAlreadyEmittedException() {
    SegmentImpl segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test");
    segment.getName();
    segment.end();
    segment.end();
}
Also used : SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Test(org.junit.Test)

Example 4 with SegmentImpl

use of com.amazonaws.xray.entities.SegmentImpl in project aws-xray-sdk-java by aws.

the class DefaultStreamingStrategyTest method testDefaultStreamingStrategyRequiresStreaming.

@Test
public void testDefaultStreamingStrategyRequiresStreaming() {
    DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
    Segment smallSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "small");
    Assert.assertFalse(defaultStreamingStrategy.requiresStreaming(smallSegment));
    Segment bigSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "big");
    bigSegment.addSubsegment(new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child", bigSegment));
    bigSegment.addSubsegment(new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child", bigSegment));
    Assert.assertTrue(defaultStreamingStrategy.requiresStreaming(bigSegment));
}
Also used : SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 5 with SegmentImpl

use of com.amazonaws.xray.entities.SegmentImpl in project aws-xray-sdk-java by aws.

the class EntityTest method testAllSegmentImplMutationMethodsThrowAlreadyEmittedExceptions.

@Test
public void testAllSegmentImplMutationMethodsThrowAlreadyEmittedExceptions() {
    SegmentImpl segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test");
    MutatingMethodCount mutationResults = numberOfMutatingMethodsThatThrewException(segment, SegmentImpl.class);
    Assert.assertEquals(0, mutationResults.getMutatingMethodsThrowingExceptions());
    segment.end();
    mutationResults = numberOfMutatingMethodsThatThrewException(segment, SegmentImpl.class);
    Assert.assertEquals(mutationResults.getMutatingMethods(), mutationResults.getMutatingMethodsThrowingExceptions());
}
Also used : SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Test(org.junit.Test)

Aggregations

SegmentImpl (com.amazonaws.xray.entities.SegmentImpl)9 Test (org.junit.Test)9 SubsegmentImpl (com.amazonaws.xray.entities.SubsegmentImpl)5 Segment (com.amazonaws.xray.entities.Segment)4 TraceID (com.amazonaws.xray.entities.TraceID)3 Subsegment (com.amazonaws.xray.entities.Subsegment)1