2006-11-30 23:23:01 +00:00
|
|
|
|
2007-03-27 23:12:11 +00:00
|
|
|
import os
|
2006-11-30 23:23:01 +00:00
|
|
|
from twisted.trial import unittest
|
2007-06-08 05:09:02 +00:00
|
|
|
from twisted.application import service
|
2006-11-30 23:23:01 +00:00
|
|
|
|
2007-04-26 19:01:25 +00:00
|
|
|
import allmydata
|
2007-03-30 03:19:52 +00:00
|
|
|
from allmydata import client, introducer
|
2007-04-26 19:01:25 +00:00
|
|
|
from allmydata.util import version
|
2007-06-08 05:09:02 +00:00
|
|
|
from foolscap.eventual import flushEventualQueue
|
2006-11-30 23:23:01 +00:00
|
|
|
|
2007-03-30 03:19:52 +00:00
|
|
|
class MyIntroducerClient(introducer.IntroducerClient):
|
|
|
|
def __init__(self):
|
2007-03-27 23:12:11 +00:00
|
|
|
self.connections = {}
|
|
|
|
|
2007-03-30 03:19:52 +00:00
|
|
|
def permute(c, key):
|
|
|
|
return [ y for x, y, z in c.get_permuted_peers(key) ]
|
2007-03-27 23:12:11 +00:00
|
|
|
|
2006-11-30 23:23:01 +00:00
|
|
|
class Basic(unittest.TestCase):
|
2006-12-01 03:18:51 +00:00
|
|
|
def test_loadable(self):
|
2007-03-27 23:12:11 +00:00
|
|
|
basedir = "test_client.Basic.test_loadable"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
2006-11-30 23:23:01 +00:00
|
|
|
|
2007-06-08 00:55:49 +00:00
|
|
|
def test_loadable_without_vdrive(self):
|
|
|
|
basedir = "test_client.Basic.test_loadable_without_vdrive"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
|
2007-07-04 00:27:07 +00:00
|
|
|
def test_sizelimit_1(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_1"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("1000")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
self.failUnlessEqual(c.getServiceNamed("storageserver").sizelimit,
|
|
|
|
1000)
|
|
|
|
|
|
|
|
def test_sizelimit_2(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_2"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("10K")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
self.failUnlessEqual(c.getServiceNamed("storageserver").sizelimit,
|
|
|
|
10*1000)
|
|
|
|
|
|
|
|
def test_sizelimit_3(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_3"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("5mB")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
self.failUnlessEqual(c.getServiceNamed("storageserver").sizelimit,
|
|
|
|
5*1000*1000)
|
|
|
|
|
|
|
|
def test_sizelimit_4(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_4"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("78Gb")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
self.failUnlessEqual(c.getServiceNamed("storageserver").sizelimit,
|
|
|
|
78*1000*1000*1000)
|
|
|
|
|
|
|
|
def test_sizelimit_bad(self):
|
|
|
|
basedir = "client.Basic.test_sizelimit_bad"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "sizelimit"), "w").write("bogus")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
self.failUnlessEqual(c.getServiceNamed("storageserver").sizelimit,
|
|
|
|
None)
|
|
|
|
|
2006-12-01 03:18:51 +00:00
|
|
|
def test_permute(self):
|
2007-03-27 23:12:11 +00:00
|
|
|
basedir = "test_client.Basic.test_permute"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
2007-03-30 03:19:52 +00:00
|
|
|
c = client.Client(basedir)
|
|
|
|
c.introducer_client = MyIntroducerClient()
|
2007-03-23 23:15:57 +00:00
|
|
|
for k in ["%d" % i for i in range(5)]:
|
2007-03-30 03:19:52 +00:00
|
|
|
c.introducer_client.connections[k] = None
|
|
|
|
self.failUnlessEqual(permute(c, "one"), ['3','1','0','4','2'])
|
|
|
|
self.failUnlessEqual(permute(c, "two"), ['0','4','2','1','3'])
|
|
|
|
c.introducer_client.connections.clear()
|
|
|
|
self.failUnlessEqual(permute(c, "one"), [])
|
|
|
|
|
|
|
|
c2 = client.Client(basedir)
|
|
|
|
c2.introducer_client = MyIntroducerClient()
|
2007-03-23 23:15:57 +00:00
|
|
|
for k in ["%d" % i for i in range(5)]:
|
2007-03-30 03:19:52 +00:00
|
|
|
c2.introducer_client.connections[k] = None
|
|
|
|
self.failUnlessEqual(permute(c2, "one"), ['3','1','0','4','2'])
|
2007-01-16 04:22:22 +00:00
|
|
|
|
2007-04-26 19:01:25 +00:00
|
|
|
def test_versions(self):
|
|
|
|
basedir = "test_client.Basic.test_versions"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
|
|
|
open(os.path.join(basedir, "vdrive.furl"), "w").write("")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
mine, oldest = c.remote_get_versions()
|
|
|
|
self.failUnlessEqual(version.Version(mine), allmydata.__version__)
|
|
|
|
|
2007-06-08 05:09:02 +00:00
|
|
|
def flush_but_dont_ignore(res):
|
|
|
|
d = flushEventualQueue()
|
|
|
|
def _done(ignored):
|
|
|
|
return res
|
|
|
|
d.addCallback(_done)
|
|
|
|
return d
|
|
|
|
|
|
|
|
class Run(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.sparent = service.MultiService()
|
|
|
|
self.sparent.startService()
|
|
|
|
def tearDown(self):
|
|
|
|
d = self.sparent.stopService()
|
|
|
|
d.addBoth(flush_but_dont_ignore)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def test_loadable(self):
|
|
|
|
basedir = "test_client.Run.test_loadable"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write(dummy)
|
|
|
|
open(os.path.join(basedir, "suicide_prevention_hotline"), "w")
|
|
|
|
c = client.Client(basedir)
|
|
|
|
|
|
|
|
def test_reloadable(self):
|
|
|
|
basedir = "test_client.Run.test_reloadable"
|
|
|
|
os.mkdir(basedir)
|
|
|
|
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
|
|
|
open(os.path.join(basedir, "introducer.furl"), "w").write(dummy)
|
|
|
|
c1 = client.Client(basedir)
|
|
|
|
c1.setServiceParent(self.sparent)
|
|
|
|
|
|
|
|
d = c1.disownServiceParent()
|
|
|
|
def _restart(res):
|
|
|
|
c2 = client.Client(basedir)
|
|
|
|
c2.setServiceParent(self.sparent)
|
|
|
|
return c2.disownServiceParent()
|
|
|
|
d.addCallback(_restart)
|
|
|
|
return d
|
|
|
|
|