@Test
  public void testNestedTransactional() throws Throwable {
    // create mocks
    TransactionalLocks transactionalLocks = m_injector.getInstance(TransactionalLocks.class);
    ReadWriteLock readWriteLock = EasyMock.createStrictMock(ReadWriteLock.class);
    Lock readLock = EasyMock.createStrictMock(Lock.class);
    Lock writeLock = EasyMock.createStrictMock(Lock.class);

    // expectations
    EasyMock.expect(transactionalLocks.getLock(LockArea.HRC_STATUS_CACHE)).andReturn(readWriteLock).times(2);
    EasyMock.expect(readWriteLock.writeLock()).andReturn(writeLock).times(2);
    writeLock.lock();
    EasyMock.expectLastCall().once();
    writeLock.unlock();
    EasyMock.expectLastCall().once();

    // replay
    EasyMock.replay(transactionalLocks, readWriteLock, readLock, writeLock);

    // invoke method with annotations
    TestObject testObject = m_injector.getInstance(TestObject.class);
    testObject.testLockMethodAsChildOfActiveTransaction();

    // verify locks are called
    EasyMock.verify(transactionalLocks, readWriteLock, readLock, writeLock);
  }
Tests that a {@link TransactionalLock} called within the constructs of an
earlier transaction will still lock.

@throws Throwable
ambari-server/src/test/java/org/apache/ambari/annotations/TransactionalLockInterceptorTest.java