9
9
import net.sf.ehcache.Element;
10
10
import net.sf.ehcache.config.CacheConfiguration;
11
11
import net.sf.ehcache.config.Configuration;
12
import net.sf.ehcache.transaction.TransactionTimeoutException;
12
13
import org.junit.After;
13
14
import org.junit.Before;
14
15
import org.junit.Test;
17
import java.lang.reflect.Field;
20
import javax.transaction.RollbackException;
16
21
import javax.transaction.Status;
23
import static org.junit.Assert.assertEquals;
24
import static org.junit.Assert.fail;
39
47
.maxEntriesLocalHeap(10)
40
48
.transactionalMode(CacheConfiguration.TransactionalMode.XA_STRICT)));
42
transactionManager.begin();
43
50
xaCache1 = cacheManager.getEhcache("xaCache1");
51
xaCache2 = cacheManager.getEhcache("xaCache2");
54
private void clearAll() throws Exception {
55
transactionManager.begin();
44
56
xaCache1.removeAll();
45
xaCache2 = cacheManager.getEhcache("xaCache2");
46
57
xaCache2.removeAll();
47
58
transactionManager.commit();
87
99
transactionManager.commit();
103
public void testTimeout() throws Exception {
104
xaCache1.getCacheManager().getTransactionController().setDefaultTransactionTimeout(5);
106
transactionManager.setTransactionTimeout(2);
107
transactionManager.begin();
109
// get doesn't enlist -> XATransactionStore will set this cache's XA timeout for this TX to be the default local TX timeout
113
// XA tx timed out but the resource doesn't know about it -> call succeeds
117
// cache's XA timeout for this TX reached -> fail
120
fail("expected TransactionTimeoutException");
121
} catch (TransactionTimeoutException e) {
126
// this XA tx timed out
127
transactionManager.commit();
128
fail("expected RollbackException");
129
} catch (RollbackException e) {
133
// check that there is no internal leak (EHC-937)
134
assertEquals(0, ((Map)getStoreField(xaCache1, "transactionToTimeoutMap")).size());
137
private static Object getStoreField(Ehcache cache, String storeFieldName) throws IllegalAccessException, NoSuchFieldException {
138
Field storeField = cache.getClass().getDeclaredField("compoundStore");
139
storeField.setAccessible(true);
140
XATransactionStore store = (XATransactionStore)storeField.get(cache);
142
Field field = store.getClass().getDeclaredField(storeFieldName);
143
field.setAccessible(true);
144
return field.get(store);
b'\\ No newline at end of file'