/
APITxTest.java
106 lines (91 loc) · 3.13 KB
/
APITxTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package org.infinispan.api;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.testng.annotations.Test;
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import static org.testng.AssertJUnit.assertEquals;
/**
* @author William Burns
* @since 7.2
*/
@Test (groups = "functional", testName = "api.APITxTest")
public class APITxTest extends APINonTxTest {
@Override
protected EmbeddedCacheManager createCacheManager() throws Exception {
// start a single cache instance
ConfigurationBuilder c = getDefaultStandaloneCacheConfig(true);
EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(false);
cm.defineConfiguration("test", c.build());
cache = cm.getCache("test");
return cm;
}
public void testSizeInExplicitTxWithNonExistent() throws SystemException, NotSupportedException {
assertEquals(0, cache.size());
cache.put("k", "v");
TransactionManager tm1 = TestingUtil.getTransactionManager(cache);
tm1.begin();
try {
cache.get("no-exist");
assertEquals(1, cache.size());
cache.put("no-exist", "value");
assertEquals(2, cache.size());
} finally {
tm1.rollback();
}
}
public void testSizeInExplicitTxWithRemoveNonExistent() throws SystemException, NotSupportedException {
assertEquals(0, cache.size());
cache.put("k", "v");
TransactionManager tm1 = TestingUtil.getTransactionManager(cache);
tm1.begin();
try {
cache.remove("no-exist");
assertEquals(1, cache.size());
cache.put("no-exist", "value");
assertEquals(2, cache.size());
} finally {
tm1.rollback();
}
}
public void testSizeInExplicitTxWithRemoveExistent() throws SystemException, NotSupportedException {
assertEquals(0, cache.size());
cache.put("k", "v");
TransactionManager tm1 = TestingUtil.getTransactionManager(cache);
tm1.begin();
try {
cache.put("exist", "value");
assertEquals(2, cache.size());
cache.remove("exist");
assertEquals(1, cache.size());
} finally {
tm1.rollback();
}
}
public void testSizeInExplicitTx() throws SystemException, NotSupportedException {
assertEquals(0, cache.size());
cache.put("k", "v");
TransactionManager tm1 = TestingUtil.getTransactionManager(cache);
tm1.begin();
try {
assertEquals(1, cache.size());
} finally {
tm1.rollback();
}
}
public void testSizeInExplicitTxWithModification() throws SystemException, NotSupportedException {
assertEquals(0, cache.size());
cache.put("k1", "v1");
TransactionManager tm1 = TestingUtil.getTransactionManager(cache);
tm1.begin();
try {
cache.put("k2", "v2");
assertEquals(2, cache.size());
} finally {
tm1.rollback();
}
}
}