コード例 #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())
コード例 #2
0
    def test_later_exceptions(self):
        log.debug("test_later_read_exceptions")

        client = stub_etcd.Client()
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(stub_etcd.EtcdException())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(ReadTimeoutError("pool", "url", "message"))
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(SocketTimeout())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(ConnectTimeoutError())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(HTTPError())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(HTTPException())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(stub_etcd.EtcdClusterIdChanged())
        client.add_read_result(key="/bloop", value="value")
        client.add_read_exception(stub_etcd.EtcdEventIndexCleared())
        elector = election.Elector(client,
                                   "test_basic",
                                   "/bloop",
                                   interval=5,
                                   ttl=15)
        self._wait_and_stop(client, elector)
コード例 #3
0
    def test_invalid(self):
        # Test that not elected using defaults.
        with self.assertRaises(ValueError):
            client = stub_etcd.Client()
            elector = election.Elector(client,
                                       "test_basic",
                                       "/bloop",
                                       interval=-1,
                                       ttl=15)
            self.assertFalse(elector.master())

        with self.assertRaises(ValueError):
            client = stub_etcd.Client()
            elector = election.Elector(client,
                                       "test_basic",
                                       "/bloop",
                                       interval=10,
                                       ttl=5)
            self.assertFalse(elector.master())
コード例 #4
0
 def test_basic_election(self):
     # Test that not elected using defaults.
     log.debug("test_basic_election")
     client = stub_etcd.Client()
     client.add_read_result(key="/bloop", value="value")
     elector = election.Elector(client,
                                "test_basic",
                                "/bloop",
                                interval=5,
                                ttl=15)
     self._wait_and_stop(client, elector)
     self.assertFalse(elector.master())
コード例 #5
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)
コード例 #6
0
    def test_initial_read_exceptions(self):
        log.debug("test_initial_read_exceptions")

        client = stub_etcd.Client()
        client.add_read_exception(stub_etcd.EtcdException())
        client.add_read_exception(stub_etcd.EtcdConnectionFailed())
        client.add_read_exception(stub_etcd.EtcdClusterIdChanged())
        client.add_read_exception(stub_etcd.EtcdEventIndexCleared())
        elector = election.Elector(client,
                                   "test_basic",
                                   "/bloop",
                                   interval=5,
                                   ttl=15)
        self._wait_and_stop(client, elector)
コード例 #7
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)
コード例 #8
0
 def test_become_master_multiple_attempts(self):
     # Become the master after once round
     log.debug("test_become_master_multiple_circuits")
     for action in ["delete", "expire", "compareAndDelete", "something"]:
         log.info("Testing etcd delete event %s", action)
         client = stub_etcd.Client()
         client.add_read_result(key="/bloop", value="value")
         client.add_read_result(key="/bloop", value="value")
         client.add_read_result(key="/bloop", value=None, action=action)
         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)