sebb        2003/12/20 08:51:15

  Modified:    src/components/org/apache/jmeter/visualizers
                        StatVisualizerModel.java
               src/core/org/apache/jmeter/samplers SampleResult.java
               src/protocol/http/org/apache/jmeter/protocol/http/sampler
                        HTTPSampleResult.java HTTPSampler.java
  Log:
  SampleResult fixes to use start and End times
  
  Revision  Changes    Path
  1.14      +20 -7     
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/StatVisualizerModel.java
  
  Index: StatVisualizerModel.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/StatVisualizerModel.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StatVisualizerModel.java  19 Dec 2003 17:57:12 -0000      1.13
  +++ StatVisualizerModel.java  20 Dec 2003 16:51:15 -0000      1.14
  @@ -235,13 +235,14 @@
               super(name);
           }
   
  -        private SampleResult sample(String label, long timestamp,
  -                long time, boolean ok)
  +        private SampleResult sample(String label, long start,
  +                long elapsed, boolean ok)
           {
  -            SampleResult res = new SampleResult(timestamp,time);
  +            SampleResult res = SampleResult.createTestSample(start, start+elapsed);
   
               res.setSampleLabel(label);
               res.setSuccessful(ok);
  +            assertEquals(elapsed,res.getTime());
               return res;
           }
   
  @@ -250,9 +251,18 @@
               StatVisualizerModel m = new StatVisualizerModel();
               long t0 = System.currentTimeMillis();
   
  -            m.addNewSample(sample("1", t0 + 100, 100, true));
  -            m.addNewSample(sample("2", t0 + 350, 200, true));
  -            m.addNewSample(sample("1", t0 + 600, 300, true));
  +
  +                     //m.addNewSample(sample("1", t0 + 100, 100, true));
  +                     //m.addNewSample(sample("2", t0 + 350, 200, true));
  +                     //m.addNewSample(sample("1", t0 + 600, 300, true));
  +
  +            /*
  +             * Create 3 samples lasting a total of 600 ms
  +             */
  +            m.addNewSample(sample("1", t0 + 000, 100, true));
  +            m.addNewSample(sample("2", t0 + 150, 200, true));
  +            m.addNewSample(sample("1", t0 + 300, 300, true));
  +            
               assertEquals(2, m.getRunningSampleCount());
               assertEquals(2, m.labelMap.size());
   
  @@ -264,6 +274,7 @@
                   assertEquals(100, s.getMin());
                   assertEquals(300, s.getMax());
                   assertEquals(200, s.getAverage());
  +                             assertEquals(600, s.getElapsed());
               }
   
               {
  @@ -274,6 +285,7 @@
                   assertEquals(200, s.getMin());
                   assertEquals(200, s.getMax());
                   assertEquals(200, s.getAverage());
  +                             assertEquals(200, s.getElapsed());
               }
   
               {
  @@ -283,6 +295,7 @@
                   assertEquals(100, s.getMin());
                   assertEquals(300, s.getMax());
                   assertEquals(200, s.getAverage());
  +                assertEquals(600, s.getElapsed());
                   assertEquals(5.0, s.getRate(), 1e-6);
               }
           }
  
  
  
  1.23      +113 -26   
jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java
  
  Index: SampleResult.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- SampleResult.java 20 Dec 2003 01:00:54 -0000      1.22
  +++ SampleResult.java 20 Dec 2003 16:51:15 -0000      1.23
  @@ -129,7 +129,7 @@
   
       transient private static Logger log = LoggingManager.getLoggerForClass();
   
  -    private final boolean startTimeStamp = 
  +    private static final boolean startTimeStamp = 
           JMeterUtils.getPropDefault("sampleresult.timestamp.start",false);
   
       public SampleResult()
  @@ -138,31 +138,87 @@
       }
       
       /**
  -     * Allow users to create a sample with a specific elapsed time
  -     * for cloning and test purposes, but don't allow the time to be
  -     * changed later
  +     * Create a sample with a specific elapsed time
  +     * but don't allow the times to be changed later
  +     * 
  +     * (only used by HTTPSampleResult)
        * 
        * @param elapsed time
  +     * @param atend create the sample finishing now, else starting now
        */
  -     public SampleResult(long elapsed)
  +     protected SampleResult(long elapsed, boolean atend)
        {
  -             time = elapsed;
  +             long now = System.currentTimeMillis();
  +             if (atend){
  +                     setTimes(now - elapsed, now);
  +             } else {
  +                     setTimes(now, now + elapsed);
  +             }
        }
       
  +     /**
  +      * Create a sample with specific start and end times
  +      * for test purposes, but don't allow the times to be changed later
  +      * 
  +      * (used by StatVisualizerModel.Test)
  +      * 
  +      * @param start start time
  +      * @param end end time 
  +      */
  +     public static SampleResult createTestSample(long start, long end)
  +     {
  +             SampleResult res = new SampleResult();
  +             res.setStartTime(start);
  +             res.setEndTime(end);
  +             return res;
  +     }
  +
  +     /**
  +      * Create a sample with a specific elapsed time
  +      * for test purposes, but don't allow the times to be changed later
  +      * 
  +      * @param elapsed - desired elapsed time
  +      */
  +     public static SampleResult createTestSample(long elapsed)
  +     {
  +             long now = System.currentTimeMillis();
  +             return createTestSample(now,now+elapsed);
  +     }
  +
       /**
        * Allow users to create a sample with specific timestamp and elapsed times
  -     * for cloning and test purposes, but don't allow the times to be
  -     * changed later
  +     * for cloning purposes, but don't allow the times to be changed later
        * 
  -     * @param stamp
  +     * Currently used by SaveService only
  +     * 
  +     * @param stamp - this may be a start time or an end time
        * @param elapsed
        */
        public SampleResult(long stamp, long elapsed)
        {
  -             timeStamp = stamp;
  -             time = elapsed;
  +             // Maintain the timestamp relationships
  +             if (startTimeStamp) {
  +                     setTimes(stamp, stamp + elapsed);
  +             } else {
  +                     setTimes(stamp - elapsed, stamp);
  +             }
        }
   
  +    /**
  +     * Method to set the elapsed time for a sample.
  +     * Retained for backward compatibility with 3rd party add-ons
  +     * It is assumed that the method is called at the end of a sample
  +     * 
  +     * Must not be used in conjunction with sampleStart()/End()
  +     * 
  +     * @deprecated use sampleStart() and sampleEnd() instead
  +     * @param elapsed time in milliseconds
  +     */
  +    public void setTime(long elapsed){
  +             long now = System.currentTimeMillis();
  +     setTimes(now,elapsed);
  +    }
  +
       public void setMarked(String filename)
       {
           if (files == null)
  @@ -482,6 +538,42 @@
                return startTime;
        }
   
  +    /*
  +     * Helper methods
  +     * N.B. setStartTime must be called before setEndTime
  +     * 
  +     * setStartTime is used by HTTPSampleResult to clone
  +     * the parent sampler and allow the original start time to be kept
  +     */
  +    protected final void setStartTime(long start)
  +    {
  +             startTime = start;
  +             if (startTimeStamp){
  +                     timeStamp = startTime;
  +             }
  +    }
  +
  +     private void setEndTime(long end)
  +     {
  +             endTime = end;
  +             if (!startTimeStamp){
  +                     timeStamp = endTime;
  +             }
  +             if (startTime == 0){
  +                     log.error("setEndTime must be called after setStartTime"
  +                              , new Throwable("Invalid call sequence"));
  +                     //TODO should this throw an error?
  +             } else {
  +                     time = endTime - startTime - idleTime;
  +             }
  +     }
  +     
  +     private void setTimes(long start, long end)
  +     {
  +             setStartTime(start);
  +             setEndTime(end);
  +     }
  +
       /**
        * Record the start time of a sample
        *
  @@ -489,12 +581,10 @@
       public void sampleStart()
       {
        if (startTime == 0){
  -                     startTime = System.currentTimeMillis();
  -                     if (startTimeStamp){
  -                             timeStamp = startTime;
  -                     }
  +                     setStartTime(System.currentTimeMillis());
        } else {
  -                     log.error("sampleStart called twice", new Throwable("Invalid 
call sequence"));
  +                     log.error("sampleStart called twice"
  +                              , new Throwable("Invalid call sequence"));
        }
       }
       
  @@ -505,14 +595,10 @@
       public void sampleEnd()
       {
        if (endTime == 0){
  -                     endTime = System.currentTimeMillis();
  -                     time = endTime - startTime - idleTime;
  -                     if (!startTimeStamp){
  -                             timeStamp = endTime;
  -                     }
  -
  +                     setEndTime(System.currentTimeMillis());
        } else {
  -             log.error("sampleEnd called twice", new Throwable("Invalid call 
sequence"));
  +             log.error("sampleEnd called twice"
  +                      , new Throwable("Invalid call sequence"));
        }
       }
   
  @@ -558,6 +644,7 @@
                res.sampleStart();
                Thread.sleep(100);
                        res.sampleEnd();
  +                     assertTrue(res.getTime() >= 100);
        }
   
                public void testPause() throws Exception
  @@ -574,8 +661,8 @@
                        res.sampleResume();
                        Thread.sleep(100);
                        res.sampleEnd();
  -                     assertTrue(res.time  >= 200);
  -                     assertFalse(res.time >= 250); // we hope!
  +                     assertTrue(res.getTime()  >= 200);
  +                     assertFalse(res.getTime() >= 290); // we hope!
                }
   
                private static Formatter fmt=new RawFormatter();
  
  
  
  1.7       +6 -5      
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
  
  Index: HTTPSampleResult.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HTTPSampleResult.java     19 Dec 2003 23:59:53 -0000      1.6
  +++ HTTPSampleResult.java     20 Dec 2003 16:51:15 -0000      1.7
  @@ -73,18 +73,20 @@
       
        public HTTPSampleResult(long elapsed)
        {
  -             super(elapsed);
  +             super(elapsed,true);
        }
       
       /**
        * Construct a 'parent' result for an already-existing result, essentially
  -     * cloning it:
  +     * cloning it
  +     * 
  +     * The start-time is set from the existing sample.
        *  
        * @param res existing sample result
        */
       public HTTPSampleResult(HTTPSampleResult res)
       {
  -        super(res.getTime());
  +        setStartTime(res.getStartTime());
   
           setSampleLabel(res.getSampleLabel());
           setHTTPMethod(res.getHTTPMethod());
  @@ -97,7 +99,6 @@
           setDataType(res.getDataType());
           setResponseHeaders(res.getResponseHeaders());
           setCookies(res.getCookies());
  -
           addSubResult(res);
       }
   
  
  
  
  1.77      +1 -2      
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
  
  Index: HTTPSampler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- HTTPSampler.java  20 Dec 2003 01:47:23 -0000      1.76
  +++ HTTPSampler.java  20 Dec 2003 16:51:15 -0000      1.77
  @@ -1218,7 +1218,6 @@
           int frameDepth)
       {
           HTTPSampleResult totalRes= new HTTPSampleResult(res);
  -        totalRes.sampleStart();
           HTTPSampleResult lastRes= res;
   
           int redirect;
  
  
  

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

Reply via email to