[ create a new paste ] login | about

Link: http://codepad.org/LIj7CF0t    [ raw code | fork ]

Python, pasted on Oct 23:
    def test_retrieve_surprise(self):
        self.basedir = "mutable/Problems/test_retrieve_surprise"
        self.set_up_grid()
        nm = self.g.clients[0].nodemaker
        d = nm.create_mutable_file(MutableData("contents 1"))
        def _get_write_uri(n):
            print repr(n)
            return n.get_write_uri()
        d.addCallback(_get_write_uri)
        def _clear_node_cache(uri):
            nm._node_cache.clear()
            return uri
        d.addCallback(_clear_node_cache)
        d.addCallback(lambda uri: nm.create_from_cap(uri))
        def _created(n):
            print repr(n)
            d = defer.succeed(None)
            d.addCallback(lambda res: n.get_servermap(MODE_READ))
            def _got_smap1(smap):
                # stash the old state of the file
                self.old_map = smap
            d.addCallback(_got_smap1)
            # then modify the file, leaving the old map untouched
            d.addCallback(lambda res: log.msg("starting winning write"))
            d.addCallback(lambda res: n.overwrite(MutableData("contents 2")))
            # now attempt to retrieve the old version with the old servermap.
            # This will look like someone has changed the file since we
            # updated the servermap.

            d.addCallback(lambda res: log.msg("starting doomed read"))
            d.addCallback(lambda res:
                          self.shouldFail(NotEnoughSharesError,
                                          "test_retrieve_surprise",
                                          "ran out of servers: have 0 of 1",
                                          n.download_version,
                                          self.old_map,
                                          self.old_map.best_recoverable_version(),
                                          ))
            return d
        d.addCallback(_created)
        return d


Create a new paste based on this one


Comments: