运行我的测试时,它会在调用method()时挂起。 难道我做错了什么? 帮帮我!
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"beans.xml"}) @Transactional(rollbackFor = Exception.class) public class Test { @Test public void test() { itemUnderTestDao.method(); // ... } } public class ItemUnderTestDao { @Transactional(propagation = Propagation.REQUIRES_NEW) public void method() { // ... } }忘记上面的代码。 我现在已经在http://www44.zippyshare.com/v/46865082/file.html上传了一个Eclipse项目(不包括像spring这样的依赖项)。 关于如何让测试通过的所有输入都非常感谢! 如果我有两个sqlite数据库和两个dataSources,测试通过...
When running my test, it hangs at the call to method(). Am I doing something wrong? Help!
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"beans.xml"}) @Transactional(rollbackFor = Exception.class) public class Test { @Test public void test() { itemUnderTestDao.method(); // ... } } public class ItemUnderTestDao { @Transactional(propagation = Propagation.REQUIRES_NEW) public void method() { // ... } }Forget the above code. I have now uploaded an Eclipse project (excluding dependencies like spring) at http://www44.zippyshare.com/v/46865082/file.html. All input on how to get the test to pass is really appreciated! The test pass if I have two sqlite databases and two dataSources...
最满意答案
正如mrembisz所说,你正试图同时获得2个连接/线程。
对于测试本身,其将在测试期间存在 对于方法调用,它将在调用期间存在。我在一些不同的情况下遇到了同样的事情。
有两种方法可以解决这个问题:
将传播更改为REQUIRED ,这样您将重用最初获取的测试的Connection。 增加池大小,但请记住,您需要考虑同时更新的最大数量,大致maxThreadPoolSize >= (maxSimultaniousUpdates + 1) + (min size for other activities) (如果您在列表1挂起连接,最终所有挂起操作将完成)。 Othrewise这将在生产中重新出现。第一个解决方案对我来说似乎更好,当然如果它不会损害你的逻辑:)
As mrembisz said you are trying to get 2 connections at the same time/thread.
For test itself, which would exist for a duration of the test For a method call, which would exist for duration of the call.I encountered the same thing in a little bit different circumstances.
2 ways you can fix this:
Change propagation to REQUIRED, this way you would reuse Connection that test originally acquired. Increase pool size, but keep in mind, that you need to consider max number of simultanious updates, roughly maxThreadPoolSize >= (maxSimultaniousUpdates + 1) + (min size for other activities) (If you have at list 1 pending connection, eventually all pending operations would complete). Othrewise this would reappear in production.First solution seems to me better one, ofcourse if it does not harm your logic :)
更多推荐
发布评论