Example #1
0
def testMasterServerList(IP, port):
    message = 'GETSERVERINFO'
    response = network.sendAndGetResponseFromIP(IP, port, message)
    servers = server.netStringToServerList(response)
    assert len(servers) == 4
    assert servers[0].role == "master"
    print "Master Server List Test Passed"
Example #2
0
def testMasterServerList(IP, port):
    message = 'GETSERVERINFO'
    response = network.sendAndGetResponseFromIP(IP, port, message)
    servers = server.netStringToServerList(response)
    assert len(servers) == 4
    assert servers[0].role == "master"
    print "Master Server List Test Passed"
Example #3
0
def checkUniquenessOfTask(bloomHash, slaveToContact):
    # TODO optimize to aviod network call if server is local
    message = HASHCHECK + MESSAGE_DELIMITER + str(bloomHash)
    # if slaveToContact is itself
    if slaveToContact.ID == HOST_ID:
        return not BloomHashFilter.checkAndInsert(bloomHash)

    hashCheckResponse = network.sendAndGetResponseFromIP(
        slaveToContact.IP, slaveToContact.port, message)
    stats.hashCheckQuerySent += 1
    # Note : this call will simultaneously put the hash
    # into the bloom filter if it was not present already
    words = hashCheckResponse.split(MESSAGE_DELIMITER)
    return not (words[1] == 'True')
Example #4
0
def checkUniquenessOfTask(bloomHash, slaveToContact):
    # TODO optimize to aviod network call if server is local
    message = HASHCHECK + MESSAGE_DELIMITER + str(bloomHash)
    # if slaveToContact is itself
    if slaveToContact.ID == HOST_ID:
        return not BloomHashFilter.checkAndInsert(bloomHash)

    hashCheckResponse = network.sendAndGetResponseFromIP(
            slaveToContact.IP,
            slaveToContact.port,
            message)
    stats.hashCheckQuerySent += 1
    # Note : this call will simultaneously put the hash
    # into the bloom filter if it was not present already
    words = hashCheckResponse.split(MESSAGE_DELIMITER)
    return not (words[1]=='True')
Example #5
0
def getNewTask(main):
    if not TaskQueue.empty():
        return TaskQueue.get()
    else:
        randomSlave = main.aliveSlaves[randint(0, main.m - 1)]
        newTaskString = network.sendAndGetResponseFromIP(
            randomSlave.IP, randomSlave.port, REQUESTTASK)
        words = newTaskString.split(MESSAGE_DELIMITER)
        messageHead = words[0]
        if messageHead == EMPTYTASK:
            time.sleep(UNSUCCESSFUL_GET_TASK_WAIT_TIME)
            return None
        elif messageHead == POPPEDTASK:
            return task.toTaskFromNetString(MESSAGE_DELIMITER.join(words[1:]))
        else:
            main.unrecognizedMessage()
Example #6
0
def getNewTask(main):
    if not TaskQueue.empty() :
        return TaskQueue.get()
    else :
        randomSlave = main.aliveSlaves[randint(0, main.m - 1)]
        newTaskString = network.sendAndGetResponseFromIP(
            randomSlave.IP,
            randomSlave.port,
            REQUESTTASK)
        words = newTaskString.split(MESSAGE_DELIMITER)
        messageHead = words[0]
        if messageHead == EMPTYTASK :
            time.sleep(UNSUCCESSFUL_GET_TASK_WAIT_TIME)
            return None
        elif messageHead == POPPEDTASK :
            return task.toTaskFromNetString(MESSAGE_DELIMITER.join(words[1:]))
        else :
            main.unrecognizedMessage()
Example #7
0
def testPingPong(IP, port):
    message = "PING"
    response = network.sendAndGetResponseFromIP(IP, port, message)
    assert response == 'PONG'
    print "Ping Test Passed"
Example #8
0
def testPingPong(IP, port):
    message = "PING"
    response = network.sendAndGetResponseFromIP(IP, port, message)
    assert response == 'PONG'
    print "Ping Test Passed"