Search in sources :

Example 11 with SamplingResponse

use of com.amazonaws.xray.strategy.sampling.SamplingResponse in project aws-xray-sdk-java by aws.

the class AWSXRayRecorderTest method testBeginSegmentWithForcedSampling.

@Test
public void testBeginSegmentWithForcedSampling() {
    SamplingResponse response = new SamplingResponse(false, "rule");
    when(mockSamplingStrategy.isForcedSamplingSupported()).thenReturn(true);
    when(mockSamplingStrategy.shouldTrace(any())).thenReturn(response);
    AWSXRay.getGlobalRecorder().setSamplingStrategy(mockSamplingStrategy);
    Segment segment = AWSXRay.beginSegmentWithSampling("test");
    assertThat(segment.isSampled()).isFalse();
    segment.setUser("user");
    // Loose way to test that segment is real
    assertThat(segment.getUser()).isEqualTo("user");
}
Also used : Segment(com.amazonaws.xray.entities.Segment) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with SamplingResponse

use of com.amazonaws.xray.strategy.sampling.SamplingResponse in project aws-xray-sdk-java by aws.

the class AWSXRayRecorderTest method testBeginSegmentWithSamplingDoesNotSample.

@Test
public void testBeginSegmentWithSamplingDoesNotSample() {
    SamplingResponse response = new SamplingResponse(false, "rule");
    when(mockSamplingStrategy.shouldTrace(any())).thenReturn(response);
    AWSXRay.getGlobalRecorder().setSamplingStrategy(mockSamplingStrategy);
    Segment segment = AWSXRay.beginSegmentWithSampling("test");
    assertThat(segment.isSampled()).isFalse();
    segment.setUser("user");
    // Loose way to test that segment is a no-op
    assertThat(segment.getUser()).isEmpty();
}
Also used : Segment(com.amazonaws.xray.entities.Segment) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SamplingResponse (com.amazonaws.xray.strategy.sampling.SamplingResponse)12 Test (org.junit.Test)8 SamplingRule (com.amazonaws.services.xray.model.SamplingRule)5 SamplingTargetDocument (com.amazonaws.services.xray.model.SamplingTargetDocument)5 Segment (com.amazonaws.xray.entities.Segment)5 Clock (java.time.Clock)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AWSXRayRecorder (com.amazonaws.xray.AWSXRayRecorder)2 SamplingRequest (com.amazonaws.xray.strategy.sampling.SamplingRequest)2 FacadeSegment (com.amazonaws.xray.entities.FacadeSegment)1 TraceHeader (com.amazonaws.xray.entities.TraceHeader)1 SampleDecision (com.amazonaws.xray.entities.TraceHeader.SampleDecision)1 TraceID (com.amazonaws.xray.entities.TraceID)1 SamplingStrategy (com.amazonaws.xray.strategy.sampling.SamplingStrategy)1 RandImpl (com.amazonaws.xray.strategy.sampling.rand.RandImpl)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1