Esempio n. 1
0
    def test_master_failure(self):
        log.debug("test_master_failure")

        client = stub_etcd.Client()
        client.add_read_exception(stub_etcd.EtcdKeyNotFound())
        # Now become the master but fail
        client.add_write_exception(stub_etcd.EtcdException())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_result(key="/bloop", value=None, action="delete")
        # Now become the master but fail again
        client.add_write_exception(stub_etcd.EtcdException())
        # Go back to the beginning again.
        client.add_read_result(key="/bloop", value="value")
        client.add_read_result(key="/bloop", value=None, action="delete")
        client.add_write_exception(None)
        client.add_write_exception(None)
        elector = election.Elector(client,
                                   "test_basic",
                                   "/bloop",
                                   interval=5,
                                   ttl=15)
        self._wait_and_stop(client, elector)

        # We are no longer the master, after error.
        self.assertFalse(elector.master())
Esempio n. 2
0
 def test_fail_to_maintain(self):
     # Become the master after once round
     log.debug("test_become_master_first_time")
     client = stub_etcd.Client()
     client.add_read_exception(stub_etcd.EtcdKeyNotFound())
     client.add_write_exception(None)
     client.add_write_exception(stub_etcd.EtcdClusterIdChanged())
     elector = election.Elector(client,
                                "test_basic",
                                "/bloop",
                                interval=5,
                                ttl=15)
     self._wait_and_stop(client, elector)
Esempio n. 3
0
 def test_become_master_implausible(self):
     # Become the master after key vanishes
     log.debug("test_become_master_implausible")
     client = stub_etcd.Client()
     client.add_read_result(key="/bloop", value="value")
     client.add_read_result(key="/bloop", value="value")
     client.add_read_exception(stub_etcd.EtcdKeyNotFound())
     client.add_write_result()
     client.add_write_result()
     elector = election.Elector(client,
                                "test_basic",
                                "/bloop",
                                interval=5,
                                ttl=15)
     self._wait_and_stop(client, elector)