def test_run_read(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() worker = loop.create_worker_for_socket(left) # callback for ioworker to record receiving self.received = None def r(worker): self.received = worker.peek_receive_buf() worker.set_receive_handler(r) # 'start' the run (dark generator magic here). Does not actually execute run, but 'yield' a generator g = loop.run() # g.next() will call it, and get as far as the 'yield select' select = g.next() # send data on other socket half right.send("hallo") # now we emulate the return value of the select ([rlist],[wlist], [elist]) g.send(([worker], [], [])) # that should result in the socket being red the data being handed # to the ioworker, the callback being called. Everybody happy. self.assertEquals(self.received, "hallo")
def test_run_read(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() worker = loop.create_worker_for_socket(left) # callback for ioworker to record receiving self.received = None def r(worker): self.received = worker.peek_receive_buf() worker.set_receive_handler(r) # 'start' the run (dark generator magic here). Does not actually execute run, but 'yield' a generator g = loop.run() # g.next() will call it, and get as far as the 'yield select' select = g.next() # send data on other socket half right.send("hallo") # now we emulate the return value of the select ([rlist],[wlist], [elist]) g.send(([worker], [], [])) # that should result in the socket being red the data being handed # to the ioworker, the callback being called. Everybody happy. self.assertEquals(self.received, "hallo")
def test_run_close(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() worker = loop.create_worker_for_socket(left) self.assertTrue(worker in loop.workers) worker.close() # This causes the worker to be scheduled to be closed -- it also # calls pinger.ping(). However, the Select task won't receive the ping # Until after this method has completed! Thus, we only test whether # worker has been added to the pending close queue self.assertTrue(worker in loop.pending_worker_closes)
def test_run_close(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() worker = loop.create_worker_for_socket(left) self.assertFalse(worker in loop._workers, "Should not add to _workers yet, until we start up the loop") self.assertTrue(loop._pending_commands.qsize() == 1, "Should have added pending create() command") worker.close() # This causes the worker to be scheduled to be closed -- it also # calls pinger.ping(). However, the Select task won't receive the ping # Until after this method has completed! Thus, we only test whether # worker has been added to the pending close queue self.assertTrue(loop._pending_commands.qsize() == 2, "Should have added pending close() command")
def test_run_write(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() worker = loop.create_worker_for_socket(left) worker.send("heppo") # 'start' the run (dark generator magic here). Does not actually execute run, but 'yield' a generator g = loop.run() # g.next() will call it, and get as far as the 'yield select' select = g.next() # now we emulate the return value of the select ([rlist],[wlist], [elist]) g.send(([], [worker], [])) # that should result in the stuff being sent on the socket self.assertEqual(right.recv(), "heppo")
def test_run_write(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() worker = loop.create_worker_for_socket(left) worker.send("heppo") # 'start' the run (dark generator magic here). Does not actually execute run, but 'yield' a generator g = loop.run() # g.next() will call it, and get as far as the 'yield select' select = g.next() # now we emulate the return value of the select ([rlist],[wlist], [elist]) g.send(([], [worker], [])) # that should result in the stuff being sent on the socket self.assertEqual(right.recv(), "heppo")
def test_run_close(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() worker = loop.create_worker_for_socket(left) self.assertFalse( worker in loop._workers, "Should not add to _workers yet, until we start up the loop") self.assertTrue(loop._pending_commands.qsize() == 1, "Should have added pending create() command") worker.close() # This causes the worker to be scheduled to be closed -- it also # calls pinger.ping(). However, the Select task won't receive the ping # Until after this method has completed! Thus, we only test whether # worker has been added to the pending close queue self.assertTrue(loop._pending_commands.qsize() == 2, "Should have added pending close() command")
def test_basic(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() loop.create_worker_for_socket(left)
for (i, c) in enumerate(controllers): command_line_args = map(lambda(x): string.replace(x, "__port__", str(c.port)), map(lambda(x): string.replace(x, "__address__", str(c.address)), c.cmdline)) print command_line_args child = popen_filtered("c%d" % i, command_line_args) logger.info("Launched controller c%d: %s [PID %d]" % (i, " ".join(command_line_args), child.pid)) child_processes.append(child) io_loop = RecocoIOLoop() scheduler = Scheduler(daemon=True, useEpoll=False) scheduler.schedule(io_loop) #if hasattr(config, 'switches'): # pass create_worker = lambda(socket): DeferredIOWorker(io_loop.create_worker_for_socket(socket), scheduler.callLater) # TODO: need a better way to choose FatTree vs. Mesh vs. whatever # Also, abusing the "num_switches" command line arg -> num_pods (panel, switch_impls, network_links, hosts, access_links) = topology_generator.populate_fat_tree(controllers, create_worker, num_pods=args.num_switches) \ if args.fattree else \ topology_generator.populate(controllers, create_worker, num_switches=args.num_switches) # For instrumenting the controller # TODO: This ugly hack has to be cleaned up ASAP ASAP
def test_basic(self): loop = RecocoIOLoop() (left, right) = MockSocket.pair() loop.create_worker_for_socket(left)