View Javadoc

1   /*
2    * $Id: PollingTestCase.java 20629 2010-12-10 22:21:51Z dzapata $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.test.integration;
11  
12  import org.mule.tck.FunctionalTestCase;
13  
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  public class PollingTestCase extends FunctionalTestCase
18  {
19      private static List<String> foo = new ArrayList<String>();
20      private static List<String> bar = new ArrayList<String>();
21      
22      @Override
23      protected String getConfigResources()
24      {
25          return "org/mule/test/integration/polling-config.xml";
26      }
27  
28      public void testPolling() throws Exception
29      {
30          Thread.sleep(5000);
31          synchronized (foo)
32          {
33              assertTrue(foo.size() > 0);
34              for (String s: foo)
35              {
36                  assertEquals(s, "foo");
37              }
38          }
39          synchronized (bar)
40          {
41              assertTrue(bar.size() > 0);
42              for (String s: bar)
43              {
44                  assertEquals(s, "bar");
45              }
46          }
47      }
48  
49      public static class FooComponent
50      {
51          public boolean process(String s)
52          {
53              synchronized (foo)
54              {
55                  if (foo.size() < 10)
56                  {
57                      foo.add(s);
58                      return true;
59                  }
60              }
61              return false;
62          }
63      }
64  
65      public static class BarComponent
66      {
67          public boolean process(String s)
68          {
69              synchronized (bar)
70              {
71                  if (bar.size() < 10)
72                  {
73                      bar.add(s);
74                      return true;
75                  }
76              }
77              return false;
78          }
79      }
80  }