use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSubsegmentWithChildEmittedTogetherInLambdaContext.
@Test
public void testSubsegmentWithChildEmittedTogetherInLambdaContext() {
TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
Emitter mockEmitter = Mockito.mock(UDPEmitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.createSubsegment("testTogether", () -> {
recorder.createSubsegment("testTogether2", () -> {
});
});
ArgumentCaptor<Subsegment> emittedSubsegment = ArgumentCaptor.forClass(Subsegment.class);
Mockito.verify(mockEmitter, Mockito.times(1)).sendSubsegment(emittedSubsegment.capture());
Subsegment captured = emittedSubsegment.getValue();
Assert.assertEquals(1, captured.getSubsegments().size());
}
use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSubsequentSubsegmentBranchesEmittedInLambdaContext.
@Test
public void testSubsequentSubsegmentBranchesEmittedInLambdaContext() {
TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
Emitter mockEmitter = Mockito.mock(UDPEmitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.createSubsegment("testTogether", () -> {
recorder.createSubsegment("testTogether2", () -> {
});
});
recorder.createSubsegment("testTogether3", () -> {
recorder.createSubsegment("testTogether4", () -> {
});
});
ArgumentCaptor<Subsegment> emittedSubsegments = ArgumentCaptor.forClass(Subsegment.class);
Mockito.verify(mockEmitter, Mockito.times(2)).sendSubsegment(emittedSubsegments.capture());
List<Subsegment> captured = emittedSubsegments.getAllValues();
captured.forEach((capturedSubsegment) -> {
Assert.assertEquals(1, capturedSubsegment.getSubsegments().size());
});
}
use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSubsegmentEmittedInLambdaContext.
@Test
public void testSubsegmentEmittedInLambdaContext() throws JSONException {
TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
Emitter mockEmitter = Mockito.mock(UDPEmitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.createSubsegment("test", () -> {
});
ArgumentCaptor<Subsegment> emittedSubsegment = ArgumentCaptor.forClass(Subsegment.class);
Mockito.verify(mockEmitter, Mockito.times(1)).sendSubsegment(emittedSubsegment.capture());
Subsegment captured = emittedSubsegment.getValue();
JSONAssert.assertEquals(expectedLambdaSubsegment(header.getRootTraceId(), header.getParentId(), captured.getId(), captured.getStartTime(), captured.getEndTime()).toString(), captured.streamSerialize(), JSONCompareMode.NON_EXTENSIBLE);
}
use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.
the class TraceHeaderTest method testLongHeaderToString.
@Test
public void testLongHeaderToString() {
TraceHeader header = new TraceHeader();
header.setSampled(SampleDecision.SAMPLED);
header.setRootTraceId(TraceID.fromString(TRACE_ID));
header.setParentId("foo");
header.getAdditionalParams().put("Foo", "bar");
Assert.assertEquals("Root=" + TRACE_ID + ";Parent=foo;Sampled=1;Foo=bar", header.toString());
}
use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.
the class TraceHeaderTest method testSampledEqualsOneFromString.
@Test
public void testSampledEqualsOneFromString() {
TraceHeader header = TraceHeader.fromString("Sampled=1");
Assert.assertEquals(SampleDecision.SAMPLED, header.getSampled());
Assert.assertNull(header.getRootTraceId());
Assert.assertNull(header.getParentId());
Assert.assertTrue(header.getAdditionalParams().isEmpty());
}
Aggregations