Frage

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...

War es hilfreich?

Lösung

As mrembisz said you are trying to get 2 connections at the same time/thread.

  1. For test itself, which would exist for a duration of the test
  2. 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:

  1. Change propagation to REQUIRED, this way you would reuse Connection that test originally acquired.
  2. 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 :)

Andere Tipps

You are trying to open second connection to the database. The first one is opened because of @Transactional for class Test, REQUIRES_NEW on method() forces another connection.

Probably your connection pool allows only one concurrent connection. Check its size and database configuration.

Also run through your questions and mark selected answers as accepted (a checkmark shape next to the answer body).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top