コード例 #1
0
  @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());
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
  @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();
  }
コード例 #4
0
  @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());
  }
コード例 #5
0
  @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);
  }