public void If_batch_execution_fails_an_error_response_is_expected() { const int MAX_BATCH_CAPACITY = 2; var batcher = new SizedBatcher <string>(_ => { throw new Exception("Execution has failed!"); }, MAX_BATCH_CAPACITY); var one = batcher.Add("one"); var two = batcher.Add("two"); var batchExecution = batcher.Query(one); Assert.IsTrue(batchExecution.IsCompleted, "Execution should be completed!"); Assert.IsInstanceOf <ExceptionBatchResponse>(batchExecution.Result, "Result should be of type 'ExceptionBatchResponse'!"); var result = batchExecution.Result as ExceptionBatchResponse; Assert.AreEqual("Execution has failed!", result.InnerException.Message); }
public void If_batch_is_NOT_full_quering_the_status_should_throw() { const int MAX_BATCH_CAPACITY = 3; var batcher = new SizedBatcher <string>(batch => { var j = string.Join(" ", batch.Items); return(new SuccessBatchResponse <string>(j)); }, MAX_BATCH_CAPACITY); var one = batcher.Add("one"); var two = batcher.Add("two"); try { var batchExecution = batcher.Query(one); Assert.Fail("Quering the batch-execution should have thrown before!"); } catch (BatchWaitingForExecutionException) { // Just an exception of this type is expected. } }
public async Task If_batch_is_full_it_should_be_processed() { const int MAX_BATCH_CAPACITY = 2; var batcher = new SizedBatcher <string>(batch => { var j = string.Join(" ", batch.Items); return(new SuccessBatchResponse <string>(j)); }, MAX_BATCH_CAPACITY); var one = batcher.Add("one"); var two = batcher.Add("two"); var batchExecution = batcher.Query(one); await batchExecution.WaitForCompletion(); Assert.IsTrue(batchExecution.IsCompleted, "Execution should be completed!"); Assert.IsInstanceOf <SuccessBatchResponse <string> >(batchExecution.Result, "Result should be of type 'SuccessBatchResponse<string>'!"); var result = batchExecution.Result as SuccessBatchResponse <string>; Assert.AreEqual("one two", result.Value); }