Ejemplo n.º 1
0
        public void TimeoutSuppressTest()
        {
            TestState state = new TestState();

            state.Initialize("timeoutsuppress", 1, 0);
            state.Options.ReceiveTimeout = TimeSpan.FromSeconds(5.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 TimeoutEventHubClientFactoryMock(1);

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

            state.VerifyNormalStartup(10);

            Thread.Sleep(20000); // timeout is 5s, sleep 20s to allow some timeouts

            state.DoNormalShutdown(10);
            state.WaitRun();

            // EXPECTED RESULT: Normal processing. Because calls on receive timeout are suppressed, batches should be 0.
            Assert.True(state.Processor.TotalBatches == 0, $"ProcessEvents was called {state.Processor.TotalBatches} times");
            Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}");
            Assert.Null(state.ShutdownException);
        }
Ejemplo n.º 2
0
        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);
        }
        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);
        }
Ejemplo n.º 4
0
        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);
        }