View Javadoc

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