2007-04-18 03:03:44 +00:00
|
|
|
|
|
|
|
from twisted.trial import unittest
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
from allmydata import storageserver
|
|
|
|
from allmydata.util import fileutil
|
|
|
|
|
|
|
|
class Storage(unittest.TestCase):
|
|
|
|
def make_workdir(self, name):
|
|
|
|
basedir = os.path.join("test_storage", "Storage", name)
|
2007-04-18 03:21:05 +00:00
|
|
|
incoming = os.path.join(basedir, "tmp", "bucket")
|
|
|
|
final = os.path.join(basedir, "bucket")
|
2007-04-18 03:03:44 +00:00
|
|
|
fileutil.make_dirs(basedir)
|
2007-04-18 03:21:05 +00:00
|
|
|
return incoming, final
|
2007-04-18 03:03:44 +00:00
|
|
|
|
|
|
|
def test_create(self):
|
2007-04-18 03:21:05 +00:00
|
|
|
incoming, final = self.make_workdir("test_create")
|
|
|
|
bw = storageserver.BucketWriter(incoming, final, 25)
|
2007-04-18 03:03:44 +00:00
|
|
|
bw.remote_put_block(0, "a"*25)
|
|
|
|
bw.remote_put_block(1, "b"*25)
|
|
|
|
bw.remote_put_block(2, "c"*7) # last block may be short
|
|
|
|
bw.remote_close()
|
|
|
|
|
|
|
|
def test_readwrite(self):
|
2007-04-18 03:21:05 +00:00
|
|
|
incoming, final = self.make_workdir("test_readwrite")
|
|
|
|
bw = storageserver.BucketWriter(incoming, final, 25)
|
2007-04-18 03:03:44 +00:00
|
|
|
bw.remote_put_block(0, "a"*25)
|
|
|
|
bw.remote_put_block(1, "b"*25)
|
|
|
|
bw.remote_put_block(2, "c"*7) # last block may be short
|
|
|
|
bw.remote_put_block_hashes(["1"*32, "2"*32, "3"*32, "4"*32])
|
|
|
|
bw.remote_put_share_hashes([(5, "5"*32), (6, "6"*32)])
|
|
|
|
bw.remote_close()
|
|
|
|
|
|
|
|
# now read from it
|
2007-04-18 03:21:05 +00:00
|
|
|
br = storageserver.BucketReader(final)
|
2007-04-18 03:03:44 +00:00
|
|
|
self.failUnlessEqual(br.remote_get_block(0), "a"*25)
|
|
|
|
self.failUnlessEqual(br.remote_get_block(1), "b"*25)
|
|
|
|
self.failUnlessEqual(br.remote_get_block(2), "c"*7)
|
|
|
|
self.failUnlessEqual(br.remote_get_block_hashes(),
|
|
|
|
["1"*32, "2"*32, "3"*32, "4"*32])
|
|
|
|
self.failUnlessEqual(br.remote_get_share_hashes(),
|
|
|
|
[(5, "5"*32), (6, "6"*32)])
|
|
|
|
|