public void CheckpointEventTest() { TestState state = new TestState(); state.Initialize("checkpointing", 1, 0); const long checkpointAt = 57L; state.Processor = new CheckpointingProcessor(state.Options, checkpointAt); 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.StartRun(sfp); state.RunForNBatches(20, 10); state.WaitRun(); // EXPECTED RESULT: Normal processing. This case checkpoints specific events. Validate that the // last event processed has a higher sequence number than the checkpointed event. Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); EventData checkpointedEvent = ((CheckpointingProcessor)state.Processor).CheckpointedEvent; Assert.NotNull(checkpointedEvent); Assert.True(checkpointedEvent.SystemProperties.SequenceNumber == checkpointAt, $"Checkpointed event has seq {checkpointedEvent.SystemProperties.SequenceNumber}, expected {checkpointAt}"); EventData lastEvent = state.Processor.LastEvent; Assert.NotNull(lastEvent); Assert.True(lastEvent.SystemProperties.SequenceNumber > checkpointedEvent.SystemProperties.SequenceNumber, $"Unexpected sequence number {lastEvent.SystemProperties.SequenceNumber}"); state.Processor = new CheckpointingProcessor(state.Options); 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.StartRun(sfp); state.RunForNBatches(1, 10); state.WaitRun(); // EXPECTED RESULT: Normal processing. The sequence number of the first event processed in // this stage should be one higher than the sequence number of the event checkpointed in // the previous stage. Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); EventData restartEvent = ((CheckpointingProcessor)state.Processor).FirstEvent; Assert.NotNull(restartEvent); Assert.True((restartEvent.SystemProperties.SequenceNumber - checkpointedEvent.SystemProperties.SequenceNumber) == 1, $"Unexpected change in sequence number from {checkpointedEvent.SystemProperties.SequenceNumber} to {restartEvent.SystemProperties.SequenceNumber}"); }
public void CheckpointBatchTest() { TestState state = new TestState(); state.Initialize("checkpointing", 1, 0); state.Processor = new CheckpointingProcessor(state.Options); 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.StartRun(sfp); state.RunForNBatches(20, 10); state.WaitRun(); // EXPECTED RESULT: Normal processing. Last event processed is also the end of the batch // and hence the final checkpoint. Save for next stage validaiton. Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); EventData checkpointedEvent = state.Processor.LastEvent; Assert.NotNull(checkpointedEvent); Assert.True(checkpointedEvent.SystemProperties.SequenceNumber > 0L, $"Unexpected sequence number {checkpointedEvent.SystemProperties.SequenceNumber}"); state.Processor = new CheckpointingProcessor(state.Options); 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.StartRun(sfp); state.RunForNBatches(1, 10); state.WaitRun(); // EXPECTED RESULT: Normal processing. The sequence number of the first event processed in // this stage should be one higher than the sequence number of the last event processed in // the previous stage. Assert.True(state.Processor.TotalErrors == 0, $"Errors found {state.Processor.TotalErrors}"); Assert.Null(state.ShutdownException); EventData restartEvent = ((CheckpointingProcessor)state.Processor).FirstEvent; Assert.NotNull(restartEvent); Assert.True((restartEvent.SystemProperties.SequenceNumber - checkpointedEvent.SystemProperties.SequenceNumber) == 1, $"Unexpected change in sequence number from {checkpointedEvent.SystemProperties.SequenceNumber} to {restartEvent.SystemProperties.SequenceNumber}"); }
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 == 0L, $"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); }