@Test(expected = IllegalStateException.class)
  public void testRemoveAttachmentFail2() {
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");

    transaction.tryEnter(ExecutionPolicy.ALWAYS);
    transaction.canLeave(ExecutionPolicy.ALWAYS);
    transaction.leave(ExecutionPolicy.ALWAYS);

    transaction.removeAttachment();
  }
  @Test
  public void testAttachment3() {
    String oldAttachment = "context";
    String newAttachment = "newnew";
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");

    transaction.tryEnter(ExecutionPolicy.ALWAYS);
    transaction.setAttachment(oldAttachment);
    assertSame(oldAttachment, transaction.getAttachment());
    assertSame(oldAttachment, transaction.setAttachment(newAttachment));
    assertSame(newAttachment, transaction.getAttachment());
    assertSame(newAttachment, transaction.removeAttachment());
    assertNull(transaction.getAttachment());
    transaction.canLeave(ExecutionPolicy.ALWAYS);
    transaction.leave(ExecutionPolicy.ALWAYS);
  }
  @Test
  public void testAttachment2() {
    String attachment = "context";
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");

    transaction.tryEnter(ExecutionPolicy.ALWAYS);
    assertNull(transaction.getAttachment());
    transaction.setAttachment(attachment);
    transaction.canLeave(ExecutionPolicy.ALWAYS);
    transaction.leave(ExecutionPolicy.ALWAYS);

    transaction.tryEnter(ExecutionPolicy.ALWAYS);
    assertNull(transaction.getAttachment());
    transaction.canLeave(ExecutionPolicy.ALWAYS);
    transaction.leave(ExecutionPolicy.ALWAYS);
  }
 private String getMethodUri(Object target) {
   String methodUri = ThriftConstants.UNKNOWN_METHOD_URI;
   InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
   Object attachment = currentTransaction.getAttachment();
   if (attachment instanceof ThriftClientCallContext && target instanceof TBaseAsyncProcessor) {
     ThriftClientCallContext clientCallContext = (ThriftClientCallContext) attachment;
     String methodName = clientCallContext.getMethodName();
     methodUri = ThriftUtils.getAsyncProcessorNameAsUri((TBaseAsyncProcessor<?>) target);
     StringBuilder sb = new StringBuilder(methodUri);
     if (!methodUri.endsWith("/")) {
       sb.append("/");
     }
     sb.append(methodName);
     methodUri = sb.toString();
   }
   return methodUri;
 }
 @Override
 public void after(Object target, Object[] args, Object result, Throwable throwable) {
   if (isDebug) {
     logger.afterInterceptor(target, args, result, throwable);
   }
   if (!validate(target)) {
     return;
   }
   final boolean shouldTrace =
       ((AsyncMarkerFlagFieldAccessor) target)._$PINPOINT$_getAsyncMarkerFlag();
   if (shouldTrace) {
     String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
     if (result instanceof TMessage) {
       TMessage message = (TMessage) result;
       methodName = message.name;
     }
     ThriftClientCallContext clientCallContext = new ThriftClientCallContext(methodName);
     InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
     currentTransaction.setAttachment(clientCallContext);
   }
 }
  @Test
  public void test1() {
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");

    assertFalse(transaction.isActive());

    assertTrue(transaction.tryEnter(ExecutionPolicy.ALWAYS));
    assertTrue(transaction.isActive());

    assertTrue(transaction.tryEnter(ExecutionPolicy.ALWAYS));
    assertTrue(transaction.isActive());

    assertTrue(transaction.canLeave(ExecutionPolicy.ALWAYS));
    assertTrue(transaction.isActive());
    transaction.leave(ExecutionPolicy.ALWAYS);
    assertTrue(transaction.isActive());

    assertTrue(transaction.canLeave(ExecutionPolicy.ALWAYS));
    assertTrue(transaction.isActive());
    transaction.leave(ExecutionPolicy.ALWAYS);
    assertFalse(transaction.isActive());
  }
  @Test
  public void test0() {
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");

    assertFalse(transaction.isActive());

    assertFalse(transaction.tryEnter(ExecutionPolicy.INTERNAL));
    assertFalse(transaction.isActive());

    assertTrue(transaction.tryEnter(ExecutionPolicy.BOUNDARY));
    assertTrue(transaction.isActive());

    assertTrue(transaction.tryEnter(ExecutionPolicy.INTERNAL));
    assertTrue(transaction.isActive());

    assertFalse(transaction.tryEnter(ExecutionPolicy.BOUNDARY));
    assertTrue(transaction.isActive());

    assertFalse(transaction.canLeave(ExecutionPolicy.BOUNDARY));
    assertTrue(transaction.isActive());

    assertTrue(transaction.canLeave(ExecutionPolicy.INTERNAL));
    transaction.leave(ExecutionPolicy.INTERNAL);
    assertTrue(transaction.isActive());

    assertTrue(transaction.canLeave(ExecutionPolicy.BOUNDARY));
    assertTrue(transaction.isActive());
    transaction.leave(ExecutionPolicy.BOUNDARY);
    assertFalse(transaction.isActive());

    assertFalse(transaction.canLeave(ExecutionPolicy.INTERNAL));
    assertFalse(transaction.isActive());
  }
 @Test(expected = IllegalStateException.class)
 public void testAfterWithoutBefore3() {
   InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");
   transaction.leave(ExecutionPolicy.INTERNAL);
 }
 @Test(expected = IllegalStateException.class)
 public void testRemoveAttachmentFail() {
   InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");
   transaction.removeAttachment();
 }