public void TransientEventHubReceiveFailure() { TestState state = new TestState(); state.Initialize("TransientEventHubReceiveFailure", 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 error = new EventHubsException(true, "ErrorInjector"); NeverEHErrorInjector injector = new NeverEHErrorInjector(EHErrorLocation.Receiving, error); sfp.EventHubClientFactory = new InjectorEventHubClientFactoryMock(1, injector); state.PrepareToRun(); state.StartRun(sfp); state.VerifyNormalStartup(10); int batchesAlreadyDone = state.CountNBatches(20, 10); Assert.True(EventHubMocks.PartitionReceiverMock.receivers.ContainsKey(InjectorEventHubClientFactoryMock.Tag), "Cannot find receiver"); InjectorPartitionReceiverMock testReceiver = (InjectorPartitionReceiverMock) EventHubMocks.PartitionReceiverMock.receivers[InjectorEventHubClientFactoryMock.Tag]; const int errorCount = 10; for (int i = 0; i < errorCount; i++) { testReceiver.ForceReceiveError(error); Thread.Sleep(100); } state.CountNBatches(batchesAlreadyDone * 2, 10); state.DoNormalShutdown(10); state.WaitRun(); // EXPECTED RESULT: Processing should happen normally but errors reported. Assert.True(state.Processor.TotalBatches >= 20, $"Run ended at {state.Processor.TotalBatches} batches"); Assert.True(state.Processor.TotalErrors == errorCount, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); }
public void CloseException() { TestState state = new TestState(); state.Initialize("CloseException", 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; sfp.EventHubClientFactory = new EventHubMocks.EventHubClientFactoryMock(1); state.PrepareToRun(); state.Processor.Injector = new TestProcessor.ErrorInjector(TestProcessor.ErrorLocation.OnClose, new NotImplementedException("ErrorInjector")); state.StartRun(sfp); state.VerifyNormalStartup(10); state.CountNBatches(20, 10); state.TokenSource.Cancel(); // EXPECTED RESULT: Failure is traced but otherwise ignored. state.WaitRun(); Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); }
public void SimpleOptionsTest() { TestState state = new TestState(); state.Initialize("SimpleOptions", 1, 0); const int testBatchSize = 42; Assert.False(state.Options.MaxBatchSize == testBatchSize); // make sure new value is not the same as the default state.Options.MaxBatchSize = testBatchSize; const int testPrefetchCount = 444; Assert.False(state.Options.PrefetchCount == testPrefetchCount); state.Options.PrefetchCount = testPrefetchCount; TimeSpan testReceiveTimeout = TimeSpan.FromSeconds(10.0); Assert.False(state.Options.ReceiveTimeout.Equals(testReceiveTimeout)); state.Options.ReceiveTimeout = testReceiveTimeout; ReceiverOptions receiverOptions = new ReceiverOptions(); Assert.Null(receiverOptions.Identifier); const string tag = "SimpleOptions"; receiverOptions.Identifier = tag; state.Options.ClientReceiverOptions = receiverOptions; ServiceFabricProcessor sfp = new ServiceFabricProcessor( state.ServiceUri, state.ServicePartitionId, state.StateManager, state.StatefulServicePartition, state.Processor, state.ConnectionString, "$Default", state.Options); sfp.MockMode = state.PartitionLister; sfp.EventHubClientFactory = new EventHubMocks.EventHubClientFactoryMock(1, tag); state.PrepareToRun(); state.StartRun(sfp); state.VerifyNormalStartup(10); state.CountNBatches(5, 10); // EXPECTED RESULT: Normal processing. Validate that simple options MaxBatchSize, PrefetchCount, ReceiveTimeout, // and ClientReceiverOptions are passed through to EH API. Assert.True(EventHubMocks.PartitionReceiverMock.receivers.ContainsKey(tag), "Cannot find receiver"); EventHubMocks.PartitionReceiverMock testReceiver = EventHubMocks.PartitionReceiverMock.receivers[tag]; Assert.True(testReceiver.HandlerBatchSize == testBatchSize, $"Unexpected batch size {testReceiver.HandlerBatchSize}"); Assert.True(testReceiver.PrefetchCount == testPrefetchCount, $"Unexpected prefetch count {testReceiver.PrefetchCount}"); Assert.True(testReceiver.ReceiveTimeout.Equals(testReceiveTimeout), $"Unexpected receive timeout {testReceiver.ReceiveTimeout}"); Assert.NotNull(testReceiver.Options); Assert.Equal(testReceiver.Options.Identifier, tag); // EnableReceiverRuntimeMetric is false by default. This case is a convenient opportunity to // verify that RuntimeInformation was not updated when the option is false. Assert.True(state.Processor.LatestContext.RuntimeInformation.LastSequenceNumber == -1L, $"RuntimeInformation.LastSequenceNumber is {state.Processor.LatestContext.RuntimeInformation.LastSequenceNumber}"); state.DoNormalShutdown(10); state.WaitRun(); Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); }
private void EventHubReceiveFailure(string name, Exception error, bool isEventHubsException) { TestState state = new TestState(); state.Initialize(name + "EventHubReceiveFailure", 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; NeverEHErrorInjector injector = new NeverEHErrorInjector(EHErrorLocation.Receiving, error); sfp.EventHubClientFactory = new InjectorEventHubClientFactoryMock(1, injector); state.PrepareToRun(); state.StartRun(sfp); state.VerifyNormalStartup(10); state.CountNBatches(20, 10); Assert.True(EventHubMocks.PartitionReceiverMock.receivers.ContainsKey(InjectorEventHubClientFactoryMock.Tag), "Cannot find receiver"); InjectorPartitionReceiverMock testReceiver = (InjectorPartitionReceiverMock) EventHubMocks.PartitionReceiverMock.receivers[InjectorEventHubClientFactoryMock.Tag]; testReceiver.ForceReceiveError(error); // EXPECTED RESULT: RunAsync will throw (Task completed exceptionally) // due to nontransient EventHubsException or other exception type from 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 inner = ae.InnerExceptions[0]; if (isEventHubsException) { Assert.True(inner is EventHubsException, $"Unexpected inner exception type {inner.GetType().Name}"); Assert.False(((EventHubsException)inner).IsTransient, "Inner exception is transient"); } else { Assert.True(inner is Exception, $"Unexpected inner exception type {inner.GetType().Name}"); } Assert.Contains("ErrorInjector", inner.Message); } }
public void TimeoutInvokeTest() { TestState state = new TestState(); state.Initialize("timeoutinvoke", 1, 0); state.Options.ReceiveTimeout = TimeSpan.FromMilliseconds(10); state.Options.InvokeProcessorAfterReceiveTimeout = true; ServiceFabricProcessor sfp = new ServiceFabricProcessor( state.ServiceUri, state.ServicePartitionId, state.StateManager, state.StatefulServicePartition, state.Processor, state.ConnectionString, "$Default", state.Options) { MockMode = state.PartitionLister, EventHubClientFactory = new TimeoutEventHubClientFactoryMock(1) }; state.PrepareToRun(); state.StartRun(sfp); state.VerifyNormalStartup(10); state.CountNBatches(1, 10); state.DoNormalShutdown(10); state.WaitRun(); // EXPECTED RESULT: Normal processing. Calls on receive timeout are enabled, so batches should be nonzero. Assert.True(state.Processor.TotalBatches > 0, "ProcessEvents was not called"); Assert.True(state.Processor.TotalEvents == 0, $"ProcessEvents got {state.Processor.TotalEvents} events"); Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); }