def testPickleWithoutValue(self):
     for mess in self.messagesNoValue:
         assert(isinstance(mess,MessDef.NetMess))
         pickled = mess.pickleMe()
         #print(pickled)
         depickled = MessDef.dePickle(pickled)
         assert(depickled == mess)
    def testPrepare(self):
        ## client 0 will send a prepare message to client 0,1. Should get a promise response:
        pm = self.messages["PREPARE"]
        pm.recipient = self.recips[1]
        pm.sender = self.senders[0]
        pm.m = 1

        for acid in self.acceptors:
            acceptor = self.acceptors[acid]
            acceptor.setDaemon(True)
            acceptor.start()
        self.srvr.inQ(self.senders[0]).put((pm,self.recips[0]))

        ##wait for acceptor to get prepare
        self.pauseWork()

        ##check that the outQ has a promise message addressed to the sender

        rm = self.srvr.outQ(self.senders[0]).get()

        dest = rm[1]
        mes = MessDef.dePickle(rm[0])
        assert(dest == self.senders[0])
        assert(mes == mes)

        ##Check that the acceptor has the right promise value:
        assert(self.acceptors[self.senders[0]].promiseN == pm.m)

        ##Test sticky

        pm.m = 0

        self.srvr.inQ(self.senders[0]).put((pm,self.recips[0]))
        rmt = self.srvr.outQ(self.senders[0]).get()

        nck = MessDef.dePickle(rmt[0])
        assert(isinstance(nck,MessDef.NetMess))
        assert(nck.messType == "NACK")
        self.endWork()
    def testAccept(self):
        import pCalendar.UserCal

        for acid in self.acceptors:
            acceptor = self.acceptors[acid]
            acceptor.setDaemon(True)
            acceptor.start()

        iq = self.srvr.inQ(self.senders[0])
        oq = self.srvr.outQ(self.senders[0])
        acc1 = self.acceptors[self.senders[0]]

        pm = self.messages["PREPARE"]
        pm.recipient = self.recips[0]
        pm.sender = self.senders[1]
        pm.m = 1

        iq.put(pm)
        self.pauseWork()
        response = oq.get()

        am = self.messages["ACCEPT"]
        am.recipient = self.recips[1]
        assert (isinstance(am,MessDef.NetMess))
        am.accNum = 1
        am.accVal = self.calendars[0]

        iq.put(am)
        self.pauseWork()
        print("Accept messages sent")
        response= MessDef.dePickle(oq.get())
        assert(isinstance(response,MessDef.NetMess))
        assert(response.messType == "ACCEPTED")
        assert(isinstance(response.accVal,pCalendar.UserCal.Calendar))
        assert(response.accVal == am.accVal)
        self.endWork()