public void Preserve_given_id() { // Arrange & Act var workBatch = new WorkBatch(1, new TestWorkBatch(BatchId)); // Assert workBatch.Id.Should().Be(BatchId); }
private static IWorkItem[] GetWorkItems(string sourcePath, Func <Uri, WorkBatch, IWorkItem> workItemFactoryMethod, int batchId) { var fileLocations = GetAllFilesWithPatternInBlob(sourcePath, ".*part.*"); var batch = new WorkBatch(fileLocations.Length, batchId.ToString()); CloudConsole.WriteLine($"Created batch {batch.Id} with {fileLocations.Length} blobs"); return(fileLocations .Select(uri => workItemFactoryMethod(uri, batch)) .ToArray()); }
public void Preserve_given_precomputed_results() { // Arrange var result = new WorkItemResult(WorkStatus.Successful); var preComputedResult = new [] { DummyData }; var testBatch = new TestWorkBatch(BatchId); var workBatch = new WorkBatch(1, testBatch, preComputedResult); // Act workBatch.DoFinally(result, CancellationToken.None); // Assert testBatch.Result.Data.Should().Contain(DummyData); }
public void Fail_when_workitems_failed() { // Arrange var results = _failedBatch; var testBatch = new TestWorkBatch(BatchId); var workBatch = new WorkBatch(results.Length, testBatch); // Act foreach (var result in results) { workBatch.DoFinally(result, CancellationToken.None); } // Assert testBatch.Result.Status.Should().Be(WorkStatus.Failed); }
public void Execute_doFinally_only_once(bool successful) { // Arrange var results = successful ? _successfulBatch :_failedBatch; var testBatch = new TestWorkBatch(BatchId); var workBatch = new WorkBatch(results.Length, testBatch); // Act foreach (var result in results) { workBatch.DoFinally(result, CancellationToken.None); } // Assert testBatch.Executions.Should().Be(1); }
private static IWorkItem[] GetWorkItems(CancellationToken cancellationToken) { var rand = new Random(); var workBatch = new WorkBatch(3); var workItems = new[] { new DummyWorkItem(rand.Next(), workBatch, cancellationToken), new DummyWorkItem(rand.Next(), workBatch, cancellationToken), new DummyWorkItem(rand.Next(), workBatch, cancellationToken) }; CloudConsole.WriteLine( $"Producer {Thread.CurrentThread.ManagedThreadId} has created " + $"{workItems[0].Id}, {workItems[1].Id}, {workItems[2].Id}"); return(workItems.Cast <IWorkItem>().ToArray()); }
public void Store_results(bool successful) { // Arrange var results = successful ? _successfulBatch : _failedBatch; var testBatch = new TestWorkBatch(BatchId); var workBatch = new WorkBatch(results.Length, testBatch); // Act foreach (var result in results) { workBatch.DoFinally(result, CancellationToken.None); } // Assert testBatch.Result.Data.Should() .Contain(results.Where(x => x.Data != null) .Select(y => y.Data.Cast <string>().First())); }
private static IWorkItem[] GetWorkItems(EventWaitHandle started = null) { var rand = new Random(); var workBatch = new WorkBatch(3, new DummyWorkBatch(started)); var workItems = new[] { new BatchedWorkItem(workBatch, new DummyWorkItem(rand.Next())), new BatchedWorkItem(workBatch, new DummyWorkItem(rand.Next())), new BatchedWorkItem(workBatch, new DummyWorkItem(rand.Next())) }; CloudConsole.WriteLine( $"Producer {Thread.CurrentThread.ManagedThreadId} has created " + $"{workItems[0].Id}, {workItems[1].Id}, {workItems[2].Id}"); return(workItems.Cast <IWorkItem>().ToArray()); }
public void Error_when_trying_to_add_a_result_to_a_completed_batch() { // Arrange var results = new[] { new WorkItemResult(WorkStatus.Successful), new WorkItemResult(WorkStatus.Failed), new WorkItemResult(WorkStatus.Successful) }; var testBatch = new TestWorkBatch(BatchId); var workBatch = new WorkBatch(results.Length, testBatch); foreach (var result in results) { workBatch.DoFinally(result, CancellationToken.None); } Action addToClosedBatch = () => workBatch.DoFinally(new WorkItemResult(WorkStatus.Successful), CancellationToken.None); // Act & Assert addToClosedBatch.ShouldThrow <ApplicationException>(); }
public StartupReadFromBlobWorkItem(ManualResetEvent started, Action <string[]> storeResults, string blobUri, WorkBatch batch, CancellationToken cancellationToken) : base(storeResults, blobUri, batch, cancellationToken) { _started = started; }
public DummyWorkItem( int id, WorkBatch batch, CancellationToken cancellationToken) : base(id.ToString(), batch, cancellationToken) { }
public ReadFromBlobWorkItem(Action <string[]> storeResults, string blobUri, WorkBatch batch, CancellationToken cancellationToken) : base(blobUri, batch, cancellationToken) { _storeResults = storeResults; }