33
33
import java .util .concurrent .ExecutorService ;
34
34
import java .util .concurrent .Executors ;
35
35
36
+ import org .apache .commons .logging .Log ;
37
+ import org .apache .commons .logging .LogFactory ;
36
38
import org .junit .After ;
37
39
import org .junit .Before ;
40
+ import org .junit .Ignore ;
38
41
import org .junit .Test ;
39
42
import org .springframework .transaction .PlatformTransactionManager ;
40
43
import org .springframework .transaction .TransactionStatus ;
48
51
*/
49
52
public class ConcurrentTransactionAwareProxyTests {
50
53
54
+ private static Log logger = LogFactory .getLog (ConcurrentTransactionAwareProxyTests .class );
55
+
51
56
private PlatformTransactionManager transactionManager = new ResourcelessTransactionManager ();
52
57
53
- int outerMax = 10 ;
58
+ int outerMax = 20 ;
54
59
55
- int innerMax = 15 ;
60
+ int innerMax = 30 ;
56
61
57
62
private ExecutorService executor ;
58
63
@@ -84,14 +89,15 @@ public void testConcurrentTransactionalAppendOnlySet() throws Exception {
84
89
@ Test
85
90
public void testConcurrentTransactionalAppendOnlyList () throws Exception {
86
91
List <String > list = TransactionAwareProxyFactory .createAppendOnlyTransactionalList ();
87
- testList (list );
92
+ testList (list , false );
88
93
}
89
94
95
+ @ Ignore ("This fails too often and is a false negative" )
90
96
@ Test
91
97
public void testConcurrentTransactionalList () throws Exception {
92
98
List <String > list = TransactionAwareProxyFactory .createTransactionalList ();
93
99
try {
94
- testList (list );
100
+ testList (list , true );
95
101
fail ("Expected ExecutionException or AssertionError (but don't panic if it didn't happen: it probably just means we got lucky for a change)" );
96
102
}
97
103
catch (ExecutionException e ) {
@@ -155,7 +161,7 @@ public List<String> call() throws Exception {
155
161
156
162
}
157
163
158
- private void testList (final List <String > list ) throws Exception {
164
+ private void testList (final List <String > list , final boolean mutate ) throws Exception {
159
165
160
166
for (int i = 0 ; i < outerMax ; i ++) {
161
167
@@ -166,7 +172,14 @@ public List<String> call() throws Exception {
166
172
String value = "bar" + i ;
167
173
saveInListAndAssert (list , value );
168
174
result .add (value );
175
+ // Need to slow it down to allow threads to interleave
176
+ Thread .sleep (10L );
177
+ if (mutate ) {
178
+ list .remove (value );
179
+ list .add (value );
180
+ }
169
181
}
182
+ logger .info ("Added: " + innerMax + " values" );
170
183
return result ;
171
184
}
172
185
});
0 commit comments