blob: e34738f433f45cc6008530fe7e26a8edf2df3822 [file] [log] [blame]
Sean Dague70112362012-04-03 13:48:49 -04001# Copyright 2011 Quanta Research Cambridge, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Class to describe actions to be included in a stress test."""
15
16
17class BasherAction(object):
18 """
19 Used to describe each action that you would like to include in a test run.
20 """
21
22 def __init__(self, test_case, probability, pargs=[], kargs={}):
23 """
24 `test_case` : the name of the class that implements the action
25 `pargs` : positional arguments to the constructor of `test_case`
26 `kargs` : keyword arguments to the constructor of `test_case`
27 `probability`: frequency that each action
28 """
29 self.test_case = test_case
30 self.pargs = pargs
31 self.kargs = kargs
32 self.probability = probability
33
34 def invoke(self, manager, state):
35 """
36 Calls the `run` method of the `test_case`.
37 """
38 return self.test_case.run(manager, state, *self.pargs, **self.kargs)
39
40 def __str__(self):
41 return self.test_case.__class__.__name__