-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_impl.py
More file actions
84 lines (75 loc) · 2.35 KB
/
run_impl.py
File metadata and controls
84 lines (75 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import argparse
import ndjson
import time
import signal
from subprocess import Popen
jar_name = "locksv-1.1-noabort-demo-jar-with-dependencies.jar"
def read_json(filename):
with open(filename) as f:
return ndjson.load(f)
def run(clients, server):
print("--- Run server ---")
network_process = Popen([
"java",
"-cp",
f"target/{jar_name}",
"org.lbee.network.Server",
"6869", "unordered"])
print("--- Run server ---")
clock_process = Popen([
"java",
"-cp",
f"target/{jar_name}",
"org.lbee.instrumentation.clock.ServerClock",
"6666"])
# Wait the server to run, if not some manager might start
# running before the server, leading to an error
# This behavior might be interesting for trace validation
time.sleep(2)
print("--- Run Server client ---")
duration = 1
args = [
"java",
"-cp",
f"target/{jar_name}",
"org.lbee.StartAgent",
"localhost", "6869", "NONE", f"{server}",f"{duration}"]
server_process = Popen(args)
print("--- Run Client clients ---")
client_processes = []
duration = 1
for client in clients:
args = [
"java",
"-cp",
f"target/{jar_name}",
"org.lbee.StartAgent",
"localhost", "6869", f"{client}", f"{server}", f"{duration}"]
client_process = Popen(args)
client_processes.append(client_process)
# Wait for all clients to be finished
server_process.wait()
for client_process in client_processes:
client_process.wait()
# terminate
network_process.terminate()
server_process.terminate()
for client_process in client_processes:
client_process.terminate()
# Kill server
os.kill(network_process.pid, signal.SIGINT)
os.kill(clock_process.pid, signal.SIGINT)
if __name__ == "__main__":
# Read program args
parser = argparse.ArgumentParser(description="")
parser.add_argument('--config', type=str, required=False,
default="conf.ndjson", help="Config file")
args = parser.parse_args()
# Read config and run
config = read_json(args.config)
clients = config[0]["Clients"]
server = config[1]["ServerID"]
print(f"Server: {server}")
print(f"Clients: {clients}")
run(clients, server)