Ejemplo n.º 1
0
    def test12Add_UpdateRequest_FetchAllCompleteTasks(self):

        fibDataDB = initializeFibDataDB(self.testName)
        finishedDate = nowInSeconds()
        startedDate = finishedDate - 5
        fd = FibDataRequest(
            None, {
                "request_id": "foo1",
                "fib_id": 3,
                "fib_value": 3,
                "started_date": startedDate,
                "finished_date": finishedDate
            })

        fibDataDB.addRequest(fd)
        fdArr = fibDataDB.getRequests(isPending=False)

        self.assertTrue(len(fdArr) == 1)

        startedDate = nowInSeconds()

        fd = FibDataRequest(
            None, {
                "request_id": "foo2",
                "fib_id": 3,
                "fib_value": 3,
                "started_date": startedDate
            })

        fibDataDB.addRequest(fd)
        fdArr = fibDataDB.getRequests(isPending=False)

        self.assertTrue(len(fdArr) == 1)
    def testComplete(self):

        try:
            fibDataDB = self.initializeFibDataDB(self.testName)
            fibData = FibDataRequest(None, {
                "worker_id": "abcd",
                "fib_id": 3,
                "fib_value": 2
            })
            testFD = fibDataDB.addRequest(fibData)
            fibDataDB.updateRequest(testFD)

            fibData = FibDataRequest(None, {
                "worker_id": "efgh",
                "fib_id": 3,
                "fib_value": 2
            })
            testFD = fibDataDB.addRequest(fibData)
            fibDataDB.updateRequest(testFD)

            fibData = FibDataRequest(None, {
                "worker_id": "efgh",
                "fib_id": 4,
                "fib_value": 3
            })
            testFD = fibDataDB.addRequest(fibData)

            responseHandler = ResponseHandler(uuid.uuid1(), fibDataDB)

            response = responseHandler.getComplete()

            self.assertTrue(response != None)

            parsedResponses = json.loads(response)

            self.assertTrue(len(parsedResponses) == 2)

            parsedResponse = parsedResponses[0]

            self.assertTrue(
                parsedResponse.has_key('formattedFinishDate') == True)

            self.assertTrue(parsedResponse['fibData']['fibId'] == 3)
            self.assertTrue(parsedResponse['fibData']['fibValue'] == 2)
            self.assertTrue(parsedResponse['fibData']['workerId'] == 'abcd')

            parsedResponse = parsedResponses[1]

            self.assertTrue(
                parsedResponse.has_key('formattedFinishDate') == True)
            self.assertTrue(parsedResponse['fibData']['fibId'] == 3)
            self.assertTrue(parsedResponse['fibData']['fibValue'] == 2)
            self.assertTrue(parsedResponse['fibData']['workerId'] == 'efgh')

        except MySQLdb.Error, e:
            self.log.error("error creating table fibdata")
            self.log.error(e)
            self.handleMySQLException(e, True)
            return None
Ejemplo n.º 3
0
 def test7Add_UpdateRequest(self):
     try:
     
         fibDataDB = initializeFibDataDB(self.testName)
         fibData = FibDataRequest(None,{"request_id":"foo1","fib_id":3, "fib_value":2, "started_date" :nowInSeconds(), "finished_date" : nowInSeconds()})
         newFD = fibDataDB.addRequest(fibData)
         
         finishedDate = nowInSeconds()+5
         fibData.finishedDate = finishedDate
         
         fibDataDB.updateRequest(fibData)
         
     except:
         e = sys.exc_info()[0]
         print e
         self.fail(e)
Ejemplo n.º 4
0
    def test3GetAllRequests(self):
        try:
            fibDataDB = initializeFibDataDB(self.testName)
            startedDate = nowInSeconds()
            fd = FibDataRequest(
                None, {
                    "request_id": "foo2",
                    "fib_id": 3,
                    "fib_value": 3,
                    "started_date": startedDate
                })

            newFd = fibDataDB.addRequest(fd)
            fdArr = fibDataDB.getRequests(isPending=True)

            self.assertTrue(len(fdArr) > 0)

            self.assertTrue(len(fdArr) == 1)
            testFd = fdArr[0]
            self.assertTrue(testFd.fibId == newFd.fibId)

            fdArr2 = fibDataDB.getRequests(isPending=True, isDescending=False)
            self.assertTrue(len(fdArr2) == 1)
            testFd2 = fdArr2[0]
            self.assertTrue(testFd2.fibId == newFd.fibId)

            fdArr3 = fibDataDB.getRequests()
            self.assertTrue(len(fdArr3) == 0)
        except:
            e = sys.exc_info()[0]
            print e
            self.fail(e)
Ejemplo n.º 5
0
    def test2AddRequest(self):

        try:
            fibDataDB = initializeFibDataDB(self.testName)
            startedDate = nowInSeconds()

            fd = FibDataRequest(
                None, {
                    "request_id": "foo1",
                    "fib_id": 3,
                    "fib_value": 3,
                    "started_date": startedDate
                })

            newFd = fibDataDB.addRequest(fd)

            fetchedFd = fibDataDB.getRequest(newFd.requestId)

            self.assertTrue(fd.fibId == fetchedFd.fibId)
            self.assertTrue(fd.fibValue == fetchedFd.fibValue)
            self.assertTrue(fd.startedDate == fetchedFd.startedDate)
        except:
            e = sys.exc_info()[0]
            print e
            self.fail(e)
Ejemplo n.º 6
0
def fib_num(number):
    if not number:
        return template('Please add a number to the end of url: /fib/5')
    fibDataPayload = {}
    fibDataPayload['fib_id'] = number
    fibDataRequest = FibDataRequest(body=fibDataPayload)
    newRequest = fibDataDB.addRequest(fibDataRequest)
    jobMessageQueue.sendMessage(
        jobsQueueName,
        WorkRequestMessage(requestId=newRequest.requestId,
                           messageKey=int(number)))
Ejemplo n.º 7
0
def fib():
    number = request.json['number']
    if not number:
        return template('Please add a number to the end of url: /send/5')
    fibDataPayload = {}
    fibDataPayload['fib_id'] = number
    requestId = str(uuid.uuid1())
    fibDataPayload['request_id'] = requestId
    fibDataRequest = FibDataRequest(body=fibDataPayload)
    newRequest = fibDataDB.addRequest(fibDataRequest)
    jobMessageQueue.sendMessage(
        WorkRequestMessage(requestId=newRequest.requestId,
                           messageKey=int(number)))
Ejemplo n.º 8
0
    def processMessage(message):
        '''
            this is the handler function passed to getAndProcessMessages
            '''
        dataMap = {}
        dataMap['request_id'] = message.requestId
        dataMap['fib_id'] = message.messageKey
        dataMap['fib_value'] = message.messageValue
        dataMap['started_date'] = message.startedDate
        dataMap['finished_date'] = message.finishedDate

        fibDataRequest = FibDataRequest(body=dataMap)
        fibDataDB.updateRequest(fibDataRequest)
Ejemplo n.º 9
0
    def test13SerializeDisplayData(self):
        try:
            fibDataDB = initializeFibDataDB(self.testName)
            startedDate = nowInSeconds()
            fd = FibDataRequest(
                None, {
                    "request_id": "foo1",
                    "fib_id": 3,
                    "fib_value": 3,
                    "started_date": startedDate
                })
            fd2 = FibDataRequest(
                None, {
                    "request_id": "foo2",
                    "fib_id": 4,
                    "fib_value": 5,
                    "started_date": startedDate
                })
            fibDataDB.addRequest(fd)
            fibDataDB.addRequest(fd2)

            fdArr = fibDataDB.getRequests(isPending=True)

            self.assertTrue(len(fdArr) == 2)

            displayDataArr = []

            for request in fdArr:
                displayDataArr.append(DisplayData(request))

            str = json.dumps(displayDataArr, cls=DataEncoder)

            print str

        except:
            e = sys.exc_info()[0]
            print e
            self.fail(e)
Ejemplo n.º 10
0
    def test7Add_UpdateRequest(self):
        try:

            fibDataDB = initializeFibDataDB(self.testName)
            fibData = FibDataRequest(
                None, {
                    "request_id": "foo1",
                    "fib_id": 3,
                    "fib_value": 2,
                    "started_date": nowInSeconds(),
                    "finished_date": nowInSeconds()
                })
            newFD = fibDataDB.addRequest(fibData)

            finishedDate = nowInSeconds() + 5
            fibData.finishedDate = finishedDate

            fibDataDB.updateRequest(fibData)

        except:
            e = sys.exc_info()[0]
            print e
            self.fail(e)
Ejemplo n.º 11
0
    def test5InitializeFromJSON(self):
        try:
            dataMap = {}
            dataMap['request_id'] = "foo1"
            dataMap['fib_id'] = 3
            dataMap['fib_value'] = 3
            dataMap['started_date'] = nowInSeconds()
            request = FibDataRequest(body=dataMap)

            self.assertTrue(request != None)
            self.assertTrue(request.fibId == dataMap['fib_id'])
            self.assertTrue(request.fibValue == dataMap['fib_value'])

        except:
            e = sys.exc_info()[0]
            print e
            self.fail(e)
Ejemplo n.º 12
0
    def test1InitializeFibData(self):

        try:
            fibDataDB = initializeFibDataDB(self.testName)
            fibData = FibDataRequest(None, {
                "request_id": "foo1",
                "fib_id": 3,
                "fib_value": 2
            })
            newFD = fibDataDB.addRequest(fibData)

            self.assertTrue(newFD.requestId == 'foo1')
            self.assertTrue(newFD.fibId == fibData.fibId)
            self.assertTrue(newFD.fibValue == fibData.fibValue)
            self.assertTrue(newFD.startedDate == fibData.startedDate)
        except:
            e = sys.exc_info()[0]
            print e
            self.fail(e)
Ejemplo n.º 13
0
    def test6AddRequestWithFinishedDate(self):
        try:
            fibDataDB = initializeFibDataDB(self.testName)
            fibData = FibDataRequest(
                None, {
                    "request_id": "foo1",
                    "fib_id": 3,
                    "fib_value": 2,
                    "started_date": nowInSeconds(),
                    "finished_date": nowInSeconds()
                })
            newFD = fibDataDB.addRequest(fibData)

            self.assertTrue(newFD.requestId != -1)
            self.assertTrue(newFD.fibId == fibData.fibId)
            self.assertTrue(newFD.fibValue == fibData.fibValue)
            self.assertTrue(newFD.startedDate == fibData.startedDate)
            self.assertTrue(newFD.finishedDate == fibData.finishedDate)
        except:
            e = sys.exc_info()[0]
            print e
            self.fail(e)