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;
}
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);
}
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();
}
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));
}
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());
}
Aggregations