当前位置: 首页>>代码示例>>Python>>正文


Python TestUtils类代码示例

本文整理汇总了Python中TestUtils的典型用法代码示例。如果您正苦于以下问题:Python TestUtils类的具体用法?Python TestUtils怎么用?Python TestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testNodeStartup

    def testNodeStartup(self):
        
        # Start a bootstrap node
        (status, self.bsNode, _observer) = yield TestUtils.startupBootstrapNode(self.myIP, 12345, 'localhost')
        self.assertTrue(status, 'Could not build bootstrap node')

        # Start a client node
        (status, self.normalNode, observer) = yield TestUtils.startupClientNode(self.myIP, 12346, 'localhost', self.bsNode.nodeLocation)
        self.assertTrue(status, 'Could not startupClientNode')

        # Are they connected together?
        status = yield self.doQuickSendTest()
        self.assertTrue(status, 'doQuickSendTest')
        
        # Stop the nodes
        yield self.normalNode.leave()
        yield self.bsNode.leave()

        # Wait for the connections to really all close
        if Config.USE_CONNECTION_CACHE:
            yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 3)
        else:
            yield TestUtils.wait(3)

        defer.returnValue(True)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:25,代码来源:QuickSendTest.py

示例2: testSerialFlooding

    def testSerialFlooding(self):
        
        # Start a bootstrap node
        (status, self.bsNode, _observer) = yield TestUtils.startupBootstrapNode(self.myIP, 12345, 'localhost')
        self.assertTrue(status, 'Could not build bootstrap node')
        self.allNodes.append(self.bsNode)
        self.bsNode.addMessageObserver(self.messageReceived)

        # Start client nodes
        for i in range(numNodes):
            (status, node, observer) = yield TestUtils.startupClientNode(self.myIP, 12346+i, 'localhost', self.bsNode.nodeLocation)
            self.assertTrue(status, 'Could not startupClientNode')
            self.allNodes.append(node)
            observer = MyMessageObserver()
            node.addMessageObserver(observer.messageReceived)
            observer.node = node
            self.allObservers.append(observer)
        
        # Wait for flooding to reach all the nodes
        waiter = ConnectivityCounter()
        yield waiter.waitForConnectivity(numNodes, self.bsNode) # Does not count bsNode itself.

        # Now do the stress test
        status = yield self.doStressTest()
        
        # Now close it all down!
        yield self.allLeave()
        
        # Wait a second or two for network timeouts
        yield TestUtils.wait(9)
        
        defer.returnValue(True)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:32,代码来源:SerialFloodingTest.py

示例3: testSerialP2PSending

    def testSerialP2PSending(self):
        
        # Start a bootstrap node
        (status, self.bsNode, _observer) = yield TestUtils.startupBootstrapNode(self.myIP, 12345, 'localhost')
        self.assertTrue(status, 'Could not build bootstrap node')
        self.allNodes.append(self.bsNode)
        self.bsNode.addMessageObserver(self.messageReceived)
        
        # Start client nodes
        log.msg("Building nodes...")
        for i in range(numNodes):
            (status, node, observer) = yield TestUtils.startupClientNode(self.myIP, 12346+i, 'localhost', self.bsNode.nodeLocation)
            self.assertTrue(status, 'Could not startupClientNode')
            self.allNodes.append(node)

        # Wait for flooding to reach all the nodes
        waiter = ConnectivityCounter()
        yield waiter.waitForConnectivity(numNodes, self.bsNode) # Does not count bsNode itself.
        
        # Do the real test
        status = yield self.doStressTest()
        
        # Now close it all down!
        yield self.allLeave()
        
        # Wait a second or two
        yield TestUtils.wait(3+Config.CONNECTION_CACHE_DELAY)
        
        defer.returnValue(True)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:29,代码来源:SerialStressTest.py

示例4: getAggResponse

    def getAggResponse(self):
        '''Send a query and get an agg response from all the nodes.'''

        bsNode = self.bsNetwork.chordNode
        
        
        for aggNumber in range(1, numNodes + 5):
            # Reset the message counter
            obs = self.getObserver(bsNode, self.allTestObservers)
            obs.resetMessageCount()
                                           
            # Send the query asking for a response        
            messageNum = aggNumber # Just to keep it incrementing
            yield TestUtils.sendFlood(bsNode,messageNum,'localhost', data="SEND_AGG_RESPONSE:%d" % aggNumber)
            
            
            # Now check how many messages the bootstrap node got in return
            for _ in range(10): # 10 seconds
                recvCount = obs.getMessageCount()
    
                if recvCount >= numNodes+1:
                    break
                else:
                    yield TestUtils.wait(1)
            
            self.failUnless(recvCount == numNodes+1, "getAggResponse didn't get the correct number of messages back.Expected[%d] Got[%d]" % (numNodes+1, recvCount))
        
        defer.returnValue(True)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:28,代码来源:APITest.py

示例5: sendP2PMsg

 def sendP2PMsg(self, src, dst, allNodeObservers):
     '''Send a P2P message from src to dst and verify it got there.
        Also check that no other nodes got it.
     '''
     
     goodCounter = 0
     
     for _ in range(numMessages):
         messageNum = random.randint(1,9999999)
         
         # Send the message
         status = yield TestUtils.sendP2P(src, dst, messageNum )
         self.assertTrue(status,"sendP2PMsg failed! [%s] [%s] to [%s]" % (status, src, dst))
 
         #yield TestUtils.wait(1) # Wait for the messages to send
         
         # Check receipt (both that one did and others did not)
         status = TestUtils.didNodeReceive(allNodeObservers,dst, messageNum)
         self.assertTrue(status,"Expected node did not receive the message!")
 
         status = TestUtils.didNotReceive(allNodeObservers, 'ALL', messageNum, len(allNodeObservers) - 1)
         self.assertTrue(status,"Extra nodes received message!") 
         
         goodCounter += 1
     
     self.assertTrue(goodCounter == numMessages, "sendP2P message did not finish all messages [%d][%d]" % (goodCounter, numMessages))
     defer.returnValue(True)       
开发者ID:danfleck,项目名称:Class-Chord,代码行数:27,代码来源:EnclaveP2PTest.py

示例6: buildNetwork

    def buildNetwork(self):
        global startingPort

        # Create Bootstrap
        port = 12345
        bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
        self.allNodeObservers = []
        self.allBootstrapObservers = []
        self.allNodes = []
        enclave = "theEnc"

        # Start a bootstrap node
        (status, self.bsNode, observer) = yield TestUtils.startupBootstrapNode(self.myIP, port, enclave)
        self.assertTrue(status, "Could not build bootstrap node")
        self.allBootstrapObservers.append(observer)

        # Add X nodes to each enclave
        for _ in range(numNodes):
            # Add a node to the enclave
            (status, node, observer) = yield TestUtils.startupClientNode(
                self.myIP, startingPort, enclave, bootstrapNodeLocation
            )
            self.assertTrue(status, "Could not startupClientNode")
            startingPort += 1
            self.allNodes.append(node)
            self.allNodeObservers.append(observer)

        # Wait for flooding to reach all the nodes
        waiter = ConnectivityCounter()
        yield waiter.waitForConnectivity(numNodes + 1, self.bsNode)  # Does not bsNode .

        defer.returnValue(True)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:32,代码来源:NodeDisconnectTest.py

示例7: testNodeStartup

 def testNodeStartup(self):
     
     port = 12345
     enclave = 'localhost'
     
     bootstrapNodeLocation = NodeLocation(None, self.myIP, port)
     
     # Start a bootstrap node
     (status, bsNode, _) = yield TestUtils.startupBootstrapNode(self.myIP, port, enclave)
     self.assertTrue(status, 'Could not build bootstrap node')
     
     # Start a client node
     (status, node, _) = yield TestUtils.startupClientNode(self.myIP, 12346, enclave, bootstrapNodeLocation)
     self.assertTrue(status, 'Could not startupClientNode')
     
     #yield TestUtils.wait(3)
     # Are they connected together?
     status = yield self.doConnectionTest(node)
     self.assertTrue(status, 'doConnectionTest')
     
     # Stop the nodes
     yield bsNode.leave()
     yield node.leave()
     
     yield TestUtils.wait(Config.CONNECTION_CACHE_DELAY + 3)
     
     defer.returnValue(True)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:27,代码来源:NodeCreationTest.py

示例8: getTestSuite

def getTestSuite(select="unit"):
    """
    Get test suite

    select  is one of the following:
            "unit"      return suite of unit tests only
            "component" return suite of unit and component tests
            "all"       return suite of unit, component and integration tests
            "pending"   return suite of pending tests
            name        a single named test to be run
    """
    testdict = {
        "unit":
            [ "testUnits"
            , "testNull"
            ],
        "component":
            [ "testComponents"
            ],
        "integration":
            [ "testIntegration"
            ],
        "pending":
            [ "testPending"
            ]
        }
    return TestUtils.getTestSuite(SparqlQueryTestCase, testdict, select=select)
开发者ID:anusharanganathan,项目名称:RDFDatabank,代码行数:27,代码来源:SparqlQueryTestCase.py

示例9: getTestSuite

def getTestSuite(select="unit"):
    """
    Get test suite

    select  is one of the following:
            "unit"      return suite of unit tests only
            "component" return suite of unit and component tests
            "all"       return suite of unit, component and integration tests
            "pending"   return suite of pending tests
            name        a single named test to be run
    """
    testdict = {
        "unit": 
            [ 
             "oai_listIdentifiers"
            ],
        "component":
            [ "testComponents"
            ],
        "integration":
            [ "testIntegration"
            ],
        "pending":
            [ "testPending"
            ]
        }
    return TestUtils.getTestSuite(TestOaiClient, testdict, select=select)
开发者ID:bodleian,项目名称:datafinder,代码行数:27,代码来源:TestOaiClient.py

示例10: testStartAutoDiscoveryClient

    def testStartAutoDiscoveryClient(self):
        '''Try to start a bootstrap node with autodiscovery on.
        '''
        
        log.msg("---------------------- BEGIN testStartAutoDiscoveryClient -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []

        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        bsNodeLocation = NodeLocation(None, self.myIP, port)
        bootstrapNodeList = [ bsNodeLocation ]
        (self.bsClient, self.bsNetwork, d) = self.startBootstrapNode(enclaveStr, self.myIP, port, "authenticate:succeed", bootstrapNodeList)
        yield d
        
        # Now try and join with autodiscovery
        yield self.startClientNodeAutoDiscovery(None, self.myIP, port+1, enclaveStr, bootstrapNodeList)

        # Shut it all down
        for (clientAPI, networkAPI) in self.allNodes:
            yield networkAPI.disconnect()
            
        yield self.bsNetwork.disconnect()     
        
        # Try and wait for connection cache to finish disconnects (just in case).
        yield TestUtils.waitForConnectionCache()        
开发者ID:danfleck,项目名称:Class-Chord,代码行数:28,代码来源:AutoDiscoveryTest.py

示例11: testStartAutoDiscoveryClientTimeout

    def testStartAutoDiscoveryClientTimeout(self):
        '''Try to start a bootstrap node with autodiscovery on.
           This should show a failure notice.
        '''
        
        log.msg("---------------------- BEGIN testStartAutoDiscoveryClientTimeout -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []

        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        
        # Now try and join with autodiscovery
        d = defer.Deferred()
        
        clientAPI = SampleClient(self.myIP, port, None)
        networkAPI = classChordNetworkChord(clientAPI, port, self.myIP)
        nodeID = networkAPI.generateNodeID(str(port), enclaveStr) # Get the ID with the bits on it we need. Use "port" because it'll be uniq for tests
        
        # Join the network
        callFunc = lambda result, payload: self.shouldFailCallback(result, payload, d)
        networkAPI.start(callFunc, nodeID, enclaveStr, "authenticate:succeed", None, False, True)
        
        yield d
        
        yield TestUtils.waitForConnectionCache()        
开发者ID:danfleck,项目名称:Class-Chord,代码行数:28,代码来源:AutoDiscoveryTest.py

示例12: testMultipleBSNodesAutoDiscoveryClient

    def testMultipleBSNodesAutoDiscoveryClient(self):
        '''Try to start multiple bootstrap nodes then a client and make sure it connects to one of them.
        '''
        
        log.msg("---------------------- BEGIN testMultipleBSNodesAutoDiscoveryClient -------------- ")
        self.allNodes = []
        self.allMetricsObservers = []
        self.allTestObservers = []


        
        # Create Bootstrap
        port = 12345
        enclaveStr = 'testclave'
        bootstrapNodeList = [ NodeLocation(None, self.myIP, port), NodeLocation(None, self.myIP, port+1)]
        
        (self.bsClient1, self.bsNetwork1, d) = self.startBootstrapNode(enclaveStr, self.myIP, port, "authenticate:succeed", bootstrapNodeList)
        yield d

        (self.bsClient2, self.bsNetwork2, d) = self.startBootstrapNode(enclaveStr, self.myIP, port+1, "authenticate:succeed", None)
        yield d
                
        # Now try and join with autodiscovery
        yield self.startClientNodeAutoDiscovery(None, self.myIP, port+2, enclaveStr, bootstrapNodeList)

        # Shut it all down
        for (clientAPI, networkAPI) in self.allNodes:
            yield networkAPI.disconnect()
            
        yield self.bsNetwork1.disconnect()
        yield self.bsNetwork2.disconnect()  
                        
        yield TestUtils.waitForConnectionCache()        
开发者ID:danfleck,项目名称:Class-Chord,代码行数:33,代码来源:AutoDiscoveryTest.py

示例13: waitForConnectivity

    def waitForConnectivity(self, numToWaitFor, chordNode):
        '''Wait till we can connect to all numNodes'''

        self.node = chordNode
        self.testCounter = 1
        self.connectedNodeList = []

        
        # Need to see the messages
        self.node.addMessageObserver(self.messageReceived)
        
        yield self.getNumConnected()
        
        while len(self.connectedNodeList) < numToWaitFor:
            log.msg("DEBUG: waiting for %d nodes. Got %d" % (numToWaitFor, len(self.connectedNodeList)), system="ConnectivityCounter")
            self.testCounter += 1
            yield self.getNumConnected()
            yield TestUtils.wait(5) # Wait for messages to go around
        
        log.msg("DEBUG: waiting for %d nodes. Got %d" % (numToWaitFor, len(self.connectedNodeList)), system="ConnectivityCounter")
#         for n in self.connectedNodeList:
#             print("DEBUG:       Node:%s" % n)

        # Don't care anymore
        self.node.removeMessageObserver(self.messageReceived)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:25,代码来源:ConnectivityCounter.py

示例14: waitForAllReceived

    def waitForAllReceived(self):
        '''Wait until all messages have been received by all the nodes.'''
        
        
        numTries = 10
        
        expectedNumMsg = numNodes*numMessages
        for _ in range(numTries):
            
            completedObservers = 0
            incompleteObservers = 0

            # Wait a sec
            yield TestUtils.wait(1)


            # Count them
            for obs in self.allObservers:
                numRx = obs.getNumReceived()
                
                if numRx == expectedNumMsg:
                    completedObservers += 1
                elif numRx > expectedNumMsg:
                    obs.printMessages()
                    raise Exception("Programming error... received more messages than possible! Got[%d] Expected[%d]" % (numRx,expectedNumMsg ))
                else:
                    incompleteObservers += 1
                    
            print("waitForAllReceived: Complete:%d   Incomplete:%d" % (completedObservers, incompleteObservers))
            
            if incompleteObservers == 0:
                defer.returnValue(True)
            
                
        defer.returnValue(False)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:35,代码来源:SerialFloodingTest.py

示例15: waitForMessageCount

 def waitForMessageCount(self, obs, numMessagesToWaitFor):
     
     for _ in range(10):
         if obs.getPingbackCount() >= numMessagesToWaitFor:
             defer.returnValue(True)
         else:
             yield TestUtils.wait(1)
             
     defer.returnValue(False)
开发者ID:danfleck,项目名称:Class-Chord,代码行数:9,代码来源:APITest.py


注:本文中的TestUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。