ExampleLoadTest.py :  » Test » pyUnitPerf » pyunitperf » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Test » pyUnitPerf 
pyUnitPerf » pyunitperf » ExampleLoadTest.py
"""
 * The <code>ExampleLoadTest</code> demonstrates how to 
 * decorate a <code>Test</code> as a <code>LoadTest</code>.
 *
 * @author <b>Mike Clark</b>
 * @author Clarkware Consulting, Inc.
 *
 * @see com.clarkware.junitperf.LoadTest
 * @see com.clarkware.junitperf.TimedTest
 **************************************
 * Ported to Python by Grig Gheorghiu *
 **************************************
"""

from unittest import TestSuite,TextTestRunner
from ExampleTestCase import ExampleTestCase
from LoadTest import LoadTest
from TimedTest import TimedTest

class ExampleLoadTest:

    def __init__(self):
        self.toleranceInSec = 0.05

    def suite(self):
        s = TestSuite()
        s.addTest(self.make1SecondResponseSingleUserLoadTest())
        s.addTest(self.make1SecondResponseMultipleUserLoadTest())
        s.addTest(self.make1SecondResponse1UserLoadIterationTest())
        return s

    def make1SecondResponseSingleUserLoadTest(self):
        """
         * Decorates a one second response time test as a one
         * user load test with a maximum elapsed time of 1 second
         * and a 0 second delay between users.
         * 
         * @return Test.
        """ 
        users = 1
        maxElapsedTimeInSec = 1 + self.toleranceInSec

        testCase = ExampleTestCase("testOneSecondResponse")

        loadTest = LoadTest(testCase, users)
        timedTest = TimedTest(loadTest, maxElapsedTimeInSec)
        return timedTest
    
    def make1SecondResponseMultipleUserLoadTest(self):
        """
         * Decorates a one second response time test as a multiple-user
         * load test with a maximum elapsed time of 1.5 
         * seconds and a 0 second delay between users.
         * 
         * @return Test.
        """ 
        users = 10
        maxElapsedTimeInSec = 1.5 + self.toleranceInSec

        testCase = ExampleTestCase("testOneSecondResponse")

        loadTest = LoadTest(testCase, users)
        timedTest = TimedTest(loadTest, maxElapsedTimeInSec)

        return timedTest

    def make1SecondResponse1UserLoadIterationTest(self):
        """
         * Decorates a one second response time test as a one
         * user load test with 10 iterations per user, a maximum 
         * elapsed time of 12 seconds, and a 0 second delay
         * between users.
         * 
         * @see testOneSecondResponseOneUserLoadRepeatedTest
         * @return Test.
        """ 

        users = 1
        iterations = 10
        maxElapsedTimeInSec = 10 + self.toleranceInSec

        testCase = ExampleTestCase("testOneSecondResponse");

        loadTest = LoadTest(testCase, users, iterations)
        timedTest = TimedTest(loadTest, maxElapsedTimeInSec)

        return timedTest
        
"""

    /**
     * Decorates a one second response time test as a one
     * user load test with 10 iterations per user, a maximum 
     * elapsed time of 12 seconds, and a 0 second delay
     * between users.
     * 
     * @see testOneSecondResponseOneUserLoadIterationTest
     * @return Test.
     */ 
    protected static Test make1SecondResponse1UserLoadRepeatedTest() {

        int users = 1;
        int iterations = 10;
        long maxElapsedTimeInMillis = 10000 + toleranceInMillis;

        Test testCase = new ExampleTestCase("testOneSecondResponse");

        Test repeatedTest = new RepeatedTest(testCase, iterations);
        Test loadTest = new LoadTest(repeatedTest, users);
        Test timedTest = new TimedTest(loadTest, maxElapsedTimeInMillis);

        return timedTest;
    }

    /**
     * Decorates a one second response time test as a two
     * user load test with a maximum elapsed time of 4 seconds
     * and a 2 second delay between users.
     * 
     * @return Test.
     */ 
    protected static Test make1SecondResponse2UserLoad2SecondDelayTest() {

        int users = 2;
        Timer timer = new ConstantTimer(2000);
        long maxElapsedTimeInMillis = 4000 + toleranceInMillis;

        Test testCase = new ExampleTestCase("testOneSecondResponse");

        Test loadTest = new LoadTest(testCase, users, timer);
        Test timedTest = new TimedTest(loadTest, maxElapsedTimeInMillis);

        return timedTest;
    }

    /**
     * Decorates a one second response time test as a 10
     * user load test with 10 iterations per user, a maximum 
     * elapsed time of 20 seconds, and a 1 second delay
     * between users.
     * 
     * @return Test.
     */ 
    protected static Test 
    make1SecondResponse10UserLoad1SecondDelayIterationTest() {

        int users = 10;
        int iterations = 10;
        Timer timer = new ConstantTimer(1000);
        long maxElapsedTimeInMillis = 20000 + toleranceInMillis;

        Test testCase = new ExampleTestCase("testOneSecondResponse");

        Test loadTest = new LoadTest(testCase, users, iterations, timer);
        Test timedTest = new TimedTest(loadTest, maxElapsedTimeInMillis);

        return timedTest;
    }

    protected static Test makeStateful10UserLoadTest() {
        /**
         * Decorates a stateful test as a 10 user load test,
         * providing each user with a different test instance
         * to ensure thread safety.
         * 
         * @return Test.
         **/

        users = 10
        iterations = 1;

        Test factory = new TestFactory(ExampleStatefulTestCase.class);

        Test loadTest = new LoadTest(factory, users, iterations);

        return loadTest;
    }

    /**
     * Decorates a stateful test method as a 10 user load test,
     * providing each user with a different test instance
     * to ensure thread safety.
     * 
     * @return Test.
     */ 
    protected static Test makeStateful10UserLoadTestMethod() {

        int users = 10;
        int iterations = 1;

        Test factory = 
            new TestMethodFactory(ExampleStatefulTestCase.class, "testState");

        Test loadTest = new LoadTest(factory, users, iterations);

        return loadTest;
    }
"""

if __name__ == "__main__":
    TextTestRunner(verbosity=1).run(ExampleLoadTest().suite())

    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.