public void TestDispatchEvent() { var logEvent = new LogEvent("", new Dictionary <string, object> { { "accountId", "1234" }, { "projectId", "9876" }, { "visitorId", "testUser" } }, "POST", new Dictionary <string, string> { { "Content-Type", "application/json" } }); var expectionedOptions = new Dictionary <string, object> { { "headers", logEvent.Headers }, { "json", logEvent.Params }, { "timeout", 10 }, { "connect_timeout", 10 } }; //TODO: Have to mock http calls. Will discuss with Randall. var eventDispatcher = new DefaultEventDispatcher(new Mock <ILogger>().Object); }
public static Optimizely NewDefaultInstance(string sdkKey, string fallback) { var logger = OptimizelyLogger ?? new DefaultLogger(); var errorHandler = new DefaultErrorHandler(); var eventDispatcher = new DefaultEventDispatcher(logger); var builder = new HttpProjectConfigManager.Builder(); var notificationCenter = new NotificationCenter(); var configManager = builder .WithSdkKey(sdkKey) .WithDatafile(fallback) .WithLogger(logger) .WithErrorHandler(errorHandler) .WithNotificationCenter(notificationCenter) .Build(true); EventProcessor eventProcessor = null; #if !NETSTANDARD1_6 && !NET35 eventProcessor = new BatchEventProcessor.Builder() .WithLogger(logger) .WithMaxBatchSize(MaxEventBatchSize) .WithFlushInterval(MaxEventFlushInterval) .WithEventDispatcher(eventDispatcher) .WithNotificationCenter(notificationCenter) .Build(); #endif return(NewDefaultInstance(configManager, notificationCenter, eventDispatcher, errorHandler, logger, eventProcessor: eventProcessor)); }
public void PushingWithNoTargetsShouldThrow() { var eventDispatcher = new DefaultEventDispatcher(); var loggingEvent = new LoggingEvent { Text = "Event" }; Executing.This(() => eventDispatcher.Push(loggingEvent, false)).Should().Throw<InvalidOperationException>(); }
public static Optimizely NewDefaultInstance() { var logger = OptimizelyLogger ?? new DefaultLogger(); OptimizelySDKConfigSection OptlySDKConfigSection = null; try { OptlySDKConfigSection = ConfigurationManager.GetSection(ConfigSectionName) as OptimizelySDKConfigSection; } catch (ConfigurationErrorsException ex) { logger.Log(LogLevel.ERROR, "Invalid App.Config. Unable to initialize optimizely instance" + ex.Message); return(null); } HttpProjectConfigElement httpProjectConfigElement = OptlySDKConfigSection.HttpProjectConfig; if (httpProjectConfigElement == null) { return(null); } var errorHandler = new DefaultErrorHandler(logger, false); var eventDispatcher = new DefaultEventDispatcher(logger); var builder = new HttpProjectConfigManager.Builder(); var notificationCenter = new NotificationCenter(); var configManager = builder .WithSdkKey(httpProjectConfigElement.SDKKey) .WithUrl(httpProjectConfigElement.Url) .WithFormat(httpProjectConfigElement.Format) .WithPollingInterval(TimeSpan.FromMilliseconds(httpProjectConfigElement.PollingInterval)) .WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(httpProjectConfigElement.BlockingTimeOutPeriod)) #if !NET40 && !NET35 .WithAccessToken(httpProjectConfigElement.DatafileAccessToken) #endif .WithLogger(logger) .WithErrorHandler(errorHandler) .WithNotificationCenter(notificationCenter) .Build(true); EventProcessor eventProcessor = null; var batchEventProcessorElement = OptlySDKConfigSection.BatchEventProcessor; if (batchEventProcessorElement == null) { return(null); } eventProcessor = new BatchEventProcessor.Builder() .WithMaxBatchSize(batchEventProcessorElement.BatchSize) .WithFlushInterval(TimeSpan.FromMilliseconds(batchEventProcessorElement.FlushInterval)) .WithTimeoutInterval(TimeSpan.FromMilliseconds(batchEventProcessorElement.TimeoutInterval)) .WithLogger(logger) .WithEventDispatcher(eventDispatcher) .WithNotificationCenter(notificationCenter) .Build(); return(NewDefaultInstance(configManager, notificationCenter, eventDispatcher, errorHandler, logger, eventProcessor: eventProcessor)); }
public void TestEventProcessorWithBatchEventProcessorObj() { var eventDispatcher = new DefaultEventDispatcher(LoggerMock.Object); var notificationCenter = new NotificationCenter(); var projectConfigManager = new HttpProjectConfigManager.Builder() .WithSdkKey("10192104166") .Build(true); var batchEventProcessor = new BatchEventProcessor.Builder() .WithLogger(LoggerMock.Object) .WithMaxBatchSize(20) .WithFlushInterval(TimeSpan.FromSeconds(3)) .WithEventDispatcher(eventDispatcher) .WithNotificationCenter(notificationCenter) .Build(); var optimizely = OptimizelyFactory.NewDefaultInstance(projectConfigManager, notificationCenter, eventProcessor: batchEventProcessor); var actualbatchEventProcessor = Reflection.GetFieldValue <BatchEventProcessor, Optimizely>(optimizely, "EventProcessor"); var actualEventProcessorProps = new EventProcessorProps(actualbatchEventProcessor); var expectedEventProcessorProps = new EventProcessorProps(batchEventProcessor); Assert.AreEqual(actualEventProcessorProps, expectedEventProcessorProps); optimizely.Dispose(); }
public void HandlerShouldBeExecuted() { var handlerExecuted = false; var dispatcher = new DefaultEventDispatcher(); var actions = new List<Action<EventContext<SampleDomainEvent>>>(); actions.Add(new Action<EventContext<SampleDomainEvent>>(e => handlerExecuted = true)); dispatcher.Dispatch<SampleDomainEvent>(actions, new SampleDomainEvent()); Assert.IsTrue(handlerExecuted); }
public void HandlerShouldBeExecuted() { var handlerExecuted = false; var dispatcher = new DefaultEventDispatcher(); var actions = new List <Action <EventContext <SampleDomainEvent> > >(); actions.Add(new Action <EventContext <SampleDomainEvent> >(e => handlerExecuted = true)); dispatcher.Dispatch <SampleDomainEvent>(actions, new SampleDomainEvent()); Assert.IsTrue(handlerExecuted); }
public void CanPushToDefaultTargets() { var target1Mock = new Mock<ITarget>(); var target2Mock = new Mock<ITarget>(); var eventDispatcher = new DefaultEventDispatcher { DefaultTargets = new[] { target1Mock.Object, target2Mock.Object } }; var loggingEvent = new LoggingEvent { Text = "Event" }; eventDispatcher.Push(loggingEvent, false); target1Mock.Verify(o => o.Log(loggingEvent)); target2Mock.Verify(o => o.Log(loggingEvent)); }
public void CanAddAndPushToTargets() { var target1Mock = new Mock<ITarget>(); var target2Mock = new Mock<ITarget>(); var eventDispatcher = new DefaultEventDispatcher(); eventDispatcher.AddTarget(target1Mock.Object); eventDispatcher.AddTarget(target2Mock.Object); var loggingEvent = new LoggingEvent { Text = "Event" }; eventDispatcher.Push(loggingEvent, false); target1Mock.Verify(o => o.Log(loggingEvent)); target2Mock.Verify(o => o.Log(loggingEvent)); }
public void CanPushToTargets() { var target1Mock = new Mock<Target>(); var target2Mock = new Mock<Target>(); var configuration = new PulsusConfiguration(); configuration.AddTarget("1", target1Mock.Object); configuration.AddTarget("2", target2Mock.Object); var eventDispatcher = new DefaultEventDispatcher(configuration); var loggingEvent = new LoggingEvent { Text = "Event" }; var loggingEvents = new[] { loggingEvent }; eventDispatcher.Push(loggingEvents); target1Mock.Verify(o => o.Push(loggingEvents)); target2Mock.Verify(o => o.Push(loggingEvents)); }
public void Event_Complying_With_Level_Filters_Should_Be_Pushed() { var targetMock = new Mock<Target>(); targetMock.SetupGet(x => x.MinLevel).Returns(LoggingEventLevel.Warning); targetMock.SetupGet(x => x.MaxLevel).Returns(LoggingEventLevel.Error); var loggingEvent = new LoggingEvent() { Level = LoggingEventLevel.Error }; var configuration = new PulsusConfiguration(); configuration.AddTarget("1", targetMock.Object); var eventDispatcher = new DefaultEventDispatcher(configuration); eventDispatcher.Push(new[] { loggingEvent }); targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Once); }
public void Register(IContainerManager containerManager, CMS.Common.Runtime.ITypeFinder typeFinder) { var assemblies = typeFinder.GetAssemblies() .Where(x => !IsIgnoredAssembly(x)) .ToList(); // Handler Registry var handlerRegistry = new DefaultEventHandlerRegistry(); handlerRegistry.RegisterAssemblies(assemblies); containerManager.AddComponentInstance<IEventHandlerRegistry>(handlerRegistry); // Event Registry var eventRegistry = new DefaultEventRegistry(); eventRegistry.RegisterAssemblies(assemblies); containerManager.AddComponentInstance<IEventRegistry>(eventRegistry); // Event Dispatcher var eventDispatcher = new DefaultEventDispatcher(handlerRegistry); containerManager.AddComponentInstance<IEventDispatcher>(eventDispatcher); }
// TODO (Cameron): Consider how to handle disposable dependencies. public IEventDispatcher Create() { var defaultEventDispatcher = new DefaultEventDispatcher(this.views); if (typeof(DefaultEventDispatcher).Equals(this.eventDispatcherType)) { return(defaultEventDispatcher); } Func <long, IOrderedBuffer> bufferFactory = number => typeof(OrderedBuffer).Equals(this.bufferType) ? new OrderedBuffer(number) : new IntelligentOrderedBuffer(number, this.eventResolver, this.publisherTimeout, this.consumerTimeout); if (this.eventDispatcherType.Equals(typeof(OrderedEventDispatcher))) { return(new OrderedEventDispatcher(defaultEventDispatcher, sequenceResolver, bufferFactory(this.sequenceNumber))); } return(new ManagedEventDispatcher(this.views, this.sequenceResolver, this.sequenceRepository, bufferFactory, 1000)); }
public void Event_Matching_LogKeyStartsWith_Ignore_Filter_Should_Be_Ignored() { var targetMock = new Mock<Target>(); targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>() { new Ignore() { LogKeyStartsWith = "Sample." } }); var loggingEvent = new LoggingEvent() { LogKey = "Sample.LogKey" }; var configuration = new PulsusConfiguration(); configuration.AddTarget("1", targetMock.Object); var eventDispatcher = new DefaultEventDispatcher(configuration); eventDispatcher.Push(new[] { loggingEvent }); targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never); }
public void MultipleHandlersShouldBeExecutedSequentially() { var dispatcher = new DefaultEventDispatcher(); var actions = new List <Action <EventContext <SampleDomainEvent> > >(); var log = new List <string>(); // 1st handler actions.Add(new Action <EventContext <SampleDomainEvent> >(e => { log.Add("1st handler"); })); // 2nd handler actions.Add(new Action <EventContext <SampleDomainEvent> >(e => { log.Add("2nd handler"); })); dispatcher.Dispatch <SampleDomainEvent>(actions, new SampleDomainEvent()); Assert.AreEqual <int>(2, log.Count); Assert.AreEqual <string>("1st handler", log[0]); Assert.AreEqual <string>("2nd handler", log[1]); }
public void MultipleHandlersShouldBeExecutedSequentially() { var dispatcher = new DefaultEventDispatcher(); var actions = new List<Action<EventContext<SampleDomainEvent>>>(); var log = new List<string>(); // 1st handler actions.Add(new Action<EventContext<SampleDomainEvent>>(e => { log.Add("1st handler"); })); // 2nd handler actions.Add(new Action<EventContext<SampleDomainEvent>>(e => { log.Add("2nd handler"); })); dispatcher.Dispatch<SampleDomainEvent>(actions, new SampleDomainEvent()); Assert.AreEqual<int>(2, log.Count); Assert.AreEqual<string>("1st handler", log[0]); Assert.AreEqual<string>("2nd handler", log[1]); }
public void Event_Matching_TextContains_Ignore_Filter_Should_Be_Ignored() { var targetMock = new Mock<Target>(); targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>() { new Ignore() { TextContains = "description" } }); var loggingEvent = new LoggingEvent() { Text = "A description of the error" }; var configuration = new PulsusConfiguration(); configuration.AddTarget("1", targetMock.Object); var eventDispatcher = new DefaultEventDispatcher(configuration); eventDispatcher.Push(new[] { loggingEvent }); targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never); }
public void Event_Matching_TagContains_Ignore_Should_Be_Ignored() { var targetMock = new Mock<Target>(); targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>() { new Ignore() { TagsContains = "tag2" } }); var loggingEvent = new LoggingEvent() { Tags = new List<string>() { "tag1", "tag2", "tag3", "tag4" } }; var configuration = new PulsusConfiguration(); configuration.AddTarget("1", targetMock.Object); var eventDispatcher = new DefaultEventDispatcher(configuration); eventDispatcher.Push(new[] { loggingEvent }); targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never); }