use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testExplicitSubsegmentEmitted.
@Test
public void testExplicitSubsegmentEmitted() {
Emitter mockEmitter = Mockito.mock(Emitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.beginSegment("test");
Subsegment subsegment = recorder.beginSubsegment("test");
recorder.endSubsegment(subsegment);
recorder.endSegment();
Mockito.verify(mockEmitter, Mockito.times(1)).sendSegment(any());
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testGetThreadLocalReturnsCurrentSubsegment.
@Test
public void testGetThreadLocalReturnsCurrentSubsegment() {
AWSXRay.beginSegment("test");
Subsegment subsegment = AWSXRay.beginSubsegment("test");
Assert.assertEquals(subsegment, AWSXRay.getTraceEntity());
AWSXRay.endSubsegment();
AWSXRay.endSegment();
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class DefaultStreamingStrategyTest method testStreamSomeChildrenNotRemovedFromParent.
// test to see if the correct actions are being taken in streamSome (children do NOT get removed from parent due to subsegments
// being in progress.)
@Test
public void testStreamSomeChildrenNotRemovedFromParent() {
TraceID traceId = new TraceID();
DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
Segment bigSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "big", traceId);
bigSegment.setStartTime(1.0);
for (int i = 0; i < 5; i++) {
Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "child" + i, bigSegment);
subsegment.setStartTime(1.0);
bigSegment.addSubsegment(subsegment);
}
Assert.assertTrue(defaultStreamingStrategy.requiresStreaming(bigSegment));
defaultStreamingStrategy.streamSome(bigSegment, AWSXRay.getGlobalRecorder().getEmitter());
Assert.assertTrue(bigSegment.getTotalSize().intValue() == 5);
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class DefaultStreamingStrategyTest method testingBasicStreamingFunctionality.
@Test
public void testingBasicStreamingFunctionality() {
DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
TraceID traceId = new TraceID();
Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceId);
Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
Subsegment subsegment1 = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
segment.addSubsegment(subsegment);
segment.addSubsegment(subsegment1);
segment.setStartTime(1.0);
subsegment.setStartTime(1.0);
subsegment1.setStartTime(1.0);
subsegment.end();
defaultStreamingStrategy.streamSome(segment, AWSXRay.getGlobalRecorder().getEmitter());
Assert.assertTrue(segment.getTotalSize().intValue() == 1);
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class DefaultStreamingStrategyTest method testDefaultStreamingStrategyForLambdaTraceContext.
// test to see if FacadeSegment can be streamed out correctly
@Test
public void testDefaultStreamingStrategyForLambdaTraceContext() {
DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
// if FacadeSegment size is larger than maxSegmentSize and only the first subsegment is completed, first subsegment will be
// streamed out
FacadeSegment facadeSegmentOne = new FacadeSegment(AWSXRay.getGlobalRecorder(), new TraceID(), "", TraceHeader.SampleDecision.SAMPLED);
Subsegment firstSubsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "FirstSubsegment", facadeSegmentOne);
Subsegment secondSubsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "SecondSubsegment", facadeSegmentOne);
facadeSegmentOne.addSubsegment(firstSubsegment);
facadeSegmentOne.addSubsegment(secondSubsegment);
firstSubsegment.end();
Assert.assertTrue(facadeSegmentOne.getTotalSize().intValue() == 2);
defaultStreamingStrategy.streamSome(facadeSegmentOne, AWSXRay.getGlobalRecorder().getEmitter());
Assert.assertTrue(facadeSegmentOne.getTotalSize().intValue() == 1);
Subsegment tempOne = facadeSegmentOne.getSubsegments().get(0);
Assert.assertEquals("SecondSubsegment", tempOne.getName());
// if FarcadeSegment size is larger than maxSegmentSize and only the second subsegment is completed, second subsegment will
// be streamed out
FacadeSegment facadeSegmentTwo = new FacadeSegment(AWSXRay.getGlobalRecorder(), new TraceID(), "", TraceHeader.SampleDecision.SAMPLED);
Subsegment thirdSubsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "ThirdSubsegment", facadeSegmentTwo);
Subsegment fourthSubsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "FourthSubsegment", facadeSegmentTwo);
facadeSegmentTwo.addSubsegment(thirdSubsegment);
facadeSegmentTwo.addSubsegment(fourthSubsegment);
fourthSubsegment.end();
Assert.assertTrue(facadeSegmentTwo.getTotalSize().intValue() == 2);
defaultStreamingStrategy.streamSome(facadeSegmentTwo, AWSXRay.getGlobalRecorder().getEmitter());
Assert.assertTrue(facadeSegmentTwo.getTotalSize().intValue() == 1);
Subsegment tempTwo = facadeSegmentTwo.getSubsegments().get(0);
Assert.assertEquals("ThirdSubsegment", tempTwo.getName());
}
Aggregations