def test_coord(context): queue = Queue(context) c = Coordinator(queue) context.create_thread(c.run).start() completed = Event(context) queue.put(Request(1, 0, 100, completed)) event_loop(context.shared) assert completed.notify_count == 1
def init(): completed = Event(context) request = Thread(context, lambda: obj_store_read_client(context, 1, 10 * 1024, 1024, completed), name="service") request.start() context.wait(events=[completed])
def seq_read_client(context, queue, file_id, length, read_size, timings, client_completed): for i in range(0, length, read_size): context.log("request {}".format(i)) completion_event = Event(context) start = context.now() queue.put(Request(file_id, i, i + length, completion_event)) context.wait(events=[completion_event]) elapsed = context.now() - start timings.append(elapsed) client_completed.notify()
def obj_store_read_client(context, file_id, length, read_size, client_completed): cancel_event = Event(context) result_queue = Queue(context) execute_obj_read(context, ObjectReadReq(file_id, 0, length), cancel_event, result_queue) bytes_read = 0 while True: result = result_queue.take() if result.length == 0: break bytes_read += result.length client_completed.notify()
def test_event(): shared = SharedState() context = Context(shared) event = Event(context) def background_notify(): context.wait(1) event.notify() def main(): context.wait(10) assert context.now() == 1 main_thread = context.create_thread(main) main_thread.start() context.create_thread(background_notify).start() event_loop(shared)
def init(): context.log("starting...") queue = Queue(context) service = Thread(context, lambda: mock_service_main_loop(context, queue), name="service") service.start() context.log("started service") timings = [] completed = Event(context) client = Thread(context, lambda: seq_read_client(context, queue, 1, 1024 * 100, 1024 * 10, timings, completed), name="client") client.start() context.log("started client") context.wait(events=[completed]) context.log("mean elapsed: {} (count={})".format( sum(timings) / len(timings), len(timings)))
def __init__(self, context): self.read_length = 1024 # number of bytes object read request returns at a time self.time_till_first_byte = 0.4 self.bytes_per_sec = 50 * 1024 * 1024 self.transfer_rate_changed = Event(context)
def __init__(self): self.transfer_rate_changed = Event()