Search in sources :

Example 1 with SqlMapClientDaoSupport

use of com.thoughtworks.go.server.transaction.SqlMapClientDaoSupport in project gocd by gocd.

the class GoCacheTest method shouldStartServingThingsOutOfCacheOnceTransactionCompletes.

@Test
public void shouldStartServingThingsOutOfCacheOnceTransactionCompletes() {
    final SqlMapClientDaoSupport daoSupport = new SqlMapClientDaoSupport(goCache, sqlMapClient, systemEnvironment, databaseStrategy);
    goCache.put("foo", "bar");
    final String[] valueInCleanTxn = new String[1];
    final String[] valueInDirtyTxn = new String[1];
    final String[] valueInAfterCommit = new String[1];
    final String[] valueInAfterCompletion = new String[1];
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            valueInCleanTxn[0] = (String) goCache.get("foo");
            User user = new User("loser", "Massive Loser", "boozer@loser.com");
            userSqlMapDao.saveOrUpdate(user);
            valueInDirtyTxn[0] = (String) goCache.get("foo");
            transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

                @Override
                public void afterCommit() {
                    valueInAfterCommit[0] = (String) goCache.get("foo");
                }

                @Override
                public void afterCompletion(int status) {
                    valueInAfterCompletion[0] = (String) goCache.get("foo");
                }
            });
        }
    });
    assertThat(valueInCleanTxn[0], is("bar"));
    assertThat(valueInDirtyTxn[0], is(nullValue()));
    assertThat(valueInAfterCommit[0], is("bar"));
    assertThat(valueInAfterCompletion[0], is("bar"));
}
Also used : User(com.thoughtworks.go.domain.User) NullUser(com.thoughtworks.go.domain.NullUser) TransactionStatus(org.springframework.transaction.TransactionStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) SqlMapClientDaoSupport(com.thoughtworks.go.server.transaction.SqlMapClientDaoSupport) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Test(org.junit.Test)

Aggregations

NullUser (com.thoughtworks.go.domain.NullUser)1 User (com.thoughtworks.go.domain.User)1 SqlMapClientDaoSupport (com.thoughtworks.go.server.transaction.SqlMapClientDaoSupport)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1 TransactionSynchronizationAdapter (org.springframework.transaction.support.TransactionSynchronizationAdapter)1