Example #1
0
 public void Pull_InitialServerResponseServerNotAvailable_NotAvailableMessage()
 {
     using (var e = new TestEnvironment("hgresumetest", ApiServerType.Dummy))
         using (var provider = GetTransportProviderForTest(e))
         {
             e.LocalAddAndCommit();
             var serverMessage = "The server is down for scheduled maintenance";
             e.ApiServer.AddResponse(ApiResponses.NotAvailable(serverMessage));
             e.ApiServer.AddResponse(ApiResponses.PullNoChange());
             var transport = provider.Transport;
             transport.Pull();
             Assert.That(e.Progress.AllMessages, Contains.Item("Server temporarily unavailable: " + serverMessage));
             Assert.That(e.Progress.AllMessages, Has.No.Member("The pull operation completed successfully"));
         }
 }
 public void Pull_InitialServerResponseServerNotAvailable_NotAvailableMessage()
 {
     using (var e = new TestEnvironment("hgresumetest", ApiServerType.Dummy))
         using (var provider = GetTransportProviderForTest(e))
         {
             e.LocalAddAndCommit();
             var serverMessage    = "The server is down for scheduled maintenance";
             var revisionResponse = ApiResponses.Custom(HttpStatusCode.OK);
             revisionResponse.Content = Encoding.UTF8.GetBytes((e.Local.Repository.GetTip().Number.Hash + ":").ToArray());
             e.ApiServer.AddResponse(revisionResponse);
             e.ApiServer.AddResponse(ApiResponses.NotAvailable(serverMessage));
             e.ApiServer.AddResponse(ApiResponses.PullNoChange());
             var transport = provider.Transport;
             transport.Pull();
             Assert.That(e.Progress.AllMessages, Contains.Item("Server temporarily unavailable: " + serverMessage));
             Assert.That(e.Progress.AllMessages, Has.No.Member("The pull operation completed successfully"));
         }
 }
Example #3
0
        public HgResumeApiResponse Execute(string method, HgResumeApiParameters request, byte[] bytesToWrite, int secondsBeforeTimeout)
        {
            ValidateParameters(method, request, bytesToWrite, secondsBeforeTimeout);
            _executeCount++;
            if (method == "finishPullBundle")
            {
                if (CurrentTip != OriginalTip)
                {
                    PrepareBundle(HgResumeTransport.GetHashStringsFromRevisions(_repo.BranchingHelper.GetBranches()));
                    return(ApiResponses.Reset());                    // repo changed in between pulls
                }
                return(ApiResponses.Custom(HttpStatusCode.OK));
            }
            if (method == "getRevisions")
            {
                IEnumerable <string> revisions = _repo.GetAllRevisions().Select(rev => rev.Number.Hash + ':' + rev.Branch);
                return(ApiResponses.Revisions(string.Join("|", revisions.ToArray())));
            }
            if (method == "pullBundleChunk")
            {
                if (_cancelCount == _executeCount)
                {
                    _progress.CancelRequested = true;
                    return(ApiResponses.Failed(""));
                }
                if (_failCount == _executeCount)
                {
                    return(ApiResponses.Failed(""));
                }
                if (_timeoutList.Contains(_executeCount))
                {
                    return(null);
                }
                if (_serverUnavailableList.Any(i => i.ExecuteCount == _executeCount))
                {
                    return(ApiResponses.NotAvailable(
                               _serverUnavailableList.Where(i => i.ExecuteCount == _executeCount).First().Message
                               ));
                }
                if (Array.BinarySearch(request.BaseHashes, 0, request.BaseHashes.Length, CurrentTip) >= 0)
                {
                    return(ApiResponses.PullNoChange());
                }

                var bundleFileInfo = new FileInfo(_helper.BundlePath);
                if (bundleFileInfo.Exists && bundleFileInfo.Length == 0 || !bundleFileInfo.Exists)
                {
                    PrepareBundle(request.BaseHashes);
                }
                //int offset = Convert.ToInt32(request["offset"]);
                //int chunkSize = Convert.ToInt32(request["chunkSize"]);
                var bundleFile = new FileInfo(_helper.BundlePath);
                if (request.StartOfWindow >= bundleFile.Length)
                {
                    return(ApiResponses.Failed("offset greater than bundleSize"));
                }
                var chunk = _helper.GetChunk(request.StartOfWindow, request.ChunkSize);
                return(ApiResponses.PullOk(Convert.ToInt32(bundleFile.Length), chunk));
            }
            return(ApiResponses.Custom(HttpStatusCode.InternalServerError));
        }