Revision cfb87e18 docs/developers/extending-clients-api.rst
b/docs/developers/extending-clients-api.rst | ||
---|---|---|
69 | 69 |
Concurrency control |
70 | 70 |
------------------- |
71 | 71 |
|
72 |
Kamaki clients may handle multiple requests at once, using threads. In that
|
|
73 |
case, users might implement their own thread handling mechanism, use an
|
|
74 |
external solution or take advantage of the mechanism featured in kamaki.clients
|
|
72 |
Kamaki clients may handle multiple requests with threads. The easiest way is
|
|
73 |
using the `async_run` method, fed with a list of argument dictionaries (one for
|
|
74 |
each call of the single method).
|
|
75 | 75 |
|
76 | 76 |
.. code-block:: python |
77 | 77 |
|
78 |
from threading import enumerate |
|
79 |
from kamaki.clients import SilentEvent |
|
80 |
... |
|
81 |
|
|
82 | 78 |
class MyNewClient(Client): |
83 | 79 |
... |
84 | 80 |
|
85 | 81 |
def _single_threaded_method(self, **args): |
86 | 82 |
... |
87 |
request code |
|
88 |
... |
|
89 | 83 |
|
90 | 84 |
def multithread_method(self): |
91 |
thread_list = [] |
|
92 |
self._init_thread_limit() |
|
93 |
while some_condition or thread_list: |
|
94 |
... |
|
95 |
event = SilentEvent(self._single_threaded_method, **args) |
|
96 |
event.start() |
|
97 |
thread_list.append(event) |
|
98 |
thread_list = self._watch_thread_limit(thread_list) |
|
85 |
kwarg_list = [kwarg for each run] |
|
86 |
self.async_run(self._single_threaded_method, kwarg_list) |
|
99 | 87 |
|
100 | 88 |
Going agile |
101 | 89 |
----------- |
... | ... | |
109 | 97 |
Using the tests |
110 | 98 |
^^^^^^^^^^^^^^^ |
111 | 99 |
|
112 |
To run the tests, the kamaki source code has to be downloaded. |
|
113 |
|
|
114 |
.. code-block:: console |
|
100 |
First, the source code of kamaki must be accessible. If this is not the case, |
|
101 |
the source code can be obtained from here: |
|
115 | 102 |
|
116 |
$ git clone https://code.grnet.gr/git/kamaki |
|
117 |
$ cd kamaki/kamaki/clients |
|
103 |
`https://code.grnet.gr/projects/kamaki/files <https://code.grnet.gr/projects/kamaki/files>`_ |
|
118 | 104 |
|
119 |
In each package under kamaki.clients, there is a test module (test.py) where |
|
120 |
the tests are implemented. To run all tests, run the test.py file from |
|
121 |
kamaki.clients |
|
105 |
In each package under kamaki.clients, there is a test module (`test.py`). To |
|
106 |
run all tests, run the test.py file from kamaki.clients |
|
122 | 107 |
|
123 | 108 |
.. code-block:: console |
124 | 109 |
|
110 |
$ cd ${KAMAKI_SOURCE_LOCATION}/kamaki/clients |
|
125 | 111 |
$ python test.py |
126 | 112 |
|
127 | 113 |
To test a specific class, add the class name as an argument. e.g., for the |
... | ... | |
166 | 152 |
Mechanism |
167 | 153 |
^^^^^^^^^ |
168 | 154 |
|
169 |
Each folder / package contains a test.py file, that represents the test module
|
|
170 |
of this package. All test modules contain a set of classes that extent the
|
|
171 |
TestCase class. They also contain a main method to run the tests.
|
|
155 |
Each folder / package contains a test.py file, where its test module lived. All
|
|
156 |
test modules contain a set of classes that extent the TestCase class. They also
|
|
157 |
contain a main method to run the tests. |
|
172 | 158 |
|
173 | 159 |
By convention, testing classes have the same name as the class they test. |
174 | 160 |
Methods not grouped in classes are tested by classes named after their |
... | ... | |
204 | 190 |
|
205 | 191 |
To implement a new method in an existing class, developers are encouraged to |
206 | 192 |
implement the corresponding unit test first. In order to do that, they should |
207 |
find the testing class that is mapped to the class or module they working on.
|
|
193 |
find the testing class that is mapped to the class or module they work on. |
|
208 | 194 |
|
209 | 195 |
Example: Adding **list_special** to *kamaki.clients.astakos.AstakosClient*, |
210 | 196 |
requires changes to *kamaki.clients.astakos.test.AstakosClient* too, as shown |
... | ... | |
236 | 222 |
|
237 | 223 |
$ mkdir new_service && touch new_service/test.py |
238 | 224 |
|
239 |
* create the file to code the package implementation:
|
|
225 |
* create the package file for the package implementation:
|
|
240 | 226 |
|
241 | 227 |
.. code-block:: console |
242 | 228 |
|
... | ... | |
254 | 240 |
def test_method1(self): |
255 | 241 |
... |
256 | 242 |
|
257 |
* Create the NewService and its actual functionality in kamaki.clients.new_service |
|
243 |
* Create the NewService and its actual functionality in |
|
244 |
kamaki.clients.new_service |
|
258 | 245 |
|
259 | 246 |
.. code-block:: python |
260 | 247 |
|
Also available in: Unified diff