jsalvata    2003/12/02 09:30:47

  Modified:    src/protocol/http/org/apache/jmeter/protocol/http/proxy
                        ProxyControl.java
               src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui
                        ProxyControlGui.java
  Log:
  Implemented grouping in controllers (put each group in a separate controller).
  
  Fixed update of target combo upon changes in the tree.
  
  Avoided changing target property during work.
  
  Avoided adding divider at the beginning of a controller after recording, then 
switching to a new empty target, then recording some more.
  
  Revision  Changes    Path
  1.40      +61 -24    
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
  
  Index: ProxyControl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- ProxyControl.java 2 Dec 2003 00:55:33 -0000       1.39
  +++ ProxyControl.java 2 Dec 2003 17:30:47 -0000       1.40
  @@ -122,8 +122,7 @@
   
       public static final int GROUPING_NO_GROUPS = 0;
       public static final int GROUPING_ADD_SEPARATORS = 1;
  -    // TODO: implement thin one:
  -    //public static final int GROUPING_IN_CONTROLLERS = 2;
  +    public static final int GROUPING_IN_CONTROLLERS = 2;
       public static final int GROUPING_STORE_FIRST_ONLY = 3;
   
        private long lastTime = 0;//When was the last sample seen?
  @@ -365,47 +364,66 @@
        private void addDivider(JMeterTreeModel model,JMeterTreeNode node)
            throws IllegalUserActionException
        {
  -             if (groupingMode == GROUPING_ADD_SEPARATORS){
  -                     GenericController sc = new GenericController();
  -                     sc.setProperty(TestElement.GUI_CLASS,
  -                         "org.apache.jmeter.control.gui.LogicControllerGui");
  -                     sc.setName("-------------------");
  -                     model.addComponent(sc,node);
  -         }
  +        GenericController sc = new GenericController();
  +        sc.setProperty(TestElement.GUI_CLASS,
  +            "org.apache.jmeter.control.gui.LogicControllerGui");
  +        sc.setName("-------------------");
  +        model.addComponent(sc,node);
        }
       
  +    /**
  +     * Helper method to add a Simple Controller to contain the samplers.
  +     * 
  +     * @param model Test component tree model
  +     * @param node  Node in the tree where we will add the Controller
  +     * @param name  A name for the Controller
  +     */
  +    private void addSimpleController(
  +            JMeterTreeModel model,
  +            JMeterTreeNode node,
  +            String name)
  +        throws IllegalUserActionException
  +    {
  +        GenericController sc = new GenericController();
  +        sc.setProperty(TestElement.GUI_CLASS,
  +            "org.apache.jmeter.control.gui.LogicControllerGui");
  +        sc.setName(name);
  +        model.addComponent(sc,node);
  +    }
  +    
       private void placeConfigElement(
           HTTPSampler sampler,
           TestElement[] subConfigs)
       {
  +        JMeterTreeNode myTarget= target;
           TestElement urlConfig = null;
           JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
  -        if (target == null)
  +        if (myTarget == null)
           {
               List nodes = treeModel.getNodesOfType(RecordingController.class);
               Iterator iter= nodes.iterator();
               while (iter.hasNext()) {
                   JMeterTreeNode node= (JMeterTreeNode) iter.next();
                   if (node.isEnabled()) {
  -                    target= node;
  +                    myTarget= node;
                       break;
                   }
               }
           }
  -        if (target == null)
  +        if (myTarget == null)
           {
               List nodes = treeModel.getNodesOfType(ThreadGroup.class);
               Iterator iter = nodes.iterator();
               while (iter.hasNext()) {
                   JMeterTreeNode node= (JMeterTreeNode) iter.next();
                   if (node.isEnabled()) {
  -                    target= node;
  +                    myTarget= node;
                       break;
                   }
               }
           }
   
  -        Enumeration enum = target.children();
  +        Enumeration enum = myTarget.children();
           String guiClassName = null;
           while (enum.hasMoreElements())
           {
  @@ -434,18 +452,22 @@
               try
               {
                   boolean firstInBatch=false;
  -                if (lastTime == 0){
  -                    lastTime = System.currentTimeMillis();
  -                    firstInBatch=true;
  -                }
                   long now = System.currentTimeMillis();
                   if (now - lastTime > sampleGap){
  -                    addDivider(treeModel,target);
  -                    firstInBatch=true;//Remember to save the new node
  +                    if (!myTarget.isLeaf() 
  +                            && groupingMode == GROUPING_ADD_SEPARATORS)
  +                    {
  +                        addDivider(treeModel, myTarget);
  +                    }
  +                    if (groupingMode == GROUPING_IN_CONTROLLERS)
  +                    {
  +                        addSimpleController(treeModel, myTarget, sampler.getName());
  +                    }
  +                    firstInBatch=true;//Remember this was first in its batch
                   }
  -                lastTime = System.currentTimeMillis();
  +                lastTime = now;
   
  -                if (groupingMode==GROUPING_STORE_FIRST_ONLY)
  +                if (groupingMode == GROUPING_STORE_FIRST_ONLY)
                   {
                       if (!firstInBatch) return; // Huh! don't store this one!
                       
  @@ -455,8 +477,23 @@
                       sampler.setImageParser(true);
                   }
                   
  +                if (groupingMode == GROUPING_IN_CONTROLLERS)
  +                {
  +                    // Find the last controller in the target to store the
  +                    // sampler there:
  +                    for (int i= myTarget.getChildCount()-1; i>=0; i--)
  +                    {
  +                        JMeterTreeNode c= (JMeterTreeNode)myTarget.getChildAt(i);
  +                        if (c.createTestElement() instanceof GenericController)
  +                        {
  +                            myTarget= c;
  +                            break;
  +                        }
  +                    }
  +                }
  +
                   JMeterTreeNode newNode =
  -                    treeModel.addComponent(sampler, target);
  +                    treeModel.addComponent(sampler, myTarget);
                               
                   if(firstInBatch){
                       addAssertion(treeModel,newNode);
  
  
  
  1.32      +8 -7      
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java
  
  Index: ProxyControlGui.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- ProxyControlGui.java      2 Dec 2003 00:55:33 -0000       1.31
  +++ ProxyControlGui.java      2 Dec 2003 17:30:47 -0000       1.32
  @@ -173,6 +173,7 @@
       public ProxyControlGui()
       {
           super();
  +        log.debug("Creating ProxyControlGui");
           init();
       }
   
  @@ -444,8 +445,8 @@
                       portField.setText("");
                   }
               }
  +            enableRestart();
           }
  -        enableRestart();
       }
   
       private void init()
  @@ -582,11 +583,11 @@
       private JPanel createGroupingPanel()
       {
           DefaultComboBoxModel m= new DefaultComboBoxModel();
  +        // Note: position of these elements in the menu *must* match the
  +        // corresponding ProxyControl.GROUPING_* values.
           m.addElement(JMeterUtils.getResString("grouping_no_groups"));
           m.addElement(JMeterUtils.getResString("grouping_add_separators"));
  -        // TODO: enable when implemented:
  -        //m.addElement(JMeterUtils.getResString("grouping_in_controllers"));
  -        m.addElement("[not implemented]");
  +        m.addElement(JMeterUtils.getResString("grouping_in_controllers"));
           m.addElement(JMeterUtils.getResString("grouping_store_first_only"));
           groupingMode = new JComboBox(m);
           groupingMode.setName(ProxyControl.GROUPING_MODE);
  @@ -692,14 +693,14 @@
           for (int i = 0; i < targetNodesModel.getSize(); i++)
           {
               choice = (TreeNodeWrapper) targetNodesModel.getElementAt(i);
  +            log.debug("Selecting item "+choice+" for model "+model+" in "+this);
               if (choice.getTreeNode() == model.getTarget()) // .equals caused NPE
               {
  -                log.debug("Selecting item "+choice);
                   break;
               }
           }
           // Reinstate action notifications:
  -        targetNodes.removeActionListener(this);
  +        targetNodes.addActionListener(this);
           // Set the current value:
           targetNodesModel.setSelectedItem(choice);        
           
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to