質問

を使用していTestNG試験持続春モジュール(JPA+Hibernate)を使用AbstractTransactionalTestNGSpringcontexttestsとしての基底クラスです。すべての重要な部品@Autowired,@TransactionConfiguration,@係の仕事です。

の問題が出たいと考えているときの走行試験と並行スレッドとthreadPoolSize=x,invocationCount=y TestNGのアノテーションを期待で

WARNING: Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@174202a] 
to process 'before' execution of test method [testCreate()] for test instance [DaoTest] java.lang.IllegalStateException:
Cannot start new transaction without ending existing transaction: Invoke endTransaction() before startNewTransaction().
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:123)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:374)
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextBeforeTestMethod(AbstractTestNGSpringContextTests.java:146)

...は誰もが抱えるのですが。

こちらのコード:

@TransactionConfiguration(defaultRollback = false)
@ContextConfiguration(locations = { "/META-INF/app.xml" })
public class DaoTest extends AbstractTransactionalTestNGSpringContextTests {

@Autowired
private DaoMgr dm;

@Test(threadPoolSize=5, invocationCount=10)
public void testCreate() {
    ...
    dao.persist(o);
    ...
}
...

更新: こAbstractTransactionalTestNGSpringcontexttestsを維持取引のみメインスレッドが他のすべての試験のスレッドさん自身の取引のインスタンス.唯一の解決方法の一つとするものであるAbstractTestNGSpringContextTests-維持取引プログラムの代わりに、@係アノテーション)と各手法(とTransactionTemplate):

@Test(threadPoolSize=5, invocationCount=10)
public void testMethod() {
    new TransactionTemplate(txManager).execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            // transactional test logic goes here
        }
    }
}
役に立ちましたか?

解決

の取引を開始する必要があるのと同じスレッドが、こちらのより詳細:

Spring3/Hibernate3/TestNG:一部の試験LazyInitializationExceptionあん

他のヒント

だと思いませんでからorg.springframework.テストです。コンテキストTestContextManagerれていないスレッドに対して安全を参照 https://jira.springsource.org/browse/SPR-5863)?

私が抱えるとともに、同誌掲載号の注目がたかったの打上げに私の取引TestNG試験に平行に見ることができる春に実を結合する取引の右ねじになります。

しかしこに失敗したランダムにこのような誤差は生じません。まAbstractTransactionalTestNGSpringcontexttests:

@Override
@BeforeMethod(alwaysRun = true)
protected synchronized void springTestContextBeforeTestMethod(
        Method testMethod) throws Exception {
    super.springTestContextBeforeTestMethod(testMethod);
}

@Override
@AfterMethod(alwaysRun = true)
protected synchronized void springTestContextAfterTestMethod(
        Method testMethod) throws Exception {
    super.springTestContextAfterTestMethod(testMethod);
}

(あるキーを同期...)

では、現在のような魅力です。ひときわ目立つ大きな春3.2ができるようcompletly parallized!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top