Exemple #1
0
        public async Task TransientErrorInSecondBatch_OverwritesNonTransientFailureDetails()
        {
            var batchSize = 10;

            Core.IMessageConverter <IRoutingMessage> routingMessageConverter = new RoutingMessageConverter();
            string cloudEndpointId = Guid.NewGuid().ToString();

            var cloudProxy = ThrowingCloudProxy
                             .CreateWithResponses(3, ThrowingCloudProxy.Success())
                             .Then(ThrowingCloudProxy.Throw <Exception>())                         // non-transient error
                             .ThenMany(batchSize - 4, ThrowingCloudProxy.Success())                // first batch ends here (3 success + 1 fail -> 10 - 4 to go)
                             .ThenMany(3, ThrowingCloudProxy.Success())
                             .Then(ThrowingCloudProxy.Throw <Client.Exceptions.IotHubException>()) // transient error
                             .ThenMany(batchSize - 4, ThrowingCloudProxy.Success())                // second batch ends here
                             .ThenMany(1 * batchSize, ThrowingCloudProxy.Success())
                             .Build();

            Task <Option <ICloudProxy> > GetCloudProxy(string id) => Task.FromResult(Option.Some(cloudProxy));

            var        cloudEndpoint         = new CloudEndpoint(cloudEndpointId, GetCloudProxy, routingMessageConverter);
            IProcessor cloudMessageProcessor = cloudEndpoint.CreateProcessor();

            var sinkResult = await cloudMessageProcessor.ProcessAsync(GetMessages("device1", 3 * batchSize), CancellationToken.None);

            Assert.False(sinkResult.IsSuccessful);
            Assert.Equal(batchSize, sinkResult.Succeeded.Count);
            Assert.Equal(batchSize, sinkResult.Failed.Count);
            Assert.Equal(batchSize, sinkResult.InvalidDetailsList.Count);
            Assert.True(sinkResult.SendFailureDetails.HasValue);
            Assert.Equal(FailureKind.Transient, sinkResult.SendFailureDetails.Expect(() => new Exception()).FailureKind);
        }
Exemple #2
0
        public async Task NoErrorFromCloudProxy_NoErrorDetailsReturned()
        {
            var batchSize = 10;

            Core.IMessageConverter <IRoutingMessage> routingMessageConverter = new RoutingMessageConverter();
            string cloudEndpointId = Guid.NewGuid().ToString();

            var cloudProxy = ThrowingCloudProxy
                             .CreateWithResponses(30, ThrowingCloudProxy.Success())
                             .Build();

            Task <Option <ICloudProxy> > GetCloudProxy(string id) => Task.FromResult(Option.Some(cloudProxy));

            var        cloudEndpoint         = new CloudEndpoint(cloudEndpointId, GetCloudProxy, routingMessageConverter, batchSize);
            IProcessor cloudMessageProcessor = cloudEndpoint.CreateProcessor();

            var sinkResult = await cloudMessageProcessor.ProcessAsync(GetMessages("device1", 3 * batchSize), CancellationToken.None);

            Assert.True(sinkResult.IsSuccessful);
            Assert.Equal(3 * batchSize, sinkResult.Succeeded.Count);
            Assert.Equal(0, sinkResult.Failed.Count);
            Assert.Equal(0, sinkResult.InvalidDetailsList.Count);
            Assert.Equal(Option.None <SendFailureDetails>(), sinkResult.SendFailureDetails);
        }