public SingleFileMuxer( [NotNull] IEventsWriterProviderFactory writerProviderFactory, [NotNull] ISingleFileWorker worker, [NotNull] FileLogSettings settings) { this.settings = settings; this.worker = worker; writerProvider = writerProviderFactory.CreateProvider(settings.FilePath, () => this.settings); eventsQueue = new Lazy <ConcurrentBoundedQueue <LogEventInfo> >( () => new ConcurrentBoundedQueue <LogEventInfo>(settings.EventsQueueCapacity), LazyThreadSafetyMode.ExecutionAndPublication); eventsBuffer = new Lazy <LogEventInfo[]>( () => new LogEventInfo[settings.EventsBufferCapacity], LazyThreadSafetyMode.ExecutionAndPublication); eventsLostCurrently = new AtomicLong(0); eventsLostSinceLastIteration = new AtomicLong(0); flushSignal = new AsyncManualResetEvent(true); flushWaiters = new List <Waiter>(); workerInitLock = new object(); workerCancellationWaiter = new Waiter(TaskCreationOptions.RunContinuationsAsynchronously); workerCancellation = new CancellationTokenSource(); workerCancellation.Token.Register(() => workerCancellationWaiter.TrySetResult(true)); }
public void TryAdd_should_wait_for_buffer_space_if_specified() { singleFileWorker = new SingleFileWorker(); muxer = new SingleFileMuxer(writerProviderFactory, singleFileWorker, new FileLogSettings { WaitIfQueueIsFull = true, EventsQueueCapacity = 1 }); for (var i = 0; i < 10; i++) { muxer.TryAdd(CreateEventInfo(), false).Should().BeTrue(); } muxer.Dispose(); eventsWriter.Received(10) .WriteEvents( Arg.Any <LogEventInfo[]>(), Arg.Is(1)); }
public void TestSetup() { eventsWriter = Substitute.For <IEventsWriter>(); eventsWriterProvider = Substitute.For <IEventsWriterProvider>(); eventsWriterProvider.ObtainWriterAsync(Arg.Any <CancellationToken>()).Returns(Task.FromResult(eventsWriter)); writerProviderFactory = Substitute.For <IEventsWriterProviderFactory>(); writerProviderFactory.CreateProvider(Arg.Any <FilePath>(), Arg.Do <Func <FileLogSettings> >(x => settingsInsideMuxer = x)).Returns(eventsWriterProvider); singleFileWorker = Substitute.For <ISingleFileWorker>(); singleFileWorker.WritePendingEventsAsync( Arg.Any <IEventsWriterProvider>(), Arg.Any <ConcurrentBoundedQueue <LogEventInfo> >(), Arg.Any <LogEventInfo[]>(), Arg.Any <AtomicLong>(), Arg.Any <AtomicLong>(), Arg.Any <CancellationToken>()) .Returns(Task.FromResult(true)); muxer = new SingleFileMuxer(writerProviderFactory, singleFileWorker, new FileLogSettings()); }