-import os, time
+import os, time, tempfile
from zope.interface import implements
from twisted.application import service
from twisted.internet import defer
def remote_wait_for_client_connections(self, num_clients):
return self.parent.debug_wait_for_client_connections(num_clients)
+ def remote_upload_random_data_from_file(self, size, convergence):
+ filename = tempfile.NamedTemporaryFile(delete=False).name
+ f = open(filename, "wb")
+ block = "a" * 8192
+ while size > 0:
+ l = min(size, 8192)
+ f.write(block[:l])
+ size -= l
+ f.close()
+ uploader = self.parent.getServiceNamed("uploader")
+ u = upload.FileName(filename, convergence=convergence)
+ d = uploader.upload(u)
+ d.addCallback(lambda results: results.get_uri())
+ def _done(uri):
+ os.remove(filename)
+ return uri
+ d.addCallback(_done)
+ return d
+
+ def remote_download_to_tempfile_and_delete(self, uri):
+ tempdir = tempfile.mkdtemp()
+ filename = os.path.join(tempdir, "data")
+ filenode = self.parent.create_node_from_uri(uri, name=filename)
+ if not IFileNode.providedBy(filenode):
+ raise AssertionError("The URI does not reference a file.")
+ c = FileWritingConsumer(filename)
+ d = filenode.read(c)
+ def _done(res):
+ os.remove(filename)
+ os.rmdir(tempdir)
+ return None
+ d.addCallback(_done)
+ return d
+
def remote_speed_test(self, count, size, mutable):
assert size > 8
log.msg("speed_test: count=%d, size=%d, mutable=%s" % (count, size,
# debug stuff
+ def upload_random_data_from_file(size=int, convergence=str):
+ return str
+
+ def download_to_tempfile_and_delete(uri=str):
+ return None
+
def get_memory_usage():
"""Return a dict describes the amount of memory currently in use. The
keys are 'VmPeak', 'VmSize', and 'VmData'. The values are integers,
print
print "uploading %s" % name
if self.mode in ("upload", "upload-self"):
- files[name] = self.create_data(name, size)
- d = self.control_rref.callRemote("upload_from_file_to_uri",
- files[name].encode("utf-8"),
+ d = self.control_rref.callRemote("upload_random_data_from_file",
+ size,
convergence="check-memory")
- def _done(uri):
- os.remove(files[name])
- del files[name]
- return uri
- d.addCallback(_done)
elif self.mode == "upload-POST":
data = "a" * size
url = "/uri"
uri = uris[name]
if self.mode == "download":
- d = self.control_rref.callRemote("download_from_uri_to_file",
- uri, "dummy.out")
+ d = self.control_rref.callRemote("download_to_tempfile_and_delete",
+ uri)
elif self.mode == "download-GET":
url = "/uri/%s" % uri
d = self.GET_discard(urllib.quote(url), stall=False)