com.amazonaws.xray.contexts.LambdaSegmentContext Java Examples
The following examples show how to use
com.amazonaws.xray.contexts.LambdaSegmentContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWSXRayRecorderTest.java From aws-xray-sdk-java with Apache License 2.0 | 6 votes |
@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(Emitter.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); }
Example #2
Source File: AWSXRayRecorderTest.java From aws-xray-sdk-java with Apache License 2.0 | 6 votes |
@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(Emitter.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()); }
Example #3
Source File: AWSXRayRecorderTest.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
@Test public void testSubsegmentNotEmittedWithoutExceptionInLambdaInitContext() { PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")) .toReturn(TraceHeader.fromString(null)); PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task"); Emitter mockEmitter = Mockito.mock(Emitter.class); AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build(); recorder.createSubsegment("test", () -> { }); Mockito.verify(mockEmitter, Mockito.times(0)).sendSubsegment(Mockito.any()); }
Example #4
Source File: AWSXRayRecorderTest.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
@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(Emitter.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()); }); }