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 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())
|
|
|
|
return d
|
2006-12-03 01:30:18 +00:00
|
|
|
|
|
|
|
def addService(self, s):
|
|
|
|
s.setServiceParent(self.sparent)
|
|
|
|
return s
|
|
|
|
|
2006-12-03 03:32:08 +00:00
|
|
|
def setUpNodes(self, NUMCLIENTS=5):
|
|
|
|
if not os.path.isdir("queen"):
|
|
|
|
os.mkdir("queen")
|
|
|
|
q = self.queen = self.addService(queen.Queen(basedir="queen"))
|
|
|
|
queen_pburl = q.urls["roster"]
|
|
|
|
clients = 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 02:37:31 +00:00
|
|
|
c = self.addService(client.Client(basedir=basedir))
|
2006-12-03 03:32:08 +00:00
|
|
|
c.set_queen_pburl(queen_pburl)
|
2006-12-03 02:37:31 +00:00
|
|
|
clients.append(c)
|
|
|
|
|
2006-12-03 01:30:18 +00:00
|
|
|
|
2006-12-03 02:37:31 +00:00
|
|
|
def waitForConnections(self):
|
|
|
|
# the cheap way: time
|
|
|
|
d = defer.Deferred()
|
|
|
|
reactor.callLater(1, d.callback, None)
|
|
|
|
return d
|
|
|
|
|
2006-12-03 03:32:08 +00:00
|
|
|
def test_connections(self):
|
|
|
|
self.setUpNodes()
|
|
|
|
d = self.waitForConnections()
|
|
|
|
def _check(res):
|
|
|
|
log.msg("CHECKING")
|
|
|
|
for c in self.clients:
|
|
|
|
self.failUnlessEqual(len(c.connections), 4)
|
|
|
|
d.addCallback(_check)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def test_upload(self):
|
2006-12-03 02:37:31 +00:00
|
|
|
self.setUpNodes()
|
|
|
|
d = self.waitForConnections()
|
2006-12-03 03:32:08 +00:00
|
|
|
def _upload(res):
|
|
|
|
log.msg("DONE")
|
|
|
|
u = self.clients[0].getServiceNamed("uploader")
|
|
|
|
d1 = u.upload_data("Some data to upload")
|
|
|
|
return d1
|
|
|
|
d.addCallback(_upload)
|
2006-12-03 02:37:31 +00:00
|
|
|
return d
|