def test_not_enough_shares(self): """ If fewer shares are found than are required to reassemble the data then ``CHKCheckerAndUEBFetcher.check`` returns a ``Deferred`` that fires with ``False``. """ storage_index = b"a" * 16 serverid = b"b" * 20 storage = StorageServer(self.mktemp(), serverid) rref_with_ueb = LocalWrapper(storage, fireNow) ueb = { "needed_shares": 2, "total_shares": 2, "segment_size": 128 * 1024, "size": 1024, } yield write_good_share(rref_with_ueb, storage_index, ueb, [0]) server_with_ueb = NoNetworkServer(serverid, rref_with_ueb) peers = {storage_index: [server_with_ueb]} caf = offloaded.CHKCheckerAndUEBFetcher( peers.get, storage_index, None, ) self.assertThat( caf.check(), succeeded(Equals(False)), )
def test_check_no_peers(self): """ If the supplied "peer getter" returns no peers then ``CHKCheckerAndUEBFetcher.check`` returns a ``Deferred`` that fires with ``False``. """ storage_index = b"a" * 16 peers = {storage_index: []} caf = offloaded.CHKCheckerAndUEBFetcher( peers.get, storage_index, None, ) self.assertThat( caf.check(), succeeded(Equals(False)), )
def test_enough_shares(self): """ If enough shares are found to reassemble the data then ``CHKCheckerAndUEBFetcher.check`` returns a ``Deferred`` that fires with share and share placement information. """ storage_index = b"a" * 16 serverids = list(ch * 20 for ch in [b"b", b"c"]) storages = list( FoolscapStorageServer(StorageServer(self.mktemp(), serverid)) for serverid in serverids) rrefs_with_ueb = list( LocalWrapper(storage, fireNow) for storage in storages) ueb = { "needed_shares": len(serverids), "total_shares": len(serverids), "segment_size": 128 * 1024, "size": 1024, } for n, rref_with_ueb in enumerate(rrefs_with_ueb): yield write_good_share(rref_with_ueb, storage_index, ueb, [n]) servers_with_ueb = list( NoNetworkServer(serverid, rref_with_ueb) for (serverid, rref_with_ueb) in zip(serverids, rrefs_with_ueb)) peers = {storage_index: servers_with_ueb} caf = offloaded.CHKCheckerAndUEBFetcher( peers.get, storage_index, None, ) self.assertThat( caf.check(), succeeded( MatchesListwise([ Equals({ n: {serverid} for (n, serverid) in enumerate(serverids) }), Equals(ueb), IsInstance(bytes), ])), )
def test_check_ueb_unavailable(self): """ If the UEB cannot be read from any of the peers supplied by the "peer getter" then ``CHKCheckerAndUEBFetcher.check`` returns a ``Deferred`` that fires with ``False``. """ storage_index = b"a" * 16 serverid = b"b" * 20 storage = StorageServer(self.mktemp(), serverid) rref_without_ueb = LocalWrapper(storage, fireNow) yield write_bad_share(rref_without_ueb, storage_index) server_without_ueb = NoNetworkServer(serverid, rref_without_ueb) peers = {storage_index: [server_without_ueb]} caf = offloaded.CHKCheckerAndUEBFetcher( peers.get, storage_index, None, ) self.assertThat( caf.check(), succeeded(Equals(False)), )