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 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)
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
def generateManyTweetSearches(randomTweetSearches, tweetId, searchId): tweetSearchList = ObjectList() for i in range(0, randomTweetSearches): tweetSearch = TweetSearch(randomTweetSearch(tweetId, searchId)) tweetSearchList.append(tweetSearch) return tweetSearchList
def generateManyTweetStreamings(randomTweetStreamings, tweetId, streamingId): tweetStreamingList = ObjectList() for i in range(0, randomTweetStreamings): tweetStreaming = TweetStreaming(randomTweetStreaming(tweetId, streamingId)) tweetStreamingList.append(tweetStreaming) return tweetStreamingList
def generateManyStreamings(randomStreamings): streamingList = ObjectList() for i in range(0, randomStreamings): streaming = Streaming(randomStreaming(i)) streamingList.append(streaming) return streamingList
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
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
def generateOneTweetStreaming(tweetId, streamingId): tweetStreaming = TweetStreaming(randomTweetStreaming(tweetId, streamingId)) tweetStreamingList = ObjectList() tweetStreamingList.append(tweetStreaming) return tweetStreamingList
def generateOneSearch(searchId): search = Search(randomSearch(searchId)) searchList = ObjectList() searchList.append(search) return searchList
def generateOneStreaming(streamingId): streaming = Streaming(randomStreaming(streamingId)) streamingList = ObjectList() streamingList.append(streaming) return streamingList
def generateOneTweet(tweetId, userId): tweet = Tweet(randomTweet(tweetId, "1-10-2013", userId)) tweetList = ObjectList() tweetList.append(tweet) return tweetList
def generateOneUser(userId): user = User(randomUser(userId, "1-10-2013", "pablo")) userList = ObjectList() userList.append(user) return userList