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