11/*
2- * Copyright 2002-2017 the original author or authors.
2+ * Copyright 2002-2018 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3434import org .springframework .aop .Advisor ;
3535import org .springframework .aop .ProxyMethodInvocation ;
3636import org .springframework .aop .framework .Advised ;
37+ import org .springframework .context .Lifecycle ;
3738import org .springframework .context .support .ClassPathXmlApplicationContext ;
3839import org .springframework .integration .endpoint .PollingConsumer ;
3940import org .springframework .integration .test .util .TestUtils ;
@@ -68,8 +69,9 @@ public void transactionWithCommit() throws InterruptedException {
6869 PollableChannel output = (PollableChannel ) context .getBean ("output" );
6970 assertEquals (0 , txManager .getCommitCount ());
7071 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 );
7375 Message <?> message = output .receive (0 );
7476 assertNotNull (message );
7577 assertEquals (1 , txManager .getCommitCount ());
@@ -82,11 +84,12 @@ public void transactionWithCommit() throws InterruptedException {
8284 public void transactionWithCommitAndAdvices () throws InterruptedException {
8385 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
8486 "transactionTests.xml" , this .getClass ());
85- PollingConsumer advicedPoller = context .getBean ("advicedSa " , PollingConsumer .class );
87+ PollingConsumer advisedPoller = context .getBean ("advisedSa " , PollingConsumer .class );
8688
87- List <Advice > adviceChain = TestUtils .getPropertyValue (advicedPoller , "adviceChain" , List .class );
89+ List <Advice > adviceChain = TestUtils .getPropertyValue (advisedPoller , "adviceChain" , List .class );
8890 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 );
9093 Callable <?> pollingTask = TestUtils .getPropertyValue (poller , "pollingTask" , Callable .class );
9194 assertTrue ("Poller is not Advised" , pollingTask instanceof Advised );
9295 Advisor [] advisors = ((Advised ) pollingTask ).getAdvisors ();
@@ -98,10 +101,14 @@ public void transactionWithCommitAndAdvices() throws InterruptedException {
98101 PollableChannel output = (PollableChannel ) context .getBean ("output" );
99102 assertEquals (0 , txManager .getCommitCount ());
100103 assertEquals (0 , txManager .getRollbackCount ());
104+
101105 input .send (new GenericMessage <>("test" ));
106+ input .send (new GenericMessage <>("test2" ));
102107 txManager .waitForCompletion (10000 );
103108 Message <?> message = output .receive (0 );
104109 assertNotNull (message );
110+ message = output .receive (0 );
111+ assertNotNull (message );
105112 assertEquals (0 , txManager .getRollbackCount ());
106113 context .close ();
107114 }
@@ -115,8 +122,11 @@ public void transactionWithRollback() throws InterruptedException {
115122 PollableChannel output = (PollableChannel ) context .getBean ("output" );
116123 assertEquals (0 , txManager .getCommitCount ());
117124 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 );
120130 Message <?> message = output .receive (0 );
121131 assertNull (message );
122132 assertEquals (0 , txManager .getCommitCount ());
@@ -132,10 +142,10 @@ public void propagationRequired() throws InterruptedException {
132142 PollableChannel input = (PollableChannel ) context .getBean ("input" );
133143 PollableChannel output = (PollableChannel ) context .getBean ("output" );
134144 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 );
137147 assertNotNull (reply );
138- txManager .waitForCompletion (3000 );
148+ txManager .waitForCompletion (10000 );
139149 assertEquals (1 , txManager .getCommitCount ());
140150 assertEquals (Propagation .REQUIRED .value (), txManager .getLastDefinition ().getPropagationBehavior ());
141151 context .close ();
@@ -149,58 +159,58 @@ public void propagationRequiresNew() throws InterruptedException {
149159 PollableChannel input = (PollableChannel ) context .getBean ("input" );
150160 PollableChannel output = (PollableChannel ) context .getBean ("output" );
151161 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 );
154164 assertNotNull (reply );
155- txManager .waitForCompletion (3000 );
165+ txManager .waitForCompletion (10000 );
156166 assertEquals (1 , txManager .getCommitCount ());
157167 assertEquals (Propagation .REQUIRES_NEW .value (), txManager .getLastDefinition ().getPropagationBehavior ());
158168 context .close ();
159169 }
160170
161171 @ Test
162- public void propagationSupports () throws InterruptedException {
172+ public void propagationSupports () {
163173 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
164174 "propagationSupportsTests.xml" , this .getClass ());
165175 TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManager" );
166176 PollableChannel input = (PollableChannel ) context .getBean ("input" );
167177 PollableChannel output = (PollableChannel ) context .getBean ("output" );
168178 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 );
171181 assertNotNull (reply );
172182 assertEquals (0 , txManager .getCommitCount ());
173183 assertNull (txManager .getLastDefinition ());
174184 context .close ();
175185 }
176186
177187 @ Test
178- public void propagationNotSupported () throws InterruptedException {
188+ public void propagationNotSupported () {
179189 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
180190 "propagationNotSupportedTests.xml" , this .getClass ());
181191 TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManager" );
182192 PollableChannel input = (PollableChannel ) context .getBean ("input" );
183193 PollableChannel output = (PollableChannel ) context .getBean ("output" );
184194 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 );
187197 assertNotNull (reply );
188198 assertEquals (0 , txManager .getCommitCount ());
189199 assertNull (txManager .getLastDefinition ());
190200 context .close ();
191201 }
192202
193203 @ Test
194- public void propagationMandatory () throws Throwable {
204+ public void propagationMandatory () {
195205 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
196206 "propagationMandatoryTests.xml" , this .getClass ());
197207 TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManager" );
198208 PollableChannel input = (PollableChannel ) context .getBean ("input" );
199209 PollableChannel output = (PollableChannel ) context .getBean ("output" );
200210 PollableChannel errorChannel = (PollableChannel ) context .getBean ("errorChannel" );
201211 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 );
204214 assertNotNull (errorMessage );
205215 Object payload = errorMessage .getPayload ();
206216 assertEquals (MessagingException .class , payload .getClass ());
@@ -212,7 +222,7 @@ public void propagationMandatory() throws Throwable {
212222 }
213223
214224 @ Test
215- public void commitFailureAndHandlerFailureTest () throws Throwable {
225+ public void commitFailureAndHandlerFailureTest () {
216226 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
217227 "transactionFailureTests.xml" , this .getClass ());
218228 TestTransactionManager txManager = (TestTransactionManager ) context .getBean ("txManagerBad" );
@@ -222,7 +232,7 @@ public void commitFailureAndHandlerFailureTest() throws Throwable {
222232 PollableChannel errorChannel = (PollableChannel ) context .getBean ("errorChannel" );
223233 assertEquals (0 , txManager .getCommitCount ());
224234 inputTxFail .send (new GenericMessage <>("commitFailureTest" ));
225- Message <?> errorMessage = errorChannel .receive (10000 );
235+ Message <?> errorMessage = errorChannel .receive (20000 );
226236 assertNotNull (errorMessage );
227237 Object payload = errorMessage .getPayload ();
228238 assertEquals (MessagingException .class , payload .getClass ());
@@ -232,7 +242,7 @@ public void commitFailureAndHandlerFailureTest() throws Throwable {
232242 assertNotNull (output .receive (0 ));
233243 assertEquals (0 , txManager .getCommitCount ());
234244
235- inputHandlerFail .send (new GenericMessage <>("handlerFalilureTest " ));
245+ inputHandlerFail .send (new GenericMessage <>("handlerFailureTest " ));
236246 errorMessage = errorChannel .receive (10000 );
237247 assertNotNull (errorMessage );
238248 payload = errorMessage .getPayload ();
0 commit comments