Beispiel #1
0
 def test_serverFiveOrLessClient(self):
     global sharedListData
     # Create stop event
     stopEvent = Event()
     # Create server barrier
     sBarrier = Barrier(2)
     # Create server
     bs = BufferServer(13001, 5, stopEvent, sBarrier, 5, 5, "http://localhost:8000", "quiltro", "perroCallejero")
     streamingList = ObjectList()
     streamingList.append(Streaming(randomStreaming(1)))
     bs.communicator.service.postStreamings(streamingList)
     searchList = ObjectList()
     searchList.append(Search(randomSearch(1)))
     bs.communicator.service.postSearches(searchList)
     bs.start()
     # Create barrier for N clients
     randomClients = randomInteger(3) + 2
     cBarrier = Barrier(randomClients + 1)
     # Create N clients
     for i in range(0, randomClients):
         thread.start_new_thread(oneThread, (cBarrier, fakeClient, 
             bs.getHostName(), 13001, ))
     cBarrier.wait()
     time.sleep(5)
     # stop server
     stopEvent.set()
     # Wait for server
     sBarrier.wait()
     time.sleep(5)
     # Get data and compare
     numberTweets = len(bs.globalBuffer.localBuffer.tweetList.list)
     numberUsers = len(bs.globalBuffer.localBuffer.userList.list)
     numberTweetStreaming = len(bs.globalBuffer.localBuffer.tweetStreamingList.list)
     numberTweetSearch = len(bs.globalBuffer.localBuffer.tweetSearchList.list)
     self.assertEqual(numberTweets, 0)
     self.assertEqual(numberUsers, 0)
     self.assertEqual(numberTweetStreaming, 0)
     self.assertEqual(numberTweetSearch, 0)
     # count originals
     originalNumberTweets = 0
     originalNumberUsers = 0
     originalNumberTweetStreaming = 0
     originalNumberTweetSearch = 0
     lb = LocalBuffer()
     for i in range(0, randomClients):
         lb = countData(lb, sharedListData[i*4 + 0], sharedListData[i*4 + 1],
             sharedListData[i*4 + 2], sharedListData[i*4 + 3])
     originalNumberTweets += len(lb.tweetList.list)
     originalNumberUsers += len(lb.userList.list)
     originalNumberTweetStreaming += len(lb.tweetStreamingList.list)
     originalNumberTweetSearch += len(lb.tweetSearchList.list)
     self.assertEqual(originalNumberTweets, bs.communicator.sentTweets)
     self.assertEqual(originalNumberUsers, bs.communicator.sentUsers)
     self.assertEqual(originalNumberTweetStreaming, bs.communicator.sentTweetStreamings)
     self.assertEqual(originalNumberTweetSearch, bs.communicator.sentTweetSearches)
def generateOneSearch(searchId):
    search = Search(randomSearch(searchId))
    searchList = ObjectList()
    searchList.append(search)
    return searchList