[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/statetransfer ...

Brian Stansberry brian.stansberry at jboss.com
Tue Jan 2 22:54:32 EST 2007


  User: bstansberry
  Date: 07/01/02 22:54:32

  Modified:    tests/functional/org/jboss/cache/statetransfer  Tag:
                        Branch_JBossCache_1_4_0 VersionedTestBase.java
  Log:
  [JBCACHE-913] Beef up the evictionAfterStateTransfer test
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.6.2.4   +122 -8    JBossCache/tests/functional/org/jboss/cache/statetransfer/VersionedTestBase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: VersionedTestBase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/statetransfer/VersionedTestBase.java,v
  retrieving revision 1.6.2.3
  retrieving revision 1.6.2.4
  diff -u -b -r1.6.2.3 -r1.6.2.4
  --- VersionedTestBase.java	21 Dec 2006 23:11:57 -0000	1.6.2.3
  +++ VersionedTestBase.java	3 Jan 2007 03:54:32 -0000	1.6.2.4
  @@ -653,23 +653,137 @@
         config.configure(cache1, "META-INF/replSync-eviction-service.xml");      
         cache1.startService();
         
  -      for (int i = 0; i < 4; i++)
  -         cache1.put("/org/jboss/test/data/" + i, "key", "value");
  +      for (int i = 0; i < 25000; i++)
  +      {
  +         cache1.put("/base/" + i, "key", "base" + i);
  +         if (i < 5)
  +             cache1.put("/org/jboss/test/data/" + i, "key", "data" + i);
  +      }
         
  -      TreeCache cache2 = new TreeCache();
  +      final TreeCache cache2 = new TreeCache();
         config.configure(cache2, "META-INF/replSync-eviction-service.xml");
         cache2.startService();
         
         Set children = cache2.getChildrenNames("/org/jboss/test/data");
  -      assertEquals("All children transferred", 4, children.size());
  +      assertEquals("All data children transferred", 5, children.size());
  +      children = cache2.getChildrenNames("/base");
  +      assertEquals("All base children transferred", 25000, children.size());
  +      
  +      // Sleep 2.5 secs so the nodes we are about to create in data won't
  +      // exceed the 4 sec TTL when eviction thread runs
  +      TestingUtil.sleepThread(2500);
  +      
  +      class Putter extends Thread
  +      {
  +          TreeCache cache = null;
  +          boolean stopped = false;
  +          Exception ex = null;
  +          public void run()
  +          {
  +              int i = 25000;
  +              while (!stopped)
  +              {
  +                  try
  +                  {
  +                      cache.put("/base/" + i, "key", "base" + i);
  +                      cache.put("/org/jboss/test/data/" + i, "key", "data"+i);
  +                      i++;
  +                  }
  +                  catch (Exception e)
  +                  {
  +                    ex = e;  
  +                  }
  +              }
  +          }
  +      }
  +      Putter p1= new Putter();
  +      p1.cache = cache1;
  +      p1.start();
  +      Putter p2= new Putter();
  +      p2.cache = cache2;
  +      p2.start();
  +      
  +      Random rnd = new Random();
  +      TestingUtil.sleepThread(rnd.nextInt(200));
  +      
  +      int maxCountBase = 0;
  +      int maxCountData = 0;
  +      boolean sawBaseDecrease = false;
  +      boolean sawDataDecrease = false;
  +      long start = System.currentTimeMillis();
  +      while ((System.currentTimeMillis() - start) < 10000)
  +      {
  +         children = cache2.getChildrenNames("/org/jboss/test/data");
  +         if (children != null)
  +         {
  +            int dataCount = children.size();
  +            if (dataCount < maxCountData)
  +            {
  +                System.out.println("data " + dataCount + " < " + maxCountData + " elapsed = " + (System.currentTimeMillis() - start));
  +                sawDataDecrease = true;
  +            }
  +            else
  +            {
  +                maxCountData = dataCount;
  +            }
  +         }
  +         
  +         children = cache2.getChildrenNames("/base");
  +         if (children != null)
  +         {
  +            int baseCount = children.size();
  +            if (baseCount < maxCountBase)
  +            {
  +                System.out.println("base " + baseCount + " < " + maxCountBase+ " elapsed = " + (System.currentTimeMillis() - start));
  +                sawBaseDecrease = true;
  +            }
  +            else
  +            {
  +                maxCountBase = baseCount;
  +            }
  +         }
  +         
  +         if (sawDataDecrease && sawBaseDecrease)
  +         {
  +             break;
  +         }
  +         
  +         TestingUtil.sleepThread(50);
  +      }
  +      
  +      p1.stopped = true; 
  +      p2.stopped = true;
  +      p1.join(1000);
  +      p2.join(1000);
  +      
  +      assertTrue("Saw data decrease", sawDataDecrease);
  +      assertTrue("Saw base decrease", sawBaseDecrease);
  +      assertNull("No exceptions in p1", p1.ex);
  +      assertNull("No exceptions in p2", p2.ex);
  +      
  +      // Sleep 5.1 secs so we are sure the eviction thread ran
  +      TestingUtil.sleepThread(5100);
  +      
  +      children = cache2.getChildrenNames("/org/jboss/test/data");
  +      if (children != null)
  +      {
  +         System.out.println(children.size());
  +         assertTrue("Excess children evicted", children.size() <= 5);
  +      }
  +      children = cache2.getChildrenNames("/base");
  +      if (children != null)
  +      {
  +         System.out.println(children.size());
  +         assertTrue("Excess children evicted", children.size() <= 25000);
  +      }
         
  -      // Sleep 10.1 secs to let the eviction thread run at least twice,
  -      // which will evict all 4 nodes due to their ttl of 4 secs
  -      TestingUtil.sleepThread(10500);
  +      // Sleep more to let the eviction thread run again,
  +      // which will evict all data nodes due to their ttl of 4 secs
  +      TestingUtil.sleepThread(5100);
         
         children = cache2.getChildrenNames("/org/jboss/test/data");
         if (children != null)
  -         assertEquals("All children evicted", 0, children.size());
  +         assertEquals("All data children evicted", 0, children.size());
      }
      
      private Object createBen(ClassLoader loader) throws Exception
  
  
  



More information about the jboss-cvs-commits mailing list