1
2
3
4
5
6
7 package org.mule.test.integration;
8
9 import org.mule.tck.junit4.FunctionalTestCase;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.junit.Test;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertTrue;
18
19 public class PollingTestCase extends FunctionalTestCase
20 {
21
22 private static List<String> foo = new ArrayList<String>();
23 private static List<String> bar = new ArrayList<String>();
24
25 @Override
26 protected String getConfigResources()
27 {
28 return "org/mule/test/integration/polling-config.xml";
29 }
30
31 @Test
32 public void testPolling() throws Exception
33 {
34 Thread.sleep(5000);
35 synchronized (foo)
36 {
37 assertTrue(foo.size() > 0);
38 for (String s: foo)
39 {
40 assertEquals(s, "foo");
41 }
42 }
43 synchronized (bar)
44 {
45 assertTrue(bar.size() > 0);
46 for (String s: bar)
47 {
48 assertEquals(s, "bar");
49 }
50 }
51 }
52
53 public static class FooComponent
54 {
55 public boolean process(String s)
56 {
57 synchronized (foo)
58 {
59 if (foo.size() < 10)
60 {
61 foo.add(s);
62 return true;
63 }
64 }
65 return false;
66 }
67 }
68
69 public static class BarComponent
70 {
71 public boolean process(String s)
72 {
73 synchronized (bar)
74 {
75 if (bar.size() < 10)
76 {
77 bar.add(s);
78 return true;
79 }
80 }
81 return false;
82 }
83 }
84 }