[jboss-cvs] JBossCache/tests/perf/org/jboss/cache/manualtests ...

Manik Surtani msurtani at jboss.com
Fri Feb 2 11:49:50 EST 2007


  User: msurtani
  Date: 07/02/02 11:49:50

  Added:       tests/perf/org/jboss/cache/manualtests 
                        LoopFlatteningTest.java
  Log:
  Fleshed out meths
  
  Revision  Changes    Path
  1.1      date: 2007/02/02 16:49:50;  author: msurtani;  state: Exp;JBossCache/tests/perf/org/jboss/cache/manualtests/LoopFlatteningTest.java
  
  Index: LoopFlatteningTest.java
  ===================================================================
  package org.jboss.cache.manualtests;
  
  import org.jboss.cache.Cache;
  import org.jboss.cache.DefaultCacheFactory;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.Node;
  
  public class LoopFlatteningTest
  {
     // number of nodes to create
     private final static int N = 10000;
     // tree depths to test with
     private final static int[] D = {3, 5, 10, 50};
  
     private final int depth;
     private Cache cache;
  
  
     public static void main(String[] args)
     {
        System.out.println("Starting test.");
        for (int depth : D)
        {
           System.out.println("Testing with depth " + depth);
           LoopFlatteningTest test = new LoopFlatteningTest(depth);
           test.doTest();
        }
     }
  
     private LoopFlatteningTest(int depth)
     {
        this.depth = depth;
     }
  
     private void doTest()
     {
        cache = DefaultCacheFactory.getInstance().createCache();
  
        long startTime = System.currentTimeMillis();
        createNodes();
        System.out.println("Node Creation\t" + (System.currentTimeMillis() - startTime));
  
        startTime = System.currentTimeMillis();
        seekNodes();
        System.out.println("Node Retrieval\t" + (System.currentTimeMillis() - startTime));
  
        startTime = System.currentTimeMillis();
        deleteNodes();
        System.out.println("Node Retrieval\t" + (System.currentTimeMillis() - startTime));
  
        cache.stop();
     }
  
  
     /**
      * Creates a node structure such as:
      * /depth1/depth2/depth3/depth4
      */
     private void createNodes()
     {
        Node previousNode = cache.getRoot();
        for (int i = 0; i < N; i++)
        {
           for (int j = 0; j < depth; j++)
           {
              String nodeName = "node" + i;
              previousNode = previousNode.addChild(Fqn.fromString("/node_" + i));
           }
           previousNode = cache.getRoot();
        }
     }
  
     private void seekNodes()
     {
        Fqn previousFqn = Fqn.ROOT;
        for (int i = 0; i < N; i++)
        {
           for (int j = 0; j < depth; j++)
           {
              String nodeName = "node" + i;
              previousFqn = new Fqn(previousFqn, nodeName);
              cache.get(previousFqn, "blah");
           }
           previousFqn = Fqn.ROOT;
        }
     }
  
     private void deleteNodes()
     {
        Fqn previousFqn = Fqn.ROOT;
        for (int i = 0; i < N; i++)
        {
           for (int j = 0; j < depth; j++)
           {
              String nodeName = "node" + i;
              previousFqn = new Fqn(previousFqn, nodeName);
              cache.removeNode(previousFqn);
           }
           previousFqn = Fqn.ROOT;
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list