2006-12-03 01:30:18 +00:00
|
|
|
|
|
|
|
from twisted.trial import unittest
|
2006-12-03 02:37:31 +00:00
|
|
|
from twisted.internet import defer, reactor
|
2006-12-03 01:30:18 +00:00
|
|
|
from twisted.application import service
|
2006-12-03 03:32:08 +00:00
|
|
|
from allmydata import client, queen
|
2006-12-03 01:30:18 +00:00
|
|
|
import os
|
2006-12-03 02:37:31 +00:00
|
|
|
from foolscap.eventual import flushEventualQueue
|
2006-12-03 03:32:08 +00:00
|
|
|
from twisted.python import log
|
2006-12-03 10:01:43 +00:00
|
|
|
from allmydata.util import idlib
|
2006-12-03 01:30:18 +00:00
|
|
|
|
|
|
|
class SystemTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.sparent = service.MultiService()
|
|
|
|
self.sparent.startService()
|
|
|
|
def tearDown(self):
|
2006-12-03 02:37:31 +00:00
|
|
|
d = self.sparent.stopService()
|
|
|
|
d.addCallback(lambda res: flushEventualQueue())
|
2006-12-03 07:56:27 +00:00
|
|
|
def _done(res):
|
|
|
|
d1 = defer.Deferred()
|
|
|
|
reactor.callLater(0.1, d1.callback, None)
|
|
|
|
return d1
|
|
|
|
d.addCallback(_done)
|
2006-12-03 02:37:31 +00:00
|
|
|
return d
|
2006-12-03 01:30:18 +00:00
|
|
|
|
2006-12-03 07:56:27 +00:00
|
|
|
def add_service(self, s):
|
2006-12-03 01:30:18 +00:00
|
|
|
s.setServiceParent(self.sparent)
|
|
|
|
return s
|
|
|
|
|
2006-12-03 07:56:27 +00:00
|
|
|
def set_up_nodes(self, NUMCLIENTS=5):
|
|
|
|
self.numclients = NUMCLIENTS
|
2006-12-03 03:32:08 +00:00
|
|
|
if not os.path.isdir("queen"):
|
|
|
|
os.mkdir("queen")
|
2006-12-03 07:56:27 +00:00
|
|
|
q = self.queen = self.add_service(queen.Queen(basedir="queen"))
|
|
|
|
self.queen_pburl = q.urls["roster"]
|
|
|
|
self.clients = []
|
2006-12-03 01:30:18 +00:00
|
|
|
for i in range(NUMCLIENTS):
|
|
|
|
basedir = "client%d" % i
|
2006-12-03 03:32:08 +00:00
|
|
|
if not os.path.isdir(basedir):
|
|
|
|
os.mkdir(basedir)
|
2006-12-03 07:56:27 +00:00
|
|
|
c = self.add_service(client.Client(basedir=basedir))
|
|
|
|
c.set_queen_pburl(self.queen_pburl)
|
|
|
|
self.clients.append(c)
|
|
|
|
log.msg("STARTING")
|
|
|
|
return self.wait_for_connections()
|
2006-12-03 02:37:31 +00:00
|
|
|
|
2006-12-03 07:56:27 +00:00
|
|
|
def wait_for_connections(self, ignored=None):
|
|
|
|
for c in self.clients:
|
|
|
|
if len(c.connections) != self.numclients - 1:
|
|
|
|
d = defer.Deferred()
|
|
|
|
d.addCallback(self.wait_for_connections)
|
|
|
|
reactor.callLater(0.05, d.callback, None)
|
|
|
|
return d
|
|
|
|
return defer.succeed(None)
|
2006-12-03 02:37:31 +00:00
|
|
|
|
2006-12-03 03:32:08 +00:00
|
|
|
def test_connections(self):
|
2006-12-03 07:56:27 +00:00
|
|
|
d = self.set_up_nodes()
|
2006-12-03 03:32:08 +00:00
|
|
|
def _check(res):
|
|
|
|
for c in self.clients:
|
|
|
|
self.failUnlessEqual(len(c.connections), 4)
|
|
|
|
d.addCallback(_check)
|
|
|
|
return d
|
2006-12-03 07:56:27 +00:00
|
|
|
test_connections.timeout = 20
|
2006-12-03 03:32:08 +00:00
|
|
|
|
2006-12-03 10:01:43 +00:00
|
|
|
def test_upload_and_download(self):
|
|
|
|
DATA = "Some data to upload\n"
|
2006-12-03 07:56:27 +00:00
|
|
|
d = self.set_up_nodes()
|
2006-12-03 10:01:43 +00:00
|
|
|
def _do_upload(res):
|
2006-12-03 07:56:27 +00:00
|
|
|
log.msg("UPLOADING")
|
2006-12-03 03:32:08 +00:00
|
|
|
u = self.clients[0].getServiceNamed("uploader")
|
2006-12-03 10:01:43 +00:00
|
|
|
d1 = u.upload_data(DATA)
|
2006-12-03 03:32:08 +00:00
|
|
|
return d1
|
2006-12-03 10:01:43 +00:00
|
|
|
d.addCallback(_do_upload)
|
|
|
|
def _upload_done(verifierid):
|
|
|
|
log.msg("upload finished: verifierid=%s" % idlib.b2a(verifierid))
|
|
|
|
dl = self.clients[1].getServiceNamed("downloader")
|
|
|
|
d1 = dl.download_to_data(verifierid)
|
|
|
|
return d1
|
|
|
|
d.addCallback(_upload_done)
|
|
|
|
def _download_done(data):
|
|
|
|
log.msg("download finished")
|
|
|
|
self.failUnlessEqual(data, DATA)
|
|
|
|
d.addCallback(_download_done)
|
2006-12-03 02:37:31 +00:00
|
|
|
return d
|
2006-12-03 10:01:43 +00:00
|
|
|
test_upload_and_download.timeout = 20
|
2006-12-03 07:56:27 +00:00
|
|
|
|
2006-12-04 05:42:19 +00:00
|
|
|
def test_vdrive(self):
|
|
|
|
DATA = "Some data to publish to the virtual drive\n"
|
|
|
|
d = self.set_up_nodes()
|
|
|
|
def _do_publish(res):
|
|
|
|
log.msg("PUBLISHING")
|
|
|
|
v0 = self.clients[0].getServiceNamed("vdrive")
|
|
|
|
d1 = v0.make_directory("/", "subdir1")
|
|
|
|
d1.addCallback(lambda subdir1:
|
|
|
|
v0.put_file_by_data(subdir1, "data", DATA))
|
|
|
|
return d1
|
|
|
|
d.addCallback(_do_publish)
|
|
|
|
def _publish_done(res):
|
|
|
|
log.msg("publish finished")
|
|
|
|
v1 = self.clients[1].getServiceNamed("vdrive")
|
|
|
|
d1 = v1.get_file_to_data("/subdir1/data")
|
|
|
|
return d1
|
|
|
|
d.addCallback(_publish_done)
|
|
|
|
def _get_done(data):
|
|
|
|
log.msg("get finished")
|
|
|
|
self.failUnlessEqual(data, DATA)
|
|
|
|
d.addCallback(_get_done)
|
|
|
|
return d
|
|
|
|
test_vdrive.timeout = 20
|
|
|
|
|