コード例 #1
0
    def testSave(self):
        import datetime
        from numpy import random as random
        import itertools
        from pCalendar.UserCal import CalEvent,Calendar

        cald = Calendar("UnitTester")
        cald.events = self.events
        #create a fresh learner:
        learnTst = Learner("unitTest-" + str( random.randint(1,10000)))
        message = MessDef.NetMess(messType="COMMIT", recipient="127.0.0.1", accNum=1, accVal = cald)
        learnTst.gotCommit(message)
        self.createdFiles.append(learnTst.fn)
        ## check that file exists now:
        assert(os.path.isfile(learnTst.fn))
コード例 #2
0
    def testLoad(self):
        import datetime
        from numpy import random as random
        import itertools
        from pCalendar.UserCal import CalEvent,Calendar
        cald = Calendar("UnitTester")
        cald.events = self.events
        #create a fresh learner:
        message = MessDef.NetMess(messType="COMMIT", recipient="127.0.0.1", accNum=1, accVal = cald)
        lrnID  = "unitTest-" + str( random.randint(1,10000))
        learnTst = Learner(lrnID)
        learnTst.gotCommit(message)

        loadLrn = Learner(lrnID)
        self.createdFiles.append(learnTst.fn)
        self.createdFiles.append(loadLrn.fn)
        print("OP is {}, learned is {}".format(cald,loadLrn.currentCal) )
        assert(cald == loadLrn.currentCal)
コード例 #3
0
    def setUp(self):
        from pCalendar.UserCal import CalEvent,Calendar
        from numpy import random as rnd
        self.messageTypes = ["PROPOSE", "PROMISE", "ACCEPT", "COMMIT", "ACK"]
        self.recips = ["127.0.0.1", "192.168.1.1"]
        self.senders = ["127.0.0.1", "192.168.1.1"]
        self.m = [1,2,3,4,5]
        self.accNums = [1,2,3,4,5]

        createCE(self)
        self.cals = []
        for i in range(0,5):
            cal = Calendar("UnitTester" + str(i))
            rnd.shuffle(self.events)
            cal.events = self.events
            self.cals.append(cal)

        ##create some messages
        self.messagesWithValue = []
        self.messagesNoValue = []
        for i in range(0,5):

            self.messagesWithValue.append(self.createMessage(""))
            self.messagesNoValue.append(self.createMessage(None))
コード例 #4
0
    def setUp(self):
        import datetime
        from numpy import random as random
        import itertools
        from pCalendar.UserCal import CalEvent,Calendar

        self.numAcceptors = 2
        numAcceptors = self.numAcceptors


        startDates = []
        endDates = []

        fns = ["bob", "john", "ringo", "Paul", "Conan", "Mike"]
        lns = ["Mario", "Luigi", "Walker", "LaQuarius", "Edmond", "Aadams"]
        rnks = ["pleb", "midLevel", "CEO"]

        self.events = []
        fullNames = [fns, lns]
        self.employeeList = []

        for list in itertools.product(*fullNames):
            self.employeeList.append(list)
        # going to use about 50% overlap events for test:
        startD = 1
        startE = 4
        for _ in range((int(len(self.employeeList) / 2))):
            startDates.append(datetime.datetime(2016, 1, startD,
                                                random.randint(1, 10),
                                                random.randint(1, 5),
                                                random.randint(1, 50)))
            endDates.append(datetime.datetime(2016, 1, startE,
                                              random.randint(1, 10),
                                              random.randint(1, 5),
                                              random.randint(1, 50)))
            startD += 1
            startE += 1
        for _ in range((len(self.employeeList))):
            sd = (self.wrd())
            startDates.append(sd)
            endDates.append(sd + datetime.timedelta(5))

        for i in range(len(self.employeeList)):
            self.events.append(CalEvent(startDates[i], endDates[i], self.employeeList[i][0],
                                        self.employeeList[i][1], random.choice(rnks), "NONE"))
        self.startDates = startDates
        self.endDates = endDates
        self.createdFiles = []
        self.calendars = []
        for i in range(1,10):
            cal = Calendar(str(i))
            np.random.shuffle( self.events)
            cal.cal = self.events
            self.calendars.append(cal)
        ##Messages
        self.messageTypes = ["PROPOSE", "PROMISE", "ACCEPT", "COMMIT", "ACK"]


        self.recips =self.getRvrs() # [ipa() for i in range(0,numAcceptors)]
        self.senders = copy.deepcopy(self.recips)
        self.m = [1,2,3,4,5]
        self.accNums = [1,2,3,4,5]

        r = self.recips[0]
        s = self.senders[0]


        self.messages = {}
        self.messages["PREPARE"] = MessDef.NetMess(messType="PREPARE",recipient=self.recips[0],sender=self.recips[1])
        self.messages["ACCEPT"] = MessDef.NetMess(messType="ACCEPT", recipient=self.recips[0],sender=self.recips[1])
        self.messages["COMMIT"] = MessDef.NetMess(messType="COMMIT", recipient=self.recips[0],sender=self.recips[1])

        self.srvr = FakeServer(self.recips)
        self.acceptors = {}
        for client in self.recips:
            self.acceptors[client] = paxos.Acceptor.Acceptor(outQ=self.srvr.outQ(client), inQ=self.srvr.inQ(client),
                                                             thisIP=client)