feat: post to leadere
This commit is contained in:
parent
9c0a85915c
commit
6ba293d287
1 changed files with 27 additions and 16 deletions
31
test.py
31
test.py
|
@ -44,11 +44,12 @@ def metrics(host: str):
|
|||
def write(host, data):
|
||||
resp = requests.post(f"http://{host}/write", json=data)
|
||||
print(f"RPC Status: {resp.status_code}")
|
||||
data = resp.json()
|
||||
if "Err" in data:
|
||||
leader = data["Err"]["APIError"]["ForwardToLeader"]["leader_node"]["addr"]
|
||||
write(leader, data)
|
||||
return data['Ok']['data']
|
||||
resp = resp.json()
|
||||
if "Err" in resp:
|
||||
leader = resp["Err"]["APIError"]["ForwardToLeader"]["leader_node"]["addr"]
|
||||
print(f"Forwarding write to leader {leader}")
|
||||
return write(leader, data)
|
||||
return resp["Ok"]["data"]
|
||||
|
||||
|
||||
def add_vote(host: str, captcha_id: str):
|
||||
|
@ -77,14 +78,24 @@ def add_captcha(host: str, captcha_id: str):
|
|||
pprint(f"Captcha added {captcha_id}: {resp}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
host = "localhost:9001"
|
||||
# init(host)
|
||||
# add_host(host, id=2, peer="localhost:9002")
|
||||
# switch_to_cluster(host, nodes=[1, 2])
|
||||
# metrics(host)
|
||||
peers = [(2, "localhost:9002"), (3, "localhost:9003"), (4, "localhost:9004")]
|
||||
captcha_id = "test_1"
|
||||
|
||||
def initialize_cluster():
|
||||
init(host)
|
||||
for peer_id, peer in peers:
|
||||
add_host(host=host, id=peer_id, peer=peer)
|
||||
|
||||
switch_to_cluster(host, nodes=[1, 2,3,4])
|
||||
|
||||
add_captcha(host, captcha_id)
|
||||
add_vote(host, captcha_id)
|
||||
for _ in range(0, 600):
|
||||
add_vote(host, captcha_id)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
add_vote("localhost:9002", captcha_id)
|
||||
|
|
Loading…
Reference in a new issue