File tree 1 file changed +5
-26
lines changed
spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka
1 file changed +5
-26
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package sample .kafka ;
17
17
18
- import java .util .concurrent .CountDownLatch ;
19
- import java .util .concurrent .TimeUnit ;
20
-
21
18
import org .junit .Rule ;
22
19
import org .junit .Test ;
23
20
import org .junit .runner .RunWith ;
24
21
25
22
import org .springframework .boot .test .context .SpringBootTest ;
26
- import org .springframework .boot .test .context .TestConfiguration ;
27
23
import org .springframework .boot .test .rule .OutputCapture ;
28
- import org .springframework .context .annotation .Bean ;
29
24
import org .springframework .kafka .test .context .EmbeddedKafka ;
30
25
import org .springframework .test .context .junit4 .SpringRunner ;
31
26
43
38
@ EmbeddedKafka
44
39
public class SampleKafkaApplicationTests {
45
40
46
- private static final CountDownLatch latch = new CountDownLatch (1 );
47
-
48
41
@ Rule
49
42
public OutputCapture outputCapture = new OutputCapture ();
50
43
51
44
@ Test
52
45
public void testVanillaExchange () throws Exception {
53
- assertThat (latch .await (10 , TimeUnit .SECONDS )).isTrue ();
46
+ long end = System .currentTimeMillis () + 10000 ;
47
+ while (!this .outputCapture .toString ().contains ("A simple test message" )
48
+ && System .currentTimeMillis () < end ) {
49
+ Thread .sleep (250 );
50
+ }
54
51
assertThat (this .outputCapture .toString ().contains ("A simple test message" ))
55
52
.isTrue ();
56
53
}
57
54
58
- @ TestConfiguration
59
- public static class Config {
60
-
61
- @ Bean
62
- public Consumer consumer () {
63
- return new Consumer () {
64
-
65
- @ Override
66
- public void processMessage (SampleMessage message ) {
67
- super .processMessage (message );
68
- latch .countDown ();
69
- }
70
-
71
- };
72
- }
73
-
74
- }
75
-
76
55
}
You can’t perform that action at this time.
0 commit comments