Java Code Examples for com.amazonaws.xray.AWSXRay#endSegment()

The following examples show how to use com.amazonaws.xray.AWSXRay#endSegment() . 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: TracedResponseHandlerTest.java    From aws-xray-sdk-java with Apache License 2.0 6 votes vote down vote up
private Segment segmentInResponseToCode(int code) {
    NoOpResponseHandler responseHandler = new NoOpResponseHandler();
    TracedResponseHandler<String> tracedResponseHandler = new TracedResponseHandler<>(responseHandler);
    HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, code, ""));

    Segment segment = AWSXRay.beginSegment("test");
    AWSXRay.beginSubsegment("someHttpCall");

    try {
        tracedResponseHandler.handleResponse(httpResponse);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    AWSXRay.endSubsegment();
    AWSXRay.endSegment();
    return segment;
}
 
Example 2
Source File: SegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleSegmentListeners() {
    SecondSegmentListener secondSegmentListener = new SecondSegmentListener();
    AWSXRay.getGlobalRecorder().addSegmentListener(secondSegmentListener);
    Segment test = AWSXRay.beginSegment("test");
    String beginAnnotation = test.getAnnotations().get("beginTest").toString();


    Assert.assertEquals(1, secondSegmentListener.getTestVal());

    Assert.assertEquals("isPresent", beginAnnotation);

    AWSXRay.endSegment();
    String endAnnotation = test.getAnnotations().get("endTest").toString();

    Assert.assertEquals("isPresent", endAnnotation);
    Assert.assertEquals(1, secondSegmentListener.getTestVal2());
}
 
Example 3
Source File: CustomSegmentContextTest.java    From aws-xray-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGlobalMapSegmentContext() {
    Segment test = AWSXRay.beginSegment("test");


    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        list.add(i);
    }

    list.parallelStream().forEach(e -> {
        AWSXRay.setTraceEntity(test);
        AWSXRay.createSubsegment("parallelPrint", (subsegment) -> {
        });
    });

    Assert.assertEquals(100, test.getTotalSize().intValue());

    AWSXRay.endSegment();
}
 
Example 4
Source File: SegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnBeginSegment() {
    Segment test = AWSXRay.beginSegment("test");
    String beginAnnotation = test.getAnnotations().get("beginTest").toString();

    Assert.assertEquals("isPresent", beginAnnotation);

    AWSXRay.endSegment();
}
 
Example 5
Source File: SegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnEndSegment() {
    Segment test = AWSXRay.beginSegment("test");
    AWSXRay.endSegment();
    String endAnnotation = test.getAnnotations().get("endTest").toString();

    Assert.assertEquals("isPresent", endAnnotation);
}
 
Example 6
Source File: InvokeTest.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Test
void invokeTest() {
  AWSXRay.beginSegment("blank-java-test");
  String path = "src/test/resources/event.json";
  String eventString = loadJsonFile(path);
  SQSEvent event = gson.fromJson(eventString, SQSEvent.class);
  Context context = new TestContext();
  String requestId = context.getAwsRequestId();
  Handler handler = new Handler();
  String result = handler.handleRequest(event, context);
  assertTrue(result.contains("totalCodeSize"));
  AWSXRay.endSegment();
}
 
Example 7
Source File: TracingInterceptorTest.java    From aws-xray-sdk-java with Apache License 2.0 4 votes vote down vote up
@After
public void teardown() {
    AWSXRay.endSegment();
}