Search in sources :

Example 1 with IgnoreErrorContextMissingStrategy

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

the class TracingStatementTest method testCaptureRuntimeExceptionWithoutSegment.

@Test
public void testCaptureRuntimeExceptionWithoutSegment() throws Exception {
    ContextMissingStrategy oldStrategy = AWSXRay.getGlobalRecorder().getContextMissingStrategy();
    AWSXRay.getGlobalRecorder().setContextMissingStrategy(new IgnoreErrorContextMissingStrategy());
    try {
        RuntimeException exception = new RuntimeException("foo");
        when(delegate.execute(SQL)).thenThrow(exception);
        try {
            statement.execute(SQL);
            fail("Expected exception is not thrown");
        } catch (RuntimeException th) {
            assertEquals(exception, th);
        }
    } finally {
        AWSXRay.getGlobalRecorder().setContextMissingStrategy(oldStrategy);
    }
}
Also used : IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) ContextMissingStrategy(com.amazonaws.xray.strategy.ContextMissingStrategy) Test(org.junit.Test)

Example 2 with IgnoreErrorContextMissingStrategy

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

the class AWSXRayRecorderTest method testBeginSubsegmentWhenMissingContext.

@Test
public void testBeginSubsegmentWhenMissingContext() {
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withContextMissingStrategy(new IgnoreErrorContextMissingStrategy()).build();
    Subsegment subsegment = recorder.beginSubsegment("hello");
    assertThat(subsegment).isNotNull();
    assertThat(subsegment.getNamespace()).isEmpty();
    // No-op
    subsegment.setNamespace("foo");
    assertThat(subsegment.getNamespace()).isEmpty();
    assertThat(subsegment.shouldPropagate()).isFalse();
}
Also used : IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) Subsegment(com.amazonaws.xray.entities.Subsegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with IgnoreErrorContextMissingStrategy

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

the class TracingStatementTest method testCaptureSqlExceptionWithoutSegment.

@Test
public void testCaptureSqlExceptionWithoutSegment() throws Exception {
    ContextMissingStrategy oldStrategy = AWSXRay.getGlobalRecorder().getContextMissingStrategy();
    AWSXRay.getGlobalRecorder().setContextMissingStrategy(new IgnoreErrorContextMissingStrategy());
    try {
        SQLException exception = new SQLException("foo");
        when(delegate.execute(SQL)).thenThrow(exception);
        try {
            statement.execute(SQL);
            fail("Expected exception is not thrown");
        } catch (SQLException th) {
            assertEquals(exception, th);
        }
    } finally {
        AWSXRay.getGlobalRecorder().setContextMissingStrategy(oldStrategy);
    }
}
Also used : SQLException(java.sql.SQLException) IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) ContextMissingStrategy(com.amazonaws.xray.strategy.ContextMissingStrategy) Test(org.junit.Test)

Example 4 with IgnoreErrorContextMissingStrategy

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

the class AWSXRayRecorderTest method testBeginSubsegmentOnEmptyThreadDoesNotThrowExceptionWithIgnoreErrorContextMissingStrategy.

@Test
public void testBeginSubsegmentOnEmptyThreadDoesNotThrowExceptionWithIgnoreErrorContextMissingStrategy() {
    AWSXRay.getGlobalRecorder().setContextMissingStrategy(new IgnoreErrorContextMissingStrategy());
    AWSXRay.beginSubsegment("test");
}
Also used : IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with IgnoreErrorContextMissingStrategy

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

the class AWSXRayRecorderTest method testBeginSegmentWhenMissingContext.

@Test
public void testBeginSegmentWhenMissingContext() {
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withSegmentContextResolverChain(new SegmentContextResolverChain()).withContextMissingStrategy(new IgnoreErrorContextMissingStrategy()).build();
    Segment segment = recorder.beginSegment("hello");
    assertThat(segment).isNotNull();
    assertThat(segment.getNamespace()).isEmpty();
    // No-op
    segment.setNamespace("foo");
    assertThat(segment.getNamespace()).isEmpty();
}
Also used : SegmentContextResolverChain(com.amazonaws.xray.contexts.SegmentContextResolverChain) IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) Segment(com.amazonaws.xray.entities.Segment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

IgnoreErrorContextMissingStrategy (com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ContextMissingStrategy (com.amazonaws.xray.strategy.ContextMissingStrategy)2 SegmentContextResolverChain (com.amazonaws.xray.contexts.SegmentContextResolverChain)1 Segment (com.amazonaws.xray.entities.Segment)1 Subsegment (com.amazonaws.xray.entities.Subsegment)1 SQLException (java.sql.SQLException)1