コード例 #1
0
        public void Request_Is_Retried()
        {
            // arrange
            var userWriter = new Mock<IUserWriter>();
            var requestQueue = new MockRequestQueue();
            var responseQueue = new MockResponseQueue();
            var controller = new CrawlerController(userWriter.Object, requestQueue, responseQueue, new RecentFriendRegistry());
            var retryRequest = new GetFriendsRequest("test");
            var errorResponse = new ErrorResponse(retryRequest, "fail whale");

            // act
            controller.ProcessResponse(errorResponse);

            // assert
            Assert.That(requestQueue.QueuedMessages, Has.Count(1));
            Assert.That(requestQueue.QueuedMessages.Single(), Is.SameAs(retryRequest));
        }
コード例 #2
0
        public void ErrorResponse_Is_Queued()
        {
            // arrange
            var requestQueue = new MockRequestQueue();
            var responseQueue = new MockResponseQueue();
            var statusService = new Mock<IStatusService>();

            statusService.Setup(ss => ss.GetFriendsOf("test")).Throws(new XmlException("Twitter is full of FAIL!"));
            var crawler = new TwitterCrawler(requestQueue, responseQueue, statusService.Object);

            // act
            var friendRequest = new GetFriendsRequest("test");
            crawler.ProcessRequest(friendRequest);

            // assert
            Assert.That(responseQueue.QueuedMessages, Has.Count(1));
            Assert.That(responseQueue.QueuedMessages.Single(), Is.TypeOf(typeof(ErrorResponse)));
            var response = (ErrorResponse)responseQueue.QueuedMessages.Single();
            Assert.That(response.Request, Is.SameAs(friendRequest));
        }
コード例 #3
0
ファイル: TwitterCrawler.cs プロジェクト: trasa/TwitDegrees
 private void ProcessGetFriendsRequest(GetFriendsRequest request)
 {
     var stopwatch = new Stopwatch();
     stopwatch.Start();
     IEnumerable<UserInfo> friends = statusService.GetFriendsOf(request.UserName);
     if (friends == null)
     {
         log.Warn("Can't get friends of " + request.UserName + " - returned null.");
         responseQueue.Send(new ErrorResponse(request, "GetFriendsOf returned null."));
     }
     else
     {
         responseQueue.Send(new GetFriendsResponse(request.UserName, friends));
         ReportStopwatchResult(stopwatch, "GetFriends", friends.Count());
     }
 }