def test_receive_membership_message(self): if not 'MembershipInfo' in dir(spread): return info = spread.MembershipInfo() self.join() # mbox self.join() message groups = spread.GroupList() self.mbox.receive(self.message, groups) self.assertTrue(self.message.is_membership()) self.assertEqual(MailboxTest.TestGroupName, self.message.sender()) self.message.get_membership_info(info) self.assertTrue(info.caused_by_join()) self.assertEqual(self.mbox.private_group(), info.changed_member()) mbox_group = spread.GroupList() local_members = spread.GroupList() all_members = spread.GroupList() mbox_group.add(self.mbox.private_group()) info.get_local_members(local_members) info.get_all_members(all_members) self.assertEqual(mbox_group, local_members) self.assertEqual(mbox_group, all_members) self.assertEqual(groups, all_members) # mbox self.join() message self.mbox.receive(self.message) self.assertTrue(self.message.is_membership()) self.assertEqual(MailboxTest.TestGroupName2, self.message.sender()) # rmbox self.join() message self.rmbox.join(MailboxTest.TestGroupName2) self.mbox.receive(self.message) self.assertTrue(self.message.is_membership()) self.assertEqual(MailboxTest.TestGroupName2, self.message.sender()) # rmbox self.leave() message self.rmbox.leave(MailboxTest.TestGroupName2) self.mbox.receive(self.message) self.assertTrue(self.message.is_membership()) self.message.get_membership_info(info) self.assertTrue(info.caused_by_leave()) self.assertEqual(MailboxTest.TestGroupName2, self.message.sender()) self.leave()
def set_up_spread_peer(): ''' Set up Spread utility for Spread peer @return Tuple of (Spread mailbox, Spread message object for sending, Spread message object for receiving, group list of the mailbox) ''' # Register the signal timeout handler signal.signal(signal.SIGALRM, timeout_handler) group_list = spread.GroupList() group_list.add(params.SPREAD_GROUP_NAME) try: mbox = spread.Mailbox(params.SPREAD_DAEMON_PORT, "vyan1_mbox", False, 0) except spread.Error as error: error._print() raise error mbox.join(params.SPREAD_GROUP_NAME) mbox.add_group(params.SPREAD_GROUP_NAME) send_MSG = spread.Message() rcv_MSG = spread.Message() service = spread.Message.Reliable | spread.Message.SelfDiscard send_MSG.set_service(service) return (mbox, send_MSG, rcv_MSG, group_list)
def test_receive_message(self): data = "foobar" groups = spread.GroupList() padding = spread.Message() self.mbox.clear_groups() self.mbox.clear_message_parts() self.mbox.add_group(self.rmbox.private_group()) self.mbox.add_message_part(data) self.mbox.send() self.rmbox.clear_groups() self.rmbox.clear_message_parts() self.rmbox.add_message_part(self.message) self.rmbox.add_message_part(padding) padding.resize(padding.capacity()) self.assertTrue(padding.size() > 0) bytes = self.rmbox.receive() self.rmbox.copy_groups(groups) self.assertEqual(0, padding.size()) self.assertEqual(len(data) + 1, bytes) self.assertEqual(len(data) + 1, self.message.size()) self.assertEqual(data, self.message.read(len(data) + 1)) self.assertEqual(self.rmbox.private_group(), groups.group(0)) self.assertEqual(self.mbox.private_group(), self.message.sender())
def test_copy(self): g2 = spread.GroupList() g2.add("foo") self.assertNotEqual(g2, self.groups) self.groups.copy(g2) self.assertEqual("foo", self.groups.group(0)) self.assertEqual(g2, self.groups)
def test_group_send(self): groups = spread.GroupList() groups.add(MailboxTest.TestGroupName) groups.add(MailboxTest.TestGroupName2) def send(s,g): self.message.clear() self.message.write(s) self.mbox.send(self.message, g) self.join() send("test_group_send", groups) send("test_group_send2", groups) self.leave()
def test_scatter_group_send(self): groups = spread.GroupList() sm = spread.ScatterMessage() m = spread.Message() groups.add(MailboxTest.TestGroupName) groups.add(MailboxTest.TestGroupName2) self.join() self.message.write("test_scatter_group_send") m.write("test_scatter_group_send2") sm.add(self.message) sm.add(m) self.mbox.send(sm, groups) self.leave()
def test_add_group_list(self): self.groups.add("foo") self.groups.add("bar") g = spread.GroupList() g.add("foobar") g.add("blah") g.add("blargh") self.groups.add(g) self.assertEqual(5, self.groups.size()) self.assertEqual("blargh", self.groups.group(4)) self.assertEqual("bar", self.groups.group(1)) self.assertNotEqual(g, self.groups) self.groups.clear() self.groups.add(g) self.assertEqual(g, self.groups)
import sys import spread group_name = "JHU_VDL" group_list = spread.GroupList() group_list.add(group_name) try: mbox = spread.Mailbox("4803", "", False, 0) except spread.Error as error: error._print() raise error message = spread.Message() rcv_msg = spread.Message() data = "foobar" service = spread.Message.Reliable | spread.Message.SelfDiscard #message.set_service(service) mbox.clear_groups() mbox.clear_message_parts() mbox.join(group_name) # mbox.add_group(group_name) message.write(data) mbox.send(message) while mbox.poll() == 0: pass print 'poll ', mbox.poll() #mbox.send(message, group_list)
def setUp(self): self.groups = spread.GroupList()