Change in vdsm[master]: DsadAS
smizrahi at redhat.com
smizrahi at redhat.com
Sun Oct 26 08:22:48 UTC 2014
Saggi Mizrahi has uploaded a new change for review.
Change subject: DsadAS
......................................................................
DsadAS
Change-Id: Ie751276e0acd6b3a1cfc5b346eabe0060ba786ba
Signed-off-by: Saggi Mizrahi <smizrahi at redhat.com>
---
M lib/yajsonrpc/__init__.py
M lib/yajsonrpc/stomp.py
M tests/jsonRpcTests.py
M tests/testlib.py
4 files changed, 42 insertions(+), 14 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/34473/1
diff --git a/lib/yajsonrpc/__init__.py b/lib/yajsonrpc/__init__.py
index b3fd590..96c9757 100644
--- a/lib/yajsonrpc/__init__.py
+++ b/lib/yajsonrpc/__init__.py
@@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import json
+import simplejson as json
import logging
from functools import partial
from Queue import Queue
diff --git a/lib/yajsonrpc/stomp.py b/lib/yajsonrpc/stomp.py
index 884bff6..9bf3990 100644
--- a/lib/yajsonrpc/stomp.py
+++ b/lib/yajsonrpc/stomp.py
@@ -15,7 +15,6 @@
import logging
import socket
-import cStringIO
from threading import Timer, Event
from uuid import uuid4
from collections import deque
@@ -147,17 +146,20 @@
self._flush()
def _flush(self):
- self._buffer = cStringIO.StringIO()
+ self._buffer = ""
+
+ def _write_buffer(self, buff):
+ self._buffer += buff
+
+ def _get_buffer(self):
+ return self._buffer
def _handle_terminator(self, term):
- if term not in self._buffer.getvalue():
+ res, _, rest = self._buffer.partition(term)
+ if not _:
return None
- data = self._buffer.getvalue()
- res, rest = data.split(term, 1)
- self._flush()
- self._buffer.write(rest)
-
+ self._buffer = rest
return res
def _parse_command(self):
@@ -226,16 +228,16 @@
return True
def _parse_body_length(self):
- buf = self._buffer
+ buf = self._get_buffer()
cl = self._contentLength
- ndata = buf.tell()
+ ndata = len(buf)
if ndata < cl:
return False
remainingBytes = 0
self._flush()
- body = buf.getvalue()
- self._buffer.write(body[cl + 1:])
+ body = buf
+ self._write_buffer(body[cl + 1:])
body = body[:cl]
if remainingBytes == 0:
@@ -250,7 +252,7 @@
def parse(self, data):
states = self._states
- self._buffer.write(data)
+ self._write_buffer(data)
while states[self._state]():
pass
diff --git a/tests/jsonRpcTests.py b/tests/jsonRpcTests.py
index 230b61a..79e9af5 100644
--- a/tests/jsonRpcTests.py
+++ b/tests/jsonRpcTests.py
@@ -18,6 +18,10 @@
# Refer to the README and COPYING files for full details of the license
#
import logging
+import os
+
+import yappi
+
from clientIF import clientIF
from contextlib import contextmanager
from monkeypatch import MonkeyPatch
@@ -176,3 +180,24 @@
res = self._callTimeout(client, "ping", [],
CALL_ID, timeout=CALL_TIMEOUT)
self.assertEquals(res, True)
+
+ @permutations(PERMUTATIONS)
+ def testTimeRequest(self, ssl, type):
+ base_file = "/tmp/jsonrpc.%s.%s" % (ssl, type,)
+ stats_file = base_file + ".stats"
+ time_file = base_file + ".ts"
+ t = os.times()[4]
+ bridge = _DummyBridge()
+ with constructClient(self.log, bridge, ssl, type) as clientFactory:
+ with self._client(clientFactory) as client:
+ yappi.start()
+ for i in xrange(5000):
+ if type == "xml":
+ client.send("ping", ())
+ else:
+ self._callTimeout(client, "ping", [],
+ CALL_ID, timeout=CALL_TIMEOUT)
+ yappi.get_func_stats().save(stats_file, type="pstat")
+
+ with open(time_file, "w") as f:
+ f.write("%s.%s: %f\n" % (type, ssl, os.times()[4] - t,))
diff --git a/tests/testlib.py b/tests/testlib.py
index 6fffb3c..d3a0bd9 100644
--- a/tests/testlib.py
+++ b/tests/testlib.py
@@ -70,6 +70,7 @@
def expandPermutations(cls):
+ logging.disable(logging.INFO)
for attr in dir(cls):
f = getattr(cls, attr)
if not hasattr(f, PERMUTATION_ATTR):
--
To view, visit http://gerrit.ovirt.org/34473
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie751276e0acd6b3a1cfc5b346eabe0060ba786ba
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Saggi Mizrahi <smizrahi at redhat.com>
More information about the vdsm-patches
mailing list