Esempio n. 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)
Esempio n. 2
0
 def test_sendData(self):
     userList = generateOneUser(userId = 1)
     tweetList = generateManyTweets(randomInteger(100), userId = 1)
     tweetStreamingList = ObjectList()
     tweetSearchList = ObjectList()
     for tweet in tweetList.getList():
         tweetStreaming = TweetStreaming(randomTweetStreaming(tweet.id, 1))
         tweetStreamingList.append(tweetStreaming)
         tweetSearch = TweetSearch(randomTweetSearch(tweet.id, 1))
         tweetSearchList.append(tweetSearch)
     self.wsDb.sendData(tweetList, userList, tweetStreamingList, tweetSearchList)
Esempio n. 3
0
def createData(base):
    status = getOneStatusTS()
    randomTweets = base + randomInteger(99) + 1
    tweetList = ObjectList()
    userList = ObjectList()
    streamingList = ObjectList()
    searchList = ObjectList()
    for i in range(base, randomTweets):
        status["id"] = i
        status["user"]["id"] = i
        ps = ParserStatus(status)
        tweet = Tweet(ps.getTweet())
        user = User(ps.getUser())
        tweetList.append(tweet)
        userList.append(user)
        streamingList.append(TweetStreaming(randomTweetStreaming(i, 1)))
        searchList.append(TweetSearch(randomTweetSearch(i, 1)))
    return tweetList, userList, streamingList, searchList
Esempio n. 4
0
def generateManyTweetSearches(randomTweetSearches, tweetId, searchId):
    tweetSearchList = ObjectList()
    for i in range(0, randomTweetSearches):
        tweetSearch = TweetSearch(randomTweetSearch(tweetId, searchId))
        tweetSearchList.append(tweetSearch)
    return tweetSearchList
Esempio n. 5
0
def generateManyTweetStreamings(randomTweetStreamings, tweetId, streamingId):
    tweetStreamingList = ObjectList()
    for i in range(0, randomTweetStreamings):
        tweetStreaming = TweetStreaming(randomTweetStreaming(tweetId, streamingId))
        tweetStreamingList.append(tweetStreaming)
    return tweetStreamingList
Esempio n. 6
0
def generateManyStreamings(randomStreamings):
    streamingList = ObjectList()
    for i in range(0, randomStreamings):
        streaming = Streaming(randomStreaming(i))
        streamingList.append(streaming)
    return streamingList
Esempio n. 7
0
def generateManyTweets(randomTweets, userId):
    tweetList = ObjectList()
    for i in range(0, randomTweets):
        tweet = Tweet(randomTweet(i, "1-10-2013", userId))
        tweetList.append(tweet)
    return tweetList
Esempio n. 8
0
def generateManyUsers(randomUsers):
    userList = ObjectList()
    for i in range(0, randomUsers):
        user = User(randomUser(i, "1-10-2013", "pablo"+str(i)))
        userList.append(user)
    return userList
Esempio n. 9
0
def generateOneTweetStreaming(tweetId, streamingId):
    tweetStreaming = TweetStreaming(randomTweetStreaming(tweetId, streamingId))
    tweetStreamingList = ObjectList()
    tweetStreamingList.append(tweetStreaming)
    return tweetStreamingList
Esempio n. 10
0
def generateOneSearch(searchId):
    search = Search(randomSearch(searchId))
    searchList = ObjectList()
    searchList.append(search)
    return searchList
Esempio n. 11
0
def generateOneStreaming(streamingId):
    streaming = Streaming(randomStreaming(streamingId))
    streamingList = ObjectList()
    streamingList.append(streaming)
    return streamingList
Esempio n. 12
0
def generateOneTweet(tweetId, userId):
    tweet = Tweet(randomTweet(tweetId, "1-10-2013", userId))
    tweetList = ObjectList()
    tweetList.append(tweet)
    return tweetList
Esempio n. 13
0
def generateOneUser(userId):
    user = User(randomUser(userId, "1-10-2013", "pablo"))
    userList = ObjectList()
    userList.append(user)
    return userList