1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
34
34
import org .springframework .aop .Advisor ;
35
35
import org .springframework .aop .ProxyMethodInvocation ;
36
36
import org .springframework .aop .framework .Advised ;
37
+ import org .springframework .context .Lifecycle ;
37
38
import org .springframework .context .support .ClassPathXmlApplicationContext ;
38
39
import org .springframework .integration .endpoint .PollingConsumer ;
39
40
import org .springframework .integration .test .util .TestUtils ;
@@ -68,8 +69,9 @@ public void transactionWithCommit() throws InterruptedException {
68
69
PollableChannel output = (PollableChannel ) context .getBean ("output" );
69
70
assertEquals (0 , txManager .getCommitCount ());
70
71
assertEquals (0 , txManager .getRollbackCount ());
71
- input .send (new GenericMessage <String >("test" ));
72
- txManager .waitForCompletion (1000 );
72
+ context .getBean ("goodService" , Lifecycle .class ).start ();
73
+ input .send (new GenericMessage <>("test" ));
74
+ txManager .waitForCompletion (10000 );
73
75
Message <?> message = output .receive (0 );
74
76
assertNotNull (message );
75
77
assertEquals (1 , txManager .getCommitCount ());
@@ -82,11 +84,12 @@ public void transactionWithCommit() throws InterruptedException {
82
84
public void transactionWithCommitAndAdvices () throws InterruptedException {
83
85
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
84
86
"transactionTests.xml" , this .getClass ());
85
- PollingConsumer advicedPoller = context .getBean ("advicedSa " , PollingConsumer .class );
87
+ PollingConsumer advisedPoller = context .getBean ("advisedSa " , PollingConsumer .class );
86
88
87
- List <Advice > adviceChain = TestUtils .getPropertyValue (advicedPoller , "adviceChain" , List .class );
89
+ List <Advice > adviceChain = TestUtils .getPropertyValue (advisedPoller , "adviceChain" , List .class );
88
90
assertEquals (4 , adviceChain .size ());
89
- Runnable poller = TestUtils .getPropertyValue (advicedPoller , "poller" , Runnable .class );
91
+ advisedPoller .start ();
92
+ Runnable poller = TestUtils .getPropertyValue (advisedPoller , "poller" , Runnable .class );
90
93
Callable <?> pollingTask = TestUtils .getPropertyValue (poller , "pollingTask" , Callable .class );
91
94
assertTrue ("Poller is not Advised" , pollingTask instanceof Advised );
92
95
Advisor [] advisors = ((Advised ) pollingTask ).getAdvisors ();
@@ -98,10 +101,14 @@ public void transactionWithCommitAndAdvices() throws InterruptedException {
98
101
PollableChannel output = (PollableChannel ) context .getBean ("output" );
99
102
assertEquals (0 , txManager .getCommitCount ());
100
103
assertEquals (0 , txManager .getRollbackCount ());
104
+
101
105
input .send (new GenericMessage <>("test" ));
106
+ input .send (new GenericMessage <>("test2" ));
102
107
txManager .waitForCompletion (10000 );
103
108
Message <?> message = output .receive (0 );
104
109
assertNotNull (message );
110
+ message = output .receive (0 );
111
+ assertNotNull (message );
105
112
assertEquals (0 , txManager .getRollbackCount ());
106
113
context .close ();
107
114
}
@@ -115,8 +122,11 @@ public void transactionWithRollback() throws InterruptedException {
115
122
PollableChannel output = (PollableChannel ) context .getBean ("output" );
116
123
assertEquals (0 , txManager .getCommitCount ());
117
124
assertEquals (0 , txManager .getRollbackCount ());
118
- input .send (new GenericMessage <String >("test" ));
119
- txManager .waitForCompletion (1000 );
125
+
126
+ context .getBean ("badService" , Lifecycle .class ).start ();
127
+
128
+ input .send (new GenericMessage <>("test" ));
129
+ txManager .waitForCompletion (10000 );
120
130
Message <?> message = output .receive (0 );
121
131
assertNull (message );
122
132
assertEquals (0 , txManager .getCommitCount ());
@@ -132,10 +142,10 @@ public void propagationRequired() throws InterruptedException {
132
142
PollableChannel input = (PollableChannel ) context .getBean ("input" );
133
143
PollableChannel output = (PollableChannel ) context .getBean ("output" );
134
144
assertEquals (0 , txManager .getCommitCount ());
135
- input .send (new GenericMessage <String >("test" ));
136
- Message <?> reply = output .receive (3000 );
145
+ input .send (new GenericMessage <>("test" ));
146
+ Message <?> reply = output .receive (10000 );
137
147
assertNotNull (reply );
138
- txManager .waitForCompletion (3000 );
148
+ txManager .waitForCompletion (10000 );
139
149
assertEquals (1 , txManager .getCommitCount ());
140
150
assertEquals (Propagation .REQUIRED .value (), txManager .getLastDefinition ().getPropagationBehavior ());
141
151
context .close ();
@@ -149,58 +159,58 @@ public void propagationRequiresNew() throws InterruptedException {
149
159
PollableChannel input = (PollableChannel ) context .getBean ("input" );
150
160
PollableChannel output = (PollableChannel ) context .getBean ("output" );
151
161
assertEquals (0 , txManager .getCommitCount ());
152
- input .send (new GenericMessage <String >("test" ));
153
- Message <?> reply = output .receive (3000 );
162
+ input .send (new GenericMessage <>("test" ));
163
+ Message <?> reply = output .receive (10000 );
154
164
assertNotNull (reply );
155
- txManager .waitForCompletion (3000 );
165
+ txManager .waitForCompletion (10000 );
156
166
assertEquals (1 , txManager .getCommitCount ());
157
167
assertEquals (Propagation .REQUIRES_NEW .value (), txManager .getLastDefinition ().getPropagationBehavior ());
158
168
context .close ();
159
169
}
160
170
161
171
@ Test
162
- public void propagationSupports () throws InterruptedException {
172
+ public void propagationSupports () {
163
173
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
164
174
"propagationSupportsTests.xml" , this .getClass ());
165
175
TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManager" );
166
176
PollableChannel input = (PollableChannel ) context .getBean ("input" );
167
177
PollableChannel output = (PollableChannel ) context .getBean ("output" );
168
178
assertEquals (0 , txManager .getCommitCount ());
169
- input .send (new GenericMessage <String >("test" ));
170
- Message <?> reply = output .receive (3000 );
179
+ input .send (new GenericMessage <>("test" ));
180
+ Message <?> reply = output .receive (10000 );
171
181
assertNotNull (reply );
172
182
assertEquals (0 , txManager .getCommitCount ());
173
183
assertNull (txManager .getLastDefinition ());
174
184
context .close ();
175
185
}
176
186
177
187
@ Test
178
- public void propagationNotSupported () throws InterruptedException {
188
+ public void propagationNotSupported () {
179
189
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
180
190
"propagationNotSupportedTests.xml" , this .getClass ());
181
191
TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManager" );
182
192
PollableChannel input = (PollableChannel ) context .getBean ("input" );
183
193
PollableChannel output = (PollableChannel ) context .getBean ("output" );
184
194
assertEquals (0 , txManager .getCommitCount ());
185
- input .send (new GenericMessage <String >("test" ));
186
- Message <?> reply = output .receive (3000 );
195
+ input .send (new GenericMessage <>("test" ));
196
+ Message <?> reply = output .receive (10000 );
187
197
assertNotNull (reply );
188
198
assertEquals (0 , txManager .getCommitCount ());
189
199
assertNull (txManager .getLastDefinition ());
190
200
context .close ();
191
201
}
192
202
193
203
@ Test
194
- public void propagationMandatory () throws Throwable {
204
+ public void propagationMandatory () {
195
205
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
196
206
"propagationMandatoryTests.xml" , this .getClass ());
197
207
TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManager" );
198
208
PollableChannel input = (PollableChannel ) context .getBean ("input" );
199
209
PollableChannel output = (PollableChannel ) context .getBean ("output" );
200
210
PollableChannel errorChannel = (PollableChannel ) context .getBean ("errorChannel" );
201
211
assertEquals (0 , txManager .getCommitCount ());
202
- input .send (new GenericMessage <String >("test" ));
203
- Message <?> errorMessage = errorChannel .receive (3000 );
212
+ input .send (new GenericMessage <>("test" ));
213
+ Message <?> errorMessage = errorChannel .receive (10000 );
204
214
assertNotNull (errorMessage );
205
215
Object payload = errorMessage .getPayload ();
206
216
assertEquals (MessagingException .class , payload .getClass ());
@@ -212,7 +222,7 @@ public void propagationMandatory() throws Throwable {
212
222
}
213
223
214
224
@ Test
215
- public void commitFailureAndHandlerFailureTest () throws Throwable {
225
+ public void commitFailureAndHandlerFailureTest () {
216
226
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
217
227
"transactionFailureTests.xml" , this .getClass ());
218
228
TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManagerBad" );
@@ -222,7 +232,7 @@ public void commitFailureAndHandlerFailureTest() throws Throwable {
222
232
PollableChannel errorChannel = (PollableChannel ) context .getBean ("errorChannel" );
223
233
assertEquals (0 , txManager .getCommitCount ());
224
234
inputTxFail .send (new GenericMessage <>("commitFailureTest" ));
225
- Message <?> errorMessage = errorChannel .receive (10000 );
235
+ Message <?> errorMessage = errorChannel .receive (20000 );
226
236
assertNotNull (errorMessage );
227
237
Object payload = errorMessage .getPayload ();
228
238
assertEquals (MessagingException .class , payload .getClass ());
@@ -232,7 +242,7 @@ public void commitFailureAndHandlerFailureTest() throws Throwable {
232
242
assertNotNull (output .receive (0 ));
233
243
assertEquals (0 , txManager .getCommitCount ());
234
244
235
- inputHandlerFail .send (new GenericMessage <>("handlerFalilureTest " ));
245
+ inputHandlerFail .send (new GenericMessage <>("handlerFailureTest " ));
236
246
errorMessage = errorChannel .receive (10000 );
237
247
assertNotNull (errorMessage );
238
248
payload = errorMessage .getPayload ();
0 commit comments