Ejemplo n.º 1
0
 def testGetOwnedTuples(self):
     node = StaticTupleSpacePeer()
     inputData = [('ownresource1','ivr',node.id),
                  ('ownresource2','ivr',node.id),
                  ('otherResource1','ivr','otherid123456')]
     
     expectedResult = []
     
     # Attempt to publish the data tuple
     for item in inputData:
         node.put(item)
     
             
     
     returnedTuples = node.getOwnedTuples()
     
     # check that the expected result was returned
     # construct the expected result
     
     for i in range(2):
         parsedStr = (inputData[i][0], inputData[i][1])
         serializedStr = cPickle.dumps(parsedStr)
         
         expectedResult.append([node.id, serializedStr])
     expectedResult.reverse()
     
     
     # Only tuples owned by this node (has this nodes id) should be returned
     self.failUnlessEqual(returnedTuples, expectedResult, "Tuples returned from getOwnedTuples not the same as the expected result."   \
                     " Only tuples owned by this node (has this nodes id) should be returned")
Ejemplo n.º 2
0
 def testFindTuple(self):
     node = StaticTupleSpacePeer()
     inputData = ('resource','ivr',node.id)
     
     # Attempt to publish the data tuple
     node.put(inputData)
     
     # Attempt to find the data
     returnedTuple = node.findTuple(('resource', 'ivr'))
     
     # check that the expected result was returned
     expectedResult = ('resource', 'ivr', node.id)
     self.failUnlessEqual(returnedTuple, expectedResult, "Tuple returned from findTuple not the same as the expected result")
Ejemplo n.º 3
0
 def testPut(self):
     node = StaticTupleSpacePeer()
     inputData = ('resource','ivr',node.id)
     parsedInput = (inputData[0], inputData[1])
     serializedInput = cPickle.dumps(parsedInput)
     
         
     # Attempt to publish the data tuple
     node.put(inputData)
     
     # Check that the data is in the data store
     h = hashlib.sha1()
     h.update(serializedInput)
     mainKey = h.digest()
     
             
     dataStoreTuple = node.dataStore.__getitem__(mainKey)
     ownerID = node.dataStore.originalPublisherID(mainKey)
     
     self.failUnlessEqual(serializedInput, dataStoreTuple, "Input data not equal to the data found in the dataStore")
     self.failUnlessEqual(ownerID, node.id, "Input owner ID not equal to the owner ID found in the dataStore")
Ejemplo n.º 4
0
        print 'or:\n%s UDP_PORT  [FILE_WITH_KNOWN_NODES]' % sys.argv[0]
        print '\nIf a file is specified, it should containg one IP address and UDP port\nper line, seperated by a space.'
        sys.exit(1)
    try:
        int(sys.argv[1])
    except ValueError:
        print '\nUDP_PORT must be an integer value.\n'
        print 'Usage:\n%s UDP_PORT  [KNOWN_NODE_IP  KNOWN_NODE_PORT]' % sys.argv[0]
        print 'or:\n%s UDP_PORT  [FILE_WITH_KNOWN_NODES]' % sys.argv[0]
        print '\nIf a file is specified, it should contain one IP address and UDP port\nper line, seperated by a space.'
        sys.exit(1)

    if len(sys.argv) == 4:
        knownNodes = [(sys.argv[2], int(sys.argv[3]))]
    elif len(sys.argv) == 3:
        knownNodes = []
        f = open(sys.argv[2], 'r')
        lines = f.readlines()
        f.close()
        for line in lines:
            ipAddress, udpPort = line.split()
            knownNodes.append((ipAddress, int(udpPort)))
    else:
        knownNodes = None

    node = StaticTupleSpacePeer( udpPort=int(sys.argv[1]) )
    node.put(('handler', 'jokeapp'), node.id)
    node.put(('ivr', 'english', 'time'), node.id)
    node.put('otherTuple', 'jjksl33434')
    node.joinNetwork(knownNodes)
    twisted.internet.reactor.run()