Example #1
0
        /// <inheritdoc />
        public EventHubContentLocationEventStore(
            EventHubContentLocationEventStoreConfiguration configuration,
            IContentLocationEventHandler eventHandler,
            string localMachineName,
            CentralStorage centralStorage,
            Interfaces.FileSystem.AbsolutePath workingDirectory)
            : base(configuration, nameof(EventHubContentLocationEventStore), eventHandler, centralStorage, workingDirectory)
        {
            Contract.Requires(configuration.MaxEventProcessingConcurrency >= 1);
            _configuration    = configuration;
            _localMachineName = localMachineName;

            if (configuration.MaxEventProcessingConcurrency > 1)
            {
                _eventProcessingBlocks =
                    Enumerable.Range(1, configuration.MaxEventProcessingConcurrency)
                    .Select(
                        _ =>
                {
                    var serializer = new ContentLocationEventDataSerializer(configuration.SelfCheckSerialization ? ValidationMode.Trace : ValidationMode.Off);
                    return(new ActionBlock <ProcessEventsInput>(
                               t => ProcessEventsCoreAsync(t, serializer),
                               new ExecutionDataflowBlockOptions()
                    {
                        MaxDegreeOfParallelism = 1,
                        BoundedCapacity = configuration.EventProcessingMaxQueueSize,
                    }));
                })
                    .ToArray();
            }
        }
Example #2
0
 /// <inheritdoc />
 public MemoryContentLocationEventStore(
     MemoryContentLocationEventStoreConfiguration configuration,
     IContentLocationEventHandler handler,
     CentralStorage centralStorage,
     Interfaces.FileSystem.AbsolutePath workingDirectory)
     : base(configuration, nameof(MemoryContentLocationEventStore), handler, centralStorage, workingDirectory)
 {
     _hub          = configuration.Hub;
     _hub.OnEvent += HubOnEvent;
 }
Example #3
0
 public SlowedEventHubContentLocationEventStore(
     ContentLocationEventStoreConfiguration configuration,
     IContentLocationEventHandler eventHandler,
     string localMachineName,
     CentralStorage centralStorage,
     AbsolutePath workingDirectory)
     : base(configuration, eventHandler, localMachineName, centralStorage, workingDirectory)
 {
     Contract.Requires(configuration is SlowedContentLocationEventStoreConfiguration);
     _configuration = (configuration as SlowedContentLocationEventStoreConfiguration) !;
 }
Example #4
0
 private static ContentLocationEventStore CreateEventStore(
     ContentLocationEventStoreConfiguration configuration,
     IContentLocationEventHandler eventHandler,
     string localMachineName,
     LocalDiskCentralStorage centralStorage,
     DisposableDirectory eventHubWorkingDirectory)
 {
     return(configuration switch
     {
         SlowedContentLocationEventStoreConfiguration _ =>
         new SlowedEventHubContentLocationEventStore(configuration, eventHandler, localMachineName, centralStorage, eventHubWorkingDirectory.Path),
         _ =>
         ContentLocationEventStore.Create(configuration, eventHandler, localMachineName, centralStorage, eventHubWorkingDirectory.Path),
     });
Example #5
0
        private async Task WithContentLocationEventStore(Func <Context, IClock, IAbsFileSystem, ContentLocationEventStore, Task> action, ContentLocationEventStoreConfiguration configuration, IContentLocationEventHandler eventHandler, string localMachineName = "Worker")
        {
            string centralStateKeyBase = "ThisIsUnused";

            var clock = new MemoryClock();

            using var fileSystem = new PassThroughFileSystem(TestGlobal.Logger);
            var tracingContext = new Context(TestGlobal.Logger);

            {
                using var localDiskCentralStoreWorkingDirectory = new DisposableDirectory(fileSystem);
                var localDiskCentralStoreConfiguration = new LocalDiskCentralStoreConfiguration(localDiskCentralStoreWorkingDirectory.Path, centralStateKeyBase);
                var centralStorage = new LocalDiskCentralStorage(localDiskCentralStoreConfiguration);

                {
                    using var eventHubWorkingDirectory = new DisposableDirectory(fileSystem);
                    var eventStore = CreateEventStore(configuration, eventHandler, localMachineName, centralStorage, eventHubWorkingDirectory, clock);

                    (await eventStore.StartupAsync(tracingContext)).ShouldBeSuccess();
                    await action(tracingContext, clock, fileSystem, eventStore);

                    if (!eventStore.ShutdownStarted)
                    {
                        (await eventStore.ShutdownAsync(tracingContext)).ShouldBeSuccess();
                    }
                }
            }
        }