public void HardEventHubClientClosingFailure()
        {
            Exception             injectee = new Exception("ErrorInjector");
            AlwaysEHErrorInjector injector = new AlwaysEHErrorInjector(EHErrorLocation.EventHubClientClosing, injectee);

            NoFailures("HardEventHubClientClosingFailure", injector);
        }
        void NontransientEventHubClientClosingFailure()
        {
            EventHubsException    injectee = new EventHubsException(false, "ErrorInjector");
            AlwaysEHErrorInjector injector = new AlwaysEHErrorInjector(EHErrorLocation.EventHubClientClosing, injectee);

            NoFailures("NontransientEventHubClientClosingFailure", injector);
        }
        public void HardReceiverClosingFailure()
        {
            Exception             injectee = new Exception("ErrorInjector");
            AlwaysEHErrorInjector injector = new AlwaysEHErrorInjector(EHErrorLocation.ReceiverClosing, injectee);

            NoFailures("HardReceiverClosingFailure", injector);
        }
        public void HardTransientReceiverClosingFailure()
        {
            EventHubsException    injectee = new EventHubsException(true, "ErrorInjector");
            AlwaysEHErrorInjector injector = new AlwaysEHErrorInjector(EHErrorLocation.ReceiverClosing, injectee);

            NoFailures("HardTransientReceiverClosingFailure", injector);
        }
        private void HardTransientStartupFailure(string name, EHErrorLocation location)
        {
            TestState state = new TestState();

            state.Initialize("HardTransient" + name + "Failure", 1, 0);

            ServiceFabricProcessor sfp = new ServiceFabricProcessor(
                state.ServiceUri,
                state.ServicePartitionId,
                state.StateManager,
                state.StatefulServicePartition,
                state.Processor,
                state.ConnectionString,
                "$Default",
                state.Options);

            sfp.MockMode = state.PartitionLister;
            EventHubsException    injectee = new EventHubsException(true, "ErrorInjector");
            AlwaysEHErrorInjector injector = new AlwaysEHErrorInjector(location, injectee);

            sfp.EventHubClientFactory = new InjectorEventHubClientFactoryMock(1, injector);

            state.PrepareToRun();
            state.StartRun(sfp);

            // EXPECTED RESULT: RunAsync will throw (Task completed exceptionally) during startup
            // after running out of retries on an EH operation.
            // The Wait call bundles the exception into an AggregateException and rethrows.
            state.OuterTask.Wait();
            try
            {
                state.SFPTask.Wait();
            }
            catch (AggregateException ae)
            {
                Assert.True(ae.InnerExceptions.Count == 1, $"Unexpected number of errors {ae.InnerExceptions.Count}");
                Exception inner1 = ae.InnerExceptions[0];
                Assert.True(inner1 is Exception, $"Unexpected inner exception type {inner1.GetType().Name}");
                Assert.StartsWith("Out of retries ", inner1.Message);
                Assert.NotNull(inner1.InnerException);
                Exception inner2 = inner1.InnerException;
                Assert.True(inner2 is EventHubsException, $"Unexpected inner exception type {inner2.GetType().Name}");
                Assert.True(((EventHubsException)inner2).IsTransient, "Inner exception is not transient");
                Assert.Equal("ErrorInjector", inner2.Message);
            }
        }