Search in sources :

Example 11 with Emitter

use of com.amazonaws.xray.emitters.Emitter 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());
    });
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) UDPEmitter(com.amazonaws.xray.emitters.UDPEmitter) Emitter(com.amazonaws.xray.emitters.Emitter) Subsegment(com.amazonaws.xray.entities.Subsegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with Emitter

use of com.amazonaws.xray.emitters.Emitter 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);
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) UDPEmitter(com.amazonaws.xray.emitters.UDPEmitter) Emitter(com.amazonaws.xray.emitters.Emitter) Subsegment(com.amazonaws.xray.entities.Subsegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with Emitter

use of com.amazonaws.xray.emitters.Emitter in project aws-xray-sdk-java by aws.

the class AWSXRayRecorderTest method setupAWSXRay.

@Before
public void setupAWSXRay() {
    Emitter blankEmitter = Mockito.mock(Emitter.class);
    Mockito.doReturn(true).when(blankEmitter).sendSegment(Mockito.anyObject());
    Mockito.doReturn(true).when(blankEmitter).sendSubsegment(Mockito.anyObject());
    AWSXRay.setGlobalRecorder(AWSXRayRecorderBuilder.standard().withEmitter(blankEmitter).build());
    AWSXRay.clearTraceEntity();
}
Also used : UDPEmitter(com.amazonaws.xray.emitters.UDPEmitter) Emitter(com.amazonaws.xray.emitters.Emitter)

Example 14 with Emitter

use of com.amazonaws.xray.emitters.Emitter in project aws-xray-sdk-java by aws.

the class CustomSegmentContextTest method setupAWSXRay.

@Before
public void setupAWSXRay() {
    Emitter blankEmitter = Mockito.mock(Emitter.class);
    Mockito.doReturn(true).when(blankEmitter).sendSegment(Mockito.anyObject());
    Mockito.doReturn(true).when(blankEmitter).sendSubsegment(Mockito.anyObject());
    SegmentContextResolverChain chain = new SegmentContextResolverChain();
    chain.addResolver(new GlobalMapSegmentContextResolver());
    AWSXRay.setGlobalRecorder(AWSXRayRecorderBuilder.standard().withEmitter(blankEmitter).withSegmentContextResolverChain(chain).build());
    AWSXRay.clearTraceEntity();
}
Also used : Emitter(com.amazonaws.xray.emitters.Emitter) Before(org.junit.Before)

Example 15 with Emitter

use of com.amazonaws.xray.emitters.Emitter in project aws-xray-sdk-java by aws.

the class LambdaSegmentContextTest method setupAWSXRay.

@Before
public void setupAWSXRay() {
    Emitter blankEmitter = Mockito.mock(Emitter.class);
    Mockito.doReturn(true).when(blankEmitter).sendSegment(Mockito.anyObject());
    Mockito.doReturn(true).when(blankEmitter).sendSubsegment(Mockito.anyObject());
    AWSXRay.setGlobalRecorder(AWSXRayRecorderBuilder.standard().withEmitter(blankEmitter).build());
    AWSXRay.clearTraceEntity();
}
Also used : Emitter(com.amazonaws.xray.emitters.Emitter) Before(org.junit.Before)

Aggregations

Emitter (com.amazonaws.xray.emitters.Emitter)15 UDPEmitter (com.amazonaws.xray.emitters.UDPEmitter)8 Before (org.junit.Before)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Subsegment (com.amazonaws.xray.entities.Subsegment)3 TraceHeader (com.amazonaws.xray.entities.TraceHeader)3 Segment (com.amazonaws.xray.entities.Segment)1