def test_downed_recipient_cancels_the_hub_sender_during_chunked_request( self): port = _free_port() hub = junction.Hub(("127.0.0.1", port), []) triggered = [False] @hub.accept_rpc('service', 0, 0, 'method') def handle(chunks): for item in chunks: pass return "all done" hub.start() port2 = _free_port() hub2 = junction.Hub(("127.0.0.1", port2), [("127.0.0.1", port)]) hub2.start() hub2.wait_connected() def gen(): try: while 1: yield None backend.pause_for(TIMEOUT) finally: triggered[0] = True rpc = hub2.send_rpc('service', 0, 'method', (gen(), )) hub = [hub] backend.schedule_in(TIMEOUT * 4, self.kill_hub, args=(hub, )) backend.pause_for(TIMEOUT * 5) assert triggered[0]
def test_unrelated_rpcs_are_unaffected(self): global PORT hub = junction.Hub(("127.0.0.1", PORT), []) PORT += 2 @hub.accept_rpc('service', 0, 0, 'method') def handle(): backend.pause_for(TIMEOUT) return 1 hub.start() peer = junction.Hub(("127.0.0.1", PORT), [hub.addr]) PORT += 2 peer.start() peer.wait_connected() client = junction.Client(hub.addr) client.connect() client.wait_connected() client = [client] backend.schedule(self.kill_client, (client, )) # hub does a self-rpc during which the client connection goes away result = peer.rpc('service', 0, 'method') self.assertEqual(result, 1)
def test_downed_recipient_cancels_the_hub_sender_during_chunked_publish( self): global PORT hub = junction.Hub(("127.0.0.1", PORT), []) PORT += 2 triggered = [False] @hub.accept_publish('service', 0, 0, 'method') def handle(chunks): for item in chunks: pass hub.start() hub2 = junction.Hub(("127.0.0.1", PORT), [("127.0.0.1", PORT - 2)]) PORT += 2 hub2.start() hub2.wait_connected() def gen(): try: while 1: yield None backend.pause_for(TIMEOUT) finally: triggered[0] = True hub2.publish('service', 0, 'method', (gen(), )) hub = [hub] backend.schedule_in(TIMEOUT * 4, self.kill_hub, args=(hub, )) backend.pause_for(TIMEOUT * 5) assert triggered[0]
def test_downed_hub_during_chunked_publish_terminates_correctly(self): global PORT hub = junction.Hub(("127.0.0.1", PORT), []) PORT += 2 l = [] ev = backend.Event() @hub.accept_publish('service', 0, 0, 'method') def handle(x): for item in x: l.append(item) ev.set() hub.start() hub2 = junction.Hub(("127.0.0.1", PORT), [("127.0.0.1", PORT - 2)]) PORT += 2 hub2.start() hub2.wait_connected() hub2 = [hub2] def gen(): yield 1 yield 2 self.kill_hub(hub2) hub2[0].publish('service', 0, 'method', (gen(), )) ev.wait(TIMEOUT) self.assertEqual(l[:2], [1, 2]) self.assertEqual(len(l), 3, l) self.assertIsInstance(l[-1], junction.errors.LostConnection)
def test_unrelated_self_rpcs_are_unaffected(self): global PORT hub = junction.Hub(("127.0.0.1", PORT), []) PORT += 2 @hub.accept_rpc('service', 0, 0, 'method') def handle(): backend.pause_for(TIMEOUT) return 1 hub.start() client = junction.Client(hub.addr) client.connect() client.wait_connected() client = [client] @backend.schedule def kill_client(): # so it'll get GC'd cli = client.pop() cli._peer.sock.close() # hub does a self-rpc during which the client connection goes away result = hub.rpc('service', 0, 'method') self.assertEqual(result, 1)
def test_downed_hub_during_chunk_pub_to_client_terminates_correctly(self): global PORT hub = junction.Hub(("127.0.0.1", PORT), []) PORT += 2 l = [] ev = greenhouse.Event() @hub.accept_publish('service', 0, 0, 'method') def handle(x): for item in x: l.append(item) ev.set() hub.start() client = junction.Client(("127.0.0.1", PORT - 2)) PORT += 2 client.connect() client.wait_connected() client = [client] def gen(): yield 1 yield 2 self.kill_client(client) client[0].publish('service', 0, 'method', (gen(),)) ev.wait(TIMEOUT) self.assertEqual(l[:2], [1,2]) self.assertEqual(len(l), 3) self.assertIsInstance(l[-1], junction.errors.LostConnection)
def main(environ, argv): greenhouse.global_exception_handler(traceback.print_exception) junction.configure_logging(level=1) hub = junction.Hub(("", 9057), [("", 9056)]) hub.start() greenhouse.Event().wait()
def main(environ, argv): greenhouse.global_exception_handler(traceback.print_exception) junction.configure_logging(level=1) hub = junction.Hub(("", 9056), []) hub.accept_rpc('service', 0, 0, 'echostream', handle) hub.start() greenhouse.Event().wait()
def test_unrelated_client_chunked_publishes_are_unrelated(self): global PORT hub = junction.Hub(("127.0.0.1", PORT), []) PORT += 2 d = {} @hub.accept_publish('service', 0, 0, 'method') def handle(x, source): for item in x: d.setdefault(source, 0) d[source] += 1 hub.start() c1 = junction.Client(("127.0.0.1", PORT - 2)) c1.connect() c1.wait_connected() c2 = junction.Client(("127.0.0.1", PORT - 2)) c2.connect() c2.wait_connected() def gen(): backend.pause_for(TIMEOUT) yield None backend.pause_for(TIMEOUT) yield None backend.pause_for(TIMEOUT) yield None backend.schedule(c1.publish, args=('service', 0, 'method'), kwargs={ 'args': (gen(), ), 'kwargs': { 'source': 'a' } }) backend.schedule(c2.publish, args=('service', 0, 'method'), kwargs={ 'args': (gen(), ), 'kwargs': { 'source': 'b' } }) backend.pause_for(TIMEOUT) c2 = [c2] self.kill_client(c2) backend.pause_for(TIMEOUT) backend.pause_for(TIMEOUT) backend.pause_for(TIMEOUT) self.assertEquals(d, {'a': 3, 'b': 1})
def build_sender(self): self.relayer = junction.Hub(("127.0.0.1", self.peer.addr[1] + 1), [self.peer.addr]) self.relayer.start() self.connection = self.relayer self.sender = junction.Client(self.relayer.addr) self.sender.connect() self.relayer.wait_connected() self.sender.wait_connected()
def main(): hub = junction.Hub(("localhost", PORT), [("localhost", SERVICE_PORT)]) hub.start() greenhouse.schedule(greenhouse.run_backdoor, args=(("localhost", PORT + 1), { 'hub': hub })) try: greenhouse.Event().wait() except KeyboardInterrupt: pass
def main(): hub = junction.Hub((HOST, PORT), [(RELAY_HOST, RELAY_PORT)]) hub.start() hub.accept_rpc(SERVICE, 0, 0, "echo", handler) greenhouse.schedule(greenhouse.run_backdoor, args=((BACKHOST, BACKPORT), { 'hub': hub })) try: greenhouse.Event().wait() except KeyboardInterrupt: pass
def main(): hub = junction.Hub(("localhost", PORT), [("localhost", MIDDLEMAN_PORT)]) hub.start() hub.accept_rpc(WAIT_SERVICE, 0, 0, "wait", wait) greenhouse.schedule(greenhouse.run_backdoor, args=(("localhost", PORT + 1), { 'hub': hub })) try: greenhouse.Event().wait() except KeyboardInterrupt: pass
def main(environ, argv): greenhouse.global_exception_handler(traceback.print_exception) junction.configure_logging(level=1) port = 9056 if argv[1:] and argv[1] == 'relay': port += 1 #client = junction.Client(("", port)) #client.connect() client = junction.Hub(("", port + 1), [("", port)]) client.start() client.wait_connected() for line in client.rpc('service', 0, 'echostream', (gen_input(), )): print 'line:', line
def create_hub(self, peers=None): peer = junction.Hub(("127.0.0.1", _free_port()), peers or []) peer.start() return peer
code = type(load_func.func_code)(*mummy.loads(s)) func.func_code = code return func if __name__ == '__main__': greenhouse.global_exception_handler(traceback.print_exception) level = 1 if sys.argv[1] == 'client': level = logging.ERROR if '-v' in sys.argv: level = 1 junction.configure_logging(level=level) if sys.argv[1] == "mapper": hub = junction.Hub(("", 9090), [("", 9091), ("", 9092)]) hub.start() mapper = Mapper(hub, 'map-reduce', 1) greenhouse.run_backdoor(("", 8090), locals()) elif sys.argv[1] == "reducer": hub = junction.Hub(("", 9091), [("", 9090), ("", 9092)]) hub.start() reducer = Reducer(hub, 'map-reduce', 0, 0) greenhouse.run_backdoor(("", 8091), locals()) elif sys.argv[1] == "coordinator": hub = junction.Hub(("", 9092), [("", 9090), ("", 9091)]) hub.start() coord = Coordinator(hub, 'map-reduce', 0, 0, 1) greenhouse.run_backdoor(("", 8092), locals()) elif sys.argv[1] == "client": cli = junction.Client(("", 9092)) # only need the coordinator
def build_sender(self): self.sender = junction.Hub(("127.0.0.1", 8000), [self.peer.addr]) self.sender.start() self.sender.wait_connected()
def create_hub(self, peers=None): global PORT peer = junction.Hub(("127.0.0.1", PORT), peers or []) PORT += 2 peer.start() return peer