Search in sources :

Example 1 with SubsegmentImpl

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

the class ThreadLocalSegmentContext method beginSubsegment.

@Override
public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) {
    Entity current = getTraceEntity();
    if (null == current) {
        recorder.getContextMissingStrategy().contextMissing("Failed to begin subsegment named '" + name + "': segment cannot be found.", SegmentNotFoundException.class);
        return null;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Beginning subsegment named: " + name);
    }
    Segment parentSegment = getTraceEntity().getParentSegment();
    Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSegment);
    subsegment.setParent(current);
    current.addSubsegment(subsegment);
    setTraceEntity(subsegment);
    return subsegment;
}
Also used : Entity(com.amazonaws.xray.entities.Entity) SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment)

Example 2 with SubsegmentImpl

use of com.amazonaws.xray.entities.SubsegmentImpl 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 3 with SubsegmentImpl

use of com.amazonaws.xray.entities.SubsegmentImpl 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 4 with SubsegmentImpl

use of com.amazonaws.xray.entities.SubsegmentImpl 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 SubsegmentImpl

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

the class EntityTest method testAllSubsegmentImplMutationMethodsThrowAlreadyEmittedExceptions.

@Test
public void testAllSubsegmentImplMutationMethodsThrowAlreadyEmittedExceptions() {
    SegmentImpl segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test");
    segment.getName();
    SubsegmentImpl subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
    MutatingMethodCount mutationResults = numberOfMutatingMethodsThatThrewException(subsegment, SubsegmentImpl.class);
    Assert.assertEquals(0, mutationResults.getMutatingMethodsThrowingExceptions());
    // the mutating methods set this to null...
    subsegment.setParentSegment(segment);
    segment.end();
    subsegment.end();
    mutationResults = numberOfMutatingMethodsThatThrewException(subsegment, SubsegmentImpl.class);
    Assert.assertEquals(mutationResults.getMutatingMethods(), mutationResults.getMutatingMethodsThrowingExceptions());
}
Also used : SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Test(org.junit.Test)

Aggregations

SubsegmentImpl (com.amazonaws.xray.entities.SubsegmentImpl)7 SegmentImpl (com.amazonaws.xray.entities.SegmentImpl)5 Test (org.junit.Test)5 Segment (com.amazonaws.xray.entities.Segment)4 Subsegment (com.amazonaws.xray.entities.Subsegment)3 TraceID (com.amazonaws.xray.entities.TraceID)2 Entity (com.amazonaws.xray.entities.Entity)1 FacadeSegment (com.amazonaws.xray.entities.FacadeSegment)1