Search in sources :

Example 6 with DefaultInterceptorScopeDefinition

use of com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition in project pinpoint by naver.

the class ThreadLocalScopePoolTest method testGetOrCreate.

@Test
public void testGetOrCreate() throws Exception {
    ScopePool pool = new ThreadLocalScopePool();
    InterceptorScopeInvocation scope = pool.getScope(new DefaultInterceptorScopeDefinition("test"));
    scope.tryEnter(ExecutionPolicy.BOUNDARY);
    scope.tryEnter(ExecutionPolicy.BOUNDARY);
    Assert.assertNull(scope.getAttachment());
    Assert.assertEquals(scope.getOrCreateAttachment(new AttachmentFactory() {

        @Override
        public Object createAttachment() {
            return "test";
        }
    }), "test");
    scope.canLeave(ExecutionPolicy.BOUNDARY);
    Assert.assertEquals(scope.getAttachment(), "test");
    Assert.assertTrue(scope.canLeave(ExecutionPolicy.BOUNDARY));
    scope.leave(ExecutionPolicy.BOUNDARY);
    Assert.assertEquals("name", scope.getName(), "test");
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) DefaultInterceptorScopeDefinition(com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition) AttachmentFactory(com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory) Test(org.junit.Test)

Aggregations

DefaultInterceptorScopeDefinition (com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition)6 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)6 Test (org.junit.Test)6 AttachmentFactory (com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)1