示例#1
0
        public void Preserve_given_id()
        {
            // Arrange & Act
            var workBatch = new WorkBatch(1, new TestWorkBatch(BatchId));

            // Assert
            workBatch.Id.Should().Be(BatchId);
        }
示例#2
0
        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());
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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());
        }
示例#7
0
        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());
        }
示例#9
0
        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;
 }
示例#11
0
 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;
 }