Executes a query to aggregate the measurements after the simulation is over.
:param start_time: start time of simulation (in nanoseconds)
:param end_time: end time of simulation (in nanoseconds)
:param sample_period: sample period for grouping (in minutes)
:return:
"""
query='SELECT mean("delay") as "Dnet", mean("response_time") as "Dresponse_time" INTO "E2EMetrics"."autogen"."e2e" from "E2EMetrics"."autogen"."net", "E2EMetrics"."autogen"."service" WHERE time >= {0} and time <= {1} GROUP BY time({2}m) fill(previous)'.format(start_time,end_time,sample_period)
self.db_client.query(query=query)
defrun(self):
"""
Runs the simulation.
"""
start_time=1523779200000000# 15/04/2018, 09:00:00 in nanoseconds
sim_time=start_time
mean_delay_seconds_net=1# initial mean network delay
mean_delay_seconds_media=10# initial mean media service delay
sample_period_net=2# sample period for reporting network delays (measured in minutes)
sample_period_media=5# sample period for reporting media service delays (measured in minutes)
foriinrange(0,self.SIMULATION_LENGTH):
# net delay
ifi%sample_period_net==0:
point=[{"measurement":"net",
"fields":{
"delay":mean_delay_seconds_net
},
"time":sim_time
}]
self.db_client.write_points(point)
# increase the delay by 1 every sample
mean_delay_seconds_net+=1
# service response time
ifi%sample_period_media==0:
point=[{"measurement":"service",
"fields":{
"response_time":mean_delay_seconds_media
},
"time":sim_time
}]
self.db_client.write_points(point)
# increase the delay by 20 every sample
mean_delay_seconds_media+=20
# increase the time by one minute
sim_time+=self.MINUTE
end_time=sim_time-self.MINUTE# decrement one minute to get the last time a measurement have been reported
# test the error attribute of the result is None, that is no error is returned from executing the DB query
assertquery_result.errorisNone,"An error was encountered while executing query {0}.".format(query)
# get the dictionary of result points; the next() function just gets the first element of the query results generator (we only expect one item in the generator)
actual_result=next(query_result.get_points())
assertexpected_result==actual_result,"E2E Simulation test failure"
print("Successfully passed test for the following query: {0}".format(query))