def get_status(sock, server, node, uinput): what = uinput[0] api = "handle_call" status= pyerl.mk_atom("status") if what == 'node': value = uinput[-1] val = pyerl.mk_atom(value) elif what == 'guid': value = uinput[-1] val = pyerl.mk_int(int(value)) elif what == 'pid': rnode = uinput[1] # remote node pid = uinput[2] # remote pid nodename = pyerl.mk_atom(rnode) ppid = pyerl.mk_string(pid) val = pyerl.mk_tuple((nodename, ppid)) else: raise Exception('Unknown message: %s' % what) what = pyerl.mk_atom(what) pid = pyerl.mk_pid("node", 1, 2, 3) state = pyerl.mk_atom("atom") # passed state to server is irrelevant in this call tup = pyerl.mk_tuple((status, what, val)) args = pyerl.mk_list([tup, pid, state]) eterm = pyerl.rpc(sock, server, api, args) return eterm
def test_cons(self): atom1 = pyerl.mk_atom("atom1") atom2 = pyerl.mk_atom("atom2") list = pyerl.mk_list([atom1]) eterm = pyerl.cons(atom2, list) self.assertEqual(eterm.type, pyerl.CONS); self.assertEqual(eterm.is_cons(), True); self.assertEqual(eterm.is_list(), True); self.assertEqual(str(eterm), "[atom2, atom1]");
def test_black_box(sock, server, icmd, idir): api = "handle_call" atom = pyerl.mk_atom("process") cmd = pyerl.mk_string(icmd) name = pyerl.mk_string(idir) tup = pyerl.mk_tuple((atom, cmd, name)) pid = pyerl.mk_pid("node", 1, 2, 3) state = pyerl.mk_atom("atom") # passed state to server is irrelevant in this call args = pyerl.mk_list([tup, pid, state]) eterm = pyerl.rpc(sock, server, api, args) return eterm
def test_mk_list(self): atom = eterm = pyerl.mk_atom("atom") integer = eterm = pyerl.mk_int(-1) string = eterm = pyerl.mk_string("string") eterm = pyerl.mk_tuple((atom, integer, string)) self.assertEqual(eterm.is_tuple(), True); self.assertEqual(eterm.type, pyerl.TUPLE); self.assertEqual(str(eterm), "{atom, -1, \"string\"}");
def test_mk_list(self): atom = eterm = pyerl.mk_atom("atom") integer = eterm = pyerl.mk_int(-1) string = eterm = pyerl.mk_string("string") eterm = pyerl.mk_list([atom, integer, string]) self.assertEqual(eterm.is_list(), True); self.assertEqual(eterm.is_cons(), True); self.assertEqual(eterm.type, pyerl.LIST); self.assertEqual(str(eterm), "[atom, -1, \"string\"]");
def test_rpc(self): host = "localhost" name = "test" node = name + "@" + host cookie = "TESTCOOKIE" ret = pyerl.connect_xinit(host, name, node, "127.0.0.1", cookie, 1) self.assertEqual(ret, 1); retry = 0 while True: time.sleep(1) sock = pyerl.xconnect("127.0.0.1", "node1") if sock > 0: break if retry > 3: self.fail() retry += 1 self.assertEqual(sock > 0, True) atom = pyerl.mk_atom("ping") args = pyerl.mk_list([atom]); eterm = pyerl.rpc(sock, "pingpong", "ping", args); ret = pyerl.close_connection(sock); self.assertEqual(ret, 0); self.assertEqual(eterm.type, pyerl.ATOM); self.assertEqual(eterm.is_atom(), True); self.assertEqual(str(eterm), "pong");
def test_rpc(self): host = "localhost" name = "test" node = name + "@" + host cookie = "TESTCOOKIE" ret = pyerl.connect_xinit(host, name, node, "127.0.0.1", cookie, 1) self.assertEqual(ret, 1) retry = 0 while True: time.sleep(1) sock = pyerl.xconnect("127.0.0.1", "node1") if sock > 0: break if retry > 3: self.fail() retry += 1 self.assertEqual(sock > 0, True) atom = pyerl.mk_atom("ping") args = pyerl.mk_list([atom]) eterm = pyerl.rpc(sock, "pingpong", "ping", args) ret = pyerl.close_connection(sock) self.assertEqual(ret, 0) self.assertEqual(eterm.type, pyerl.ATOM) self.assertEqual(eterm.is_atom(), True) self.assertEqual(str(eterm), "pong")
def test_mk_atom(self): eterm = pyerl.mk_atom("atom") self.assertEqual(eterm.type, pyerl.ATOM); self.assertEqual(eterm.is_atom(), True); self.assertEqual(str(eterm), "atom");
def test_copy_term(self): atom = pyerl.mk_atom("atom") eterm = pyerl.copy_term(atom) self.assertEqual(eterm.type, pyerl.ATOM); self.assertEqual(eterm.is_atom(), True); self.assertEqual(str(eterm), "atom");