public void StartOfWindow_WriteBytes_LengthOfBytes() { using (var e = new PullStorageEnvForTest()) { var bundleHelper = new PullStorageManager(e.BaseFolder.Path, "randomHash"); string sampleText = "some sample text"; byte[] bytes = Encoding.UTF8.GetBytes(sampleText); bundleHelper.WriteChunk(0, bytes); Assert.That(bundleHelper.StartOfWindow, Is.EqualTo(bytes.Length)); } }
public void WriteChunk_MultipleWritesOverWriteSameOffset_AssemblesOk() { using (var e = new PullStorageEnvForTest()) { var bundleHelper = new PullStorageManager(e.BaseFolder.Path, "randomHash"); string[] sampleTexts = new[] { "this is a sentence. ", "Another sentence. ", "Yet another word string." }; string combinedText = ""; int startOfWindow = 0; foreach (var sampleText in sampleTexts) { combinedText += sampleText; byte[] bytes = Encoding.UTF8.GetBytes(sampleText); bundleHelper.WriteChunk(startOfWindow, bytes); startOfWindow += bytes.Length; } bundleHelper.WriteChunk(0, Encoding.UTF8.GetBytes(sampleTexts[0])); Assert.That(combinedText, Is.EqualTo(File.ReadAllText(bundleHelper.BundlePath))); } }
public void WriteChunk_Text_WriteOk() { using (var e = new PullStorageEnvForTest()) { var bundleHelper = new PullStorageManager(e.BaseFolder.Path, "randomHash"); string sampleText = "some sample text"; byte[] bytes = Encoding.UTF8.GetBytes(sampleText); bundleHelper.WriteChunk(0, bytes); string fromFile = File.ReadAllText(bundleHelper.BundlePath); Assert.That(sampleText, Is.EqualTo(fromFile)); } }
public HgResumeApiResponse Execute(string method, HgResumeApiParameters request, byte[] bytesToWrite, int secondsBeforeTimeout) { ValidateParameters(method, request, bytesToWrite, secondsBeforeTimeout); if (method == "getRevisions") { IEnumerable <Revision> revisions = _repo.GetAllRevisions(); if (revisions.Count() == 0) { return(ApiResponses.Revisions("0:default")); } var revisionStrings = _repo.GetAllRevisions().Select(rev => rev.Number.Hash + ':' + rev.Branch); return(ApiResponses.Revisions(string.Join("|", revisionStrings.ToArray()))); } if (method == "finishPushBundle") { return(ApiResponses.PushComplete()); } if (method == "pushBundleChunk") { _executeCount++; 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 )); } _helper = new PullStorageManager(_localStorage.Path, request.TransId); //int bundleSize = Convert.ToInt32(parameters["bundleSize"]); //int offset = Convert.ToInt32(parameters["offset"]); //int chunkSize = bytesToWrite.Length; _helper.WriteChunk(request.StartOfWindow, bytesToWrite); if (request.StartOfWindow + request.ChunkSize == request.BundleSize) { if (_repo.Unbundle(_helper.BundlePath)) { return(ApiResponses.PushComplete()); } return(ApiResponses.Reset()); } if (request.StartOfWindow + request.ChunkSize < request.BundleSize) { return(ApiResponses.PushAccepted(_helper.StartOfWindow)); } return(ApiResponses.Failed("offset + chunkSize > bundleSize !")); } return(ApiResponses.Custom(HttpStatusCode.InternalServerError)); }