public void EventLoggingInterceptorDoesNotBreakProcessingChain() { var eventLoggingInterceptor = new DefaultEventLoggingInterceptor(_logFactory); var simpleEventInterceptor = new EventSimpleInterceptor(); using (var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null) } }))) { using (var engine = new CqrsEngine( _logFactory, messagingEngine, Register.DefaultEndpointResolver(new InMemoryEndpointResolver()), Register.EventInterceptors(eventLoggingInterceptor, simpleEventInterceptor), Register.Saga <TestSaga>("test1") .ListeningEvents(typeof(string)).From("lykke-wallet").On("lykke-wallet-events"))) { engine.StartSubscribers(); messagingEngine.Send("1", new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json)); Thread.Sleep(1000); Assert.True(simpleEventInterceptor.Intercepted); } } }
public void CommandLoggingInterceptorDoesNotBreakProcessingChain() { var commandLoggingInterceptor = new DefaultCommandLoggingInterceptor(_logFactory); var commandSimpleInterceptor = new CommandSimpleInterceptor(); var commandsHandler = new CommandsHandler(); using (var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null) } }))) { using (var engine = new CqrsEngine( _logFactory, messagingEngine, Register.DefaultEndpointResolver(new InMemoryEndpointResolver()), Register.CommandInterceptors(commandLoggingInterceptor, commandSimpleInterceptor), Register.BoundedContext("test1") .ListeningCommands(typeof(int)).On("lykke-wallet-events") .WithCommandsHandler(commandsHandler))) { engine.StartSubscribers(); messagingEngine.Send(1, new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json)); Thread.Sleep(1000); Assert.True(commandSimpleInterceptor.Intercepted); } } }
public void EventLoggingInterceptorTest() { int eventLoggedCount = 0; var eventLoggingInterceptor = new CustomEventLoggingInterceptor( _logFactory, new Dictionary <Type, EventLoggingDelegate> { { typeof(string), (l, h, e) => ++ eventLoggedCount } }); using (var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null) } }))) { using (var engine = new CqrsEngine( _logFactory, messagingEngine, Register.DefaultEndpointResolver(new InMemoryEndpointResolver()), Register.EventInterceptors(eventLoggingInterceptor), Register.Saga <TestSaga>("test1") .ListeningEvents(typeof(string)).From("lykke-wallet").On("lykke-wallet-events"))) { engine.StartSubscribers(); messagingEngine.Send("1", new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json)); Thread.Sleep(1000); Assert.True(eventLoggedCount > 0, "Event was not logged"); Assert.True(eventLoggedCount == 1, "Event was logged more than once"); } } }
public void EventLoggingInterceptorTestForDefaultLogging() { var eventLoggingInterceptor = new DefaultEventLoggingInterceptor(_logFactory); using (var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null) } }))) { using (var engine = new CqrsEngine( _logFactory, messagingEngine, Register.DefaultEndpointResolver(new InMemoryEndpointResolver()), Register.EventInterceptors(eventLoggingInterceptor), Register.Saga <TestSaga>("test1") .ListeningEvents(typeof(string)).From("lykke-wallet").On("lykke-wallet-events"))) { engine.StartSubscribers(); using (var writer = new StringWriter()) { var prevOut = Console.Out; Console.SetOut(writer); messagingEngine.Send("1", new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json)); Thread.Sleep(1000); Console.SetOut(prevOut); var output = writer.ToString(); Assert.IsFalse(output.IsNullOrEmpty(), "Event was not logged"); } } } }
public void SendToOverflowenQueueFailureTest() { ITransportResolver resolver = MockTransportResolver(); //Assumption: queue capacity is 1mb var halfMegabyteMessage = new string('a', 1 << 19); using (var engine = new MessagingEngine(resolver, new SonicTransportFactory())) { engine.SerializationManager.RegisterSerializer("fake", typeof(string), new FakeStringSerializer()); engine.Send(halfMegabyteMessage, new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake")); Exception exception = null; var t = new Thread(() => { try { engine.Send(halfMegabyteMessage, new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake")); } catch (Exception ex) { exception = ex; } }); t.Start(); Assert.That(t.Join(2000), Is.True, "Exception was not thrown when queue is overflowed"); Assert.That(exception, Is.Not.Null); Console.WriteLine(exception); } }
public void TwoSimpleCommandInterceptorsTest() { var commandSimpleInterceptorOne = new CommandSimpleInterceptor(); var commandSimpleInterceptorTwo = new CommandSimpleInterceptor(); var commandsHandler = new CommandsHandler(); using (var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null) } }))) { using (var engine = new CqrsEngine( _logFactory, messagingEngine, Register.DefaultEndpointResolver(new InMemoryEndpointResolver()), Register.CommandInterceptors(commandSimpleInterceptorOne, commandSimpleInterceptorTwo), Register.BoundedContext("swift-cashout") .ListeningCommands(typeof(int)).On("lykke-wallet-events") .WithCommandsHandler(commandsHandler))) { engine.StartSubscribers(); messagingEngine.Send(1, new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json)); Thread.Sleep(1000); Assert.True(commandSimpleInterceptorOne.Intercepted); Assert.True(commandSimpleInterceptorTwo.Intercepted); Assert.NotNull(commandSimpleInterceptorOne.InterceptionTimestamp); Assert.NotNull(commandSimpleInterceptorTwo.InterceptionTimestamp); Assert.True(commandSimpleInterceptorOne.InterceptionTimestamp < commandSimpleInterceptorTwo.InterceptionTimestamp); Assert.True(commandsHandler.HandledCommands.Count > 0); } } }
public void SendTest(string dest) { ITransportResolver resolver = MockTransportResolver(); using (var engine = new MessagingEngine(resolver, new SonicTransportFactory())) { engine.SerializationManager.RegisterSerializer("fake", typeof(string), new FakeStringSerializer()); using (engine.Subscribe <string>(new Endpoint(TransportConstants.TRANSPORT_ID1, dest), s => { })) { engine.Send(Guid.NewGuid().ToString(), new Endpoint(TransportConstants.TRANSPORT_ID1, dest)); Thread.Sleep(1000); } int i = 0; Stopwatch sw = Stopwatch.StartNew(); var done = new ManualResetEvent(false); using (engine.Subscribe <string>(new Endpoint(TransportConstants.TRANSPORT_ID1, dest), s => { if (Interlocked.Increment(ref i) == 2961) { done.Set(); } })) { var message = string.Join(",", Enumerable.Range(0, 100).Select(x => Guid.NewGuid().ToString())); while (!done.WaitOne(0)) { engine.Send(message, new Endpoint(TransportConstants.TRANSPORT_ID1, dest)); } } Console.WriteLine(sw.ElapsedMilliseconds); } }
public void EachDestinationIsSubscribedOnDedicatedThreadTest() { ITransportResolver resolver = MockTransportResolver(); using (var engine = new MessagingEngine(resolver, new SonicTransportFactory())){ engine.SerializationManager.RegisterSerializer("fake", typeof(string), new FakeStringSerializer()); var queue1MessagesThreadIds = new List <int>(); var queue2MessagesThreadIds = new List <int>(); using (engine.Subscribe <string>(new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake"), s => queue1MessagesThreadIds.Add(Thread.CurrentThread.ManagedThreadId))) using (engine.Subscribe <string>(new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE2, serializationFormat: "fake"), s => queue2MessagesThreadIds.Add(Thread.CurrentThread.ManagedThreadId))) { engine.Send("test", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake")); engine.Send("test", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE2, serializationFormat: "fake")); engine.Send("test", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake")); engine.Send("test", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE2, serializationFormat: "fake")); engine.Send("test", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake")); engine.Send("test", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE2, serializationFormat: "fake")); Thread.Sleep(1000); } Assert.That(queue1MessagesThreadIds.Distinct().Any(), Is.True, "Messages were not processed"); Assert.That(queue2MessagesThreadIds.Distinct().Any(), Is.True, "Messages were not processed"); Assert.That(queue1MessagesThreadIds.Distinct().Count(), Is.EqualTo(1), "Messages from one subscription were processed in more then 1 thread"); Assert.That(queue2MessagesThreadIds.Distinct().Count(), Is.EqualTo(1), "Messages from one subscription were processed in more then 1 thread"); Assert.That(queue1MessagesThreadIds.First() != queue2MessagesThreadIds.First(), Is.True, "Messages from different subscriptions were processed one thread"); } }
public void InvestigationTest() { long count = 0; var handled = new AutoResetEvent(false); using (var engine = new MessagingEngine( new TransportResolver(new Dictionary <string, TransportInfo> { { "tr", new TransportInfo("localhost", "guest", "guest", "None", messaging: "RabbitMq") } }), new RabbitMqTransportFactory())) { var eventStoreConnection = EventStoreConnection.Create(ConnectionSettings.Create().UseConsoleLogger().SetDefaultUserCredentials(new UserCredentials("admin", "changeit")), new IPEndPoint(IPAddress.Loopback, 1113)); eventStoreConnection.Connect(); eventStoreConnection.SubscribeToAllFrom(Position.Start, false, (subscription, @event) => { engine.Send(@event, new Endpoint("tr", "t1", true, "json")); handled.Set(); count++; }, subscription => { }); handled.WaitOne(); var sw = Stopwatch.StartNew(); while (handled.WaitOne(100)) { } Console.WriteLine("Published {0} events. Within {1}ms", count, sw.ElapsedMilliseconds); } }
public void AllThreadsAreStoppedAfterCqrsDisposeTest() { var initialThreadCount = Process.GetCurrentProcess().Threads.Count; Console.WriteLine(initialThreadCount); using ( var messagingEngine = new MessagingEngine( new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null, "InMemory") } }))) { using (var engine = new CqrsEngine(messagingEngine, new InMemoryEndpointResolver(), LocalBoundedContext.Named("bc").ConcurrencyLevel(1) .PublishingEvents(typeof(int)) .To("eventExchange") .RoutedTo("eventQueue") .ListeningCommands(typeof(string)) .On("exchange1", CommandPriority.Low) .On("exchange2", CommandPriority.High) .RoutedFrom("commandQueue") .WithCommandsHandler(new CommandHandler(100))) ) { Console.WriteLine(Process.GetCurrentProcess().Threads.Count); } } Assert.That(Process.GetCurrentProcess().Threads.Count, Is.EqualTo(initialThreadCount), "Some threads were not stopped"); }
public void ListenSameCommandOnDifferentEndpointsTest() { using ( var messagingEngine = new MessagingEngine( new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null, "InMemory") } }))) { var commandHandler = new CommandHandler(); using (var engine = new CqrsEngine(messagingEngine, new InMemoryEndpointResolver(), LocalBoundedContext.Named("bc") .PublishingEvents(typeof(int)).To("eventExchange").RoutedTo("eventQueue") .ListeningCommands(typeof(string)).On("exchange1").On("exchange2").RoutedFrom("commandQueue") .WithCommandsHandler(commandHandler)) ) { messagingEngine.Send("test1", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("test2", new Endpoint("InMemory", "bc.exchange2", serializationFormat: "json")); messagingEngine.Send("test3", new Endpoint("InMemory", "bc.exchange3", serializationFormat: "json")); Thread.Sleep(2000); Assert.That(commandHandler.AcceptedCommands, Is.EquivalentTo(new[] { "test1", "test2" })); } } }
public void TwoSimpleEventInterceptorsTest() { var simpleEventInterceptorOne = new EventSimpleInterceptor(); var simpleEventInterceptorTwo = new EventSimpleInterceptor(); using (var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null) } }))) { using (var engine = new CqrsEngine( _logFactory, messagingEngine, Register.DefaultEndpointResolver(new InMemoryEndpointResolver()), Register.EventInterceptors(simpleEventInterceptorOne), Register.EventInterceptors(simpleEventInterceptorTwo), Register.Saga <TestSaga>("test2") .ListeningEvents(typeof(string)).From("lykke-wallet").On("lykke-wallet-events"))) { engine.StartSubscribers(); messagingEngine.Send("2", new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json)); Thread.Sleep(1000); Assert.True(simpleEventInterceptorOne.Intercepted); Assert.True(simpleEventInterceptorTwo.Intercepted); Assert.NotNull(simpleEventInterceptorOne.InterceptionTimestamp); Assert.NotNull(simpleEventInterceptorTwo.InterceptionTimestamp); Assert.True(simpleEventInterceptorOne.InterceptionTimestamp < simpleEventInterceptorTwo.InterceptionTimestamp); Assert.True(TestSaga.Messages.Contains("2")); } } }
public IContainer CreateContainer() { var builder = new ContainerBuilder(); builder.RegisterInstance(LogFactory.Create().AddUnbufferedConsole()).As <ILogFactory>().SingleInstance(); builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>() .SingleInstance(); builder.RegisterType <ForwardWithdrawalCommandHandler>(); builder.Register(ctx => { var logFactory = ctx.Resolve <ILogFactory>(); var messagingEngine = new MessagingEngine( logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null, "InMemory") } })); var cqrsEngine = CreateEngine(ctx, messagingEngine, logFactory); cqrsEngine.StartAll(); return(cqrsEngine); }) .As <ICqrsEngine>() .AutoActivate() .SingleInstance(); RegisterRepo(builder); return(builder.Build()); }
public void EndToEndRabbitResubscriptionTest() { var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "test", new TransportInfo(HOST, "guest", "guest", null, "RabbitMq") } }), new RabbitMqTransportFactory(_logFactory)); using (messagingEngine) { for (int i = 0; i < 100; i++) { messagingEngine.Send(i, new Endpoint("test", TEST_EXCHANGE, serializationFormat: SerializationFormat.Json)); } messagingEngine.Subscribe <int>(new Endpoint("test", TEST_QUEUE, serializationFormat: SerializationFormat.Json), message => { Console.WriteLine(message + "\n"); Thread.Sleep(1000); }); Thread.Sleep(30 * 60 * 1000); } Console.WriteLine("Done"); }
protected override void Load(ContainerBuilder builder) { builder.RegisterInstance(_settings.ContextNames).AsSelf().SingleInstance(); builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>() .SingleInstance(); builder.RegisterInstance(new CqrsContextNamesSettings()).AsSelf().SingleInstance(); var rabbitMqSettings = new RabbitMQ.Client.ConnectionFactory { Uri = new Uri(_settings.ConnectionString, UriKind.Absolute) }; var messagingEngine = new MessagingEngine(_log, new TransportResolver( new Dictionary <string, TransportInfo> { { "RabbitMq", new TransportInfo(rabbitMqSettings.Endpoint.ToString(), rabbitMqSettings.UserName, rabbitMqSettings.Password, "None", "RabbitMq") } }), new RabbitMqTransportFactory()); builder.RegisterType <EodStartedProjection>().AsSelf(); builder.Register(ctx => CreateEngine(ctx, messagingEngine)) .As <ICqrsEngine>() .SingleInstance() .AutoActivate(); }
public void testVideoJoinedDuh() { MessagingEngine engine = makeEngine(); engine.TimeNow = new DateTime(2021, 1, 1, 12, 58, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); List <SmsMessage> msgs = new List <SmsMessage>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; appts[1].ExternalData.ScreeningMessageResponse = true; appts[1].IsVideoConsultation = true; appts[1].ExternalData.VideoInviteSent = true; msgs.Add(new SmsMessage("+61411012345", "ok ready")); // run it engine.ProcessIncomingMessages(appts, msgs); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("The robot processing this message is stupid, and didn't understand your response. Please just say \"joined\" when you have joined the video call", OutputMsgs[0].message); Assert.AreEqual(0, StorageOps.Count); }
protected override void Load(ContainerBuilder builder) { builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>() .SingleInstance(); var rabbitMqSettings = new RabbitMQ.Client.ConnectionFactory { Uri = new Uri(_settings.ConnectionString, UriKind.Absolute) }; var messagingEngine = new MessagingEngine(_log, new TransportResolver(new Dictionary <string, TransportInfo> { { "RabbitMq", new TransportInfo(rabbitMqSettings.Endpoint.ToString(), rabbitMqSettings.UserName, rabbitMqSettings.Password, "None", "RabbitMq") } }), new RabbitMqTransportFactory()); // Sagas & command handlers builder.RegisterAssemblyTypes(GetType().Assembly) .Where(t => t.Name.EndsWith("Saga") || t.Name.EndsWith("CommandsHandler")) .AsSelf(); builder.Register(ctx => CreateEngine(ctx, messagingEngine)) .As <ICqrsEngine>() .SingleInstance() .AutoActivate(); }
protected override void Load(ContainerBuilder builder) { builder.RegisterInstance(_settings.ContextNames).AsSelf().SingleInstance(); builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>() .SingleInstance(); builder.RegisterType <CqrsSender>().As <ICqrsSender>() .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies) .SingleInstance(); builder.RegisterInstance(new CqrsContextNamesSettings()).AsSelf().SingleInstance(); var rabbitMqSettings = new RabbitMQ.Client.ConnectionFactory { Uri = _settings.ConnectionString }; var messagingEngine = new MessagingEngine(_log, new TransportResolver( new Dictionary <string, TransportInfo> { { "RabbitMq", new TransportInfo(rabbitMqSettings.Endpoint.ToString(), rabbitMqSettings.UserName, rabbitMqSettings.Password, "None", "RabbitMq") } }), new RabbitMqTransportFactory()); // Sagas & command handlers builder.RegisterAssemblyTypes(GetType().Assembly).Where(t => new [] { "Saga", "CommandsHandler", "Projection" }.Any(ending => t.Name.EndsWith(ending))).AsSelf(); builder.Register(ctx => CreateEngine(ctx, messagingEngine)).As <ICqrsEngine>().SingleInstance() .AutoActivate(); }
public void testUnexpected() { MessagingEngine engine = makeEngine(); engine.TimeNow = new DateTime(2021, 1, 1, 12, 58, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); List <SmsMessage> msgs = new List <SmsMessage>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; appts[1].ExternalData.ScreeningMessageResponse = true; appts[1].ArrivalStatus = AppointmentStatus.Fulfilled; msgs.Add(new SmsMessage("+61411012345", "Arrived")); // run it engine.ProcessIncomingMessages(appts, msgs); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("Patient Test Patient #2 has an appointment with Dr Adam Ant at 01:00 PM on 1-Jan, but this robot is not expecting a message right now", OutputMsgs[0].message); Assert.AreEqual(0, StorageOps.Count); }
public void testVideoJoined() { MessagingEngine engine = makeEngine(); var fhirServerUpdater = new MessageLogicFhirUpdaterHandler(this); engine.AppointmentUpdater = fhirServerUpdater; engine.TimeNow = new DateTime(2021, 1, 1, 12, 58, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); List <SmsMessage> msgs = new List <SmsMessage>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; appts[1].ExternalData.ScreeningMessageResponse = true; appts[1].IsVideoConsultation = true; appts[1].ExternalData.VideoInviteSent = true; msgs.Add(new SmsMessage("+61411012345", "Joined")); // run it engine.ProcessIncomingMessages(appts, msgs); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("Thank you. The Doctor will join you as soon as possible", OutputMsgs[0].message); Assert.AreEqual(1, StorageOps.Count); Assert.AreEqual("1002", StorageOps[0].Appointment.AppointmentFhirID); Assert.IsTrue(StorageOps[0].Appointment.ArrivalStatus == AppointmentStatus.Arrived); Assert.IsTrue(StorageOps[0].Appointment.ExternalData.ArrivalStatus == AppointmentStatus.Arrived); Assert.AreEqual("save-status", FhirUpdateOps[0].type); Assert.AreEqual(AppointmentStatus.Arrived, FhirUpdateOps[0].status); }
public void testArrived() { MessagingEngine engine = makeEngine(); var fhirServerUpdater = new MessageLogicFhirUpdaterHandler(this); engine.AppointmentUpdater = fhirServerUpdater; engine.TimeNow = new DateTime(2021, 1, 1, 12, 58, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); List <SmsMessage> msgs = new List <SmsMessage>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; appts[1].ExternalData.ScreeningMessageResponse = true; msgs.Add(new SmsMessage("+61411012345", "ARRIVED")); // run it engine.ProcessIncomingMessages(appts, msgs); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("Thanks for letting us know that you're here. We'll let you know as soon as the doctor is ready for you", OutputMsgs[0].message); Assert.AreEqual(1, StorageOps.Count); Assert.AreEqual("1002", StorageOps[0].Appointment.AppointmentFhirID); Assert.AreEqual("save-appt", StorageOps[0].type); Assert.AreEqual(AppointmentStatus.Arrived, StorageOps[0].Appointment.ArrivalStatus); Assert.AreEqual(AppointmentStatus.Arrived, StorageOps[0].Appointment.ExternalData.ArrivalStatus); Assert.AreEqual("save-status", FhirUpdateOps[0].type); Assert.AreEqual(AppointmentStatus.Arrived, FhirUpdateOps[0].status); }
public void testArrivedDuh() { MessagingEngine engine = makeEngine(); engine.TimeNow = new DateTime(2021, 1, 1, 12, 58, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); List <SmsMessage> msgs = new List <SmsMessage>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; appts[1].ExternalData.ScreeningMessageResponse = true; msgs.Add(new SmsMessage("+61411012345", "I'm here")); // run it engine.ProcessIncomingMessages(appts, msgs); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("The robot processing this message is stupid, and didn't understand your response. Please just say \"arrived\", or phone {num} for help", OutputMsgs[0].message); Assert.AreEqual(0, StorageOps.Count); }
public void testScreeningResponseYes() { MessagingEngine engine = makeEngine(); var fhirServerUpdater = new MessageLogicFhirUpdaterHandler(this); engine.AppointmentUpdater = fhirServerUpdater; engine.TimeNow = new DateTime(2021, 1, 1, 13, 0, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); List <SmsMessage> msgs = new List <SmsMessage>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; msgs.Add(new SmsMessage("+61411012345", "Yes")); // run it engine.ProcessIncomingMessages(appts, msgs); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("Thank you. Do not come to the doctor's clinic. You will get an SMS message containing the URL for your video meeting a few minutes before your appointment. You can join from any computer or smartphone", OutputMsgs[0].message); Assert.AreEqual(1, StorageOps.Count); Assert.AreEqual("1002", StorageOps[0].Appointment.AppointmentFhirID); Assert.IsTrue(StorageOps[0].Appointment.ExternalData.ScreeningMessageSent == true); Assert.IsTrue(StorageOps[0].Appointment.ExternalData.ScreeningMessageResponse == true); Assert.IsTrue(StorageOps[0].Appointment.IsVideoConsultation == true); Assert.AreEqual("save-video-meeting", FhirUpdateOps[0].type); Assert.IsNotNull(FhirUpdateOps[0].comment); }
public void testScreeningResponseNo() { MessagingEngine engine = makeEngine(); engine.TimeNow = new DateTime(2021, 1, 1, 13, 0, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); List <SmsMessage> msgs = new List <SmsMessage>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; msgs.Add(new SmsMessage("+61411012345", "NO!")); // run it engine.ProcessIncomingMessages(appts, msgs); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("Thank you. When you arrive at the clinic, stay in your car (or outside) and reply \"arrived\" to this message", OutputMsgs[0].message); Assert.AreEqual(1, StorageOps.Count); Assert.AreEqual("1002", StorageOps[0].Appointment.AppointmentFhirID); Assert.IsTrue(StorageOps[0].Appointment.ExternalData.ScreeningMessageSent == true); Assert.IsTrue(StorageOps[0].Appointment.ExternalData.ScreeningMessageResponse == true); Assert.IsTrue(StorageOps[0].Appointment.IsVideoConsultation == false); }
public void testVideoApptReady() { MessagingEngine engine = makeEngine(); engine.TimeNow = new DateTime(2021, 1, 1, 13, 1, 0); reset(); List <PmsAppointment> appts = new List <PmsAppointment>(); // set it up: appts.Add(appt10am()); appts.Add(appt1pm()); appts[1].ExternalData.ScreeningMessageSent = true; appts[1].ArrivalStatus = AppointmentStatus.Arrived; appts[1].ExternalData.ArrivalStatus = AppointmentStatus.Arrived; appts[1].ArrivalStatus = AppointmentStatus.Fulfilled; appts[1].ExternalData.ArrivalStatus = AppointmentStatus.Arrived; // run it engine.ProcessTodaysAppointments(appts); // inspect outputs: Assert.AreEqual(1, OutputMsgs.Count); Assert.AreEqual("+61411012345", OutputMsgs[0].phone); Assert.AreEqual("The doctor is ready to see you now. Please go to room 7.", OutputMsgs[0].message); Assert.AreEqual(1, StorageOps.Count); Assert.AreEqual("1002", StorageOps[0].Appointment.AppointmentFhirID); Assert.IsTrue(StorageOps[0].Appointment.ArrivalStatus == AppointmentStatus.Fulfilled); Assert.IsTrue(StorageOps[0].Appointment.ExternalData.ArrivalStatus == AppointmentStatus.Fulfilled); }
private MessagingEngine PrepareMessagingEngine() { MessagingEngine engine = new MessagingEngine(); engine.Initialise(Settings); engine.Logger = logger; engine.Storage = Storage; engine.RoomMappings = RoomMappings; engine.TemplateProcessor = new TemplateProcessor(); engine.TemplateProcessor.Initialise(Settings); engine.TemplateProcessor.Templates = Templates; engine.AppointmentUpdater = FhirApptUpdater; if (Settings.VideoType == VideoConferencingType.Jitsi) { engine.VideoManager = new VideoJitsi(); } else { engine.VideoManager = new VideoOpenVidu(); } engine.VideoManager.Initialize(Settings); engine.UnprocessableMessages = UnprocessableMessages; engine.SmsSender = SmsProcessor; engine.TimeNow = DateTime.Now; return(engine); }
public void ListenSameCommandOnDifferentEndpointsTest() { using (var messagingEngine = new MessagingEngine( _logFactory, new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null, "InMemory") } }))) { var commandHandler = new CommandHandler(); using (var engine = new CqrsEngine( _logFactory, messagingEngine, Register.DefaultEndpointResolver(new InMemoryEndpointResolver()), Register.BoundedContext("bc") .PublishingEvents(typeof(int)).With("eventExchange") .ListeningCommands(typeof(string)).On("exchange1") .ListeningCommands(typeof(string)).On("exchange2") .WithCommandsHandler(commandHandler))) { engine.Start(); messagingEngine.Send("test1", new Endpoint("InMemory", "exchange1", serializationFormat: SerializationFormat.Json)); messagingEngine.Send("test2", new Endpoint("InMemory", "exchange2", serializationFormat: SerializationFormat.Json)); messagingEngine.Send("test3", new Endpoint("InMemory", "exchange3", serializationFormat: SerializationFormat.Json)); Thread.Sleep(6000); Assert.That(commandHandler.AcceptedCommands, Is.EquivalentTo(new[] { "test1", "test2" })); } } }
public void MultipleInitializationsRaceConditionTest() { var transportResolver = new TransportResolver(new Dictionary <string, TransportInfo> { { "tr1", new TransportInfo("host", "guest", "guest", null, "InMemory") }, { "tr2", new TransportInfo("host", "guest", "guest", null, "InMemory") } }); var messagingEngine = new MessagingEngine(transportResolver, new ITransportFactory[] { new InMemoryTransportFactory() }); messagingEngine.SerializationManager.RegisterSerializer("txt", typeof(string), new FakeStringSerializer()); var fp1 = new FeedProvider1(messagingEngine); var consoleLogger = new ConsoleLogger(); fp1.Logger = consoleLogger; var fp2 = new FeedProvider2(messagingEngine); fp2.Logger = consoleLogger; var databus = new DataBus(); databus.RegisterFeedProvider("FP1", fp1); databus.RegisterFeedProvider("FP2", fp2); var disposable1 = databus.Channel <string>("FP1").Feed("context1").Subscribe(Console.WriteLine); var disposable2 = databus.Channel <string>("FP2").Feed("context2").Subscribe(Console.WriteLine); Thread.Sleep(10000); disposable1.Dispose(); disposable2.Dispose(); }
private void EnsureEndpoints(CommunicationType processingCommunicationType) { var allEndpointsAreValid = true; var errorMessage = new StringBuilder("Some endpoints are not valid:").AppendLine(); var endpointMessagesDict = new Dictionary <Endpoint, string>(); _log.WriteInfo(nameof(CqrsEngine), nameof(EnsureEndpoints), $"Endpoins verification for {processingCommunicationType}"); foreach (var routeMap in new List <RouteMap> { DefaultRouteMap }.Concat(Contexts)) { foreach (var route in routeMap) { foreach (var messageRoute in route.MessageRoutes) { var routingKey = messageRoute.Key; if (routingKey.CommunicationType != processingCommunicationType) { continue; } var endpoint = messageRoute.Value; endpointMessagesDict[endpoint] = $"Context {routeMap.Name}: " + (processingCommunicationType == CommunicationType.Publish ? $"publishing '{routingKey.MessageType.Name}' to" : $"subscribing '{routingKey.MessageType.Name}' on") + $" {endpoint}\t{{0}}"; } } } var endpointsErrorsDict = MessagingEngine.VerifyEndpoints( processingCommunicationType == CommunicationType.Publish ? EndpointUsage.Publish : EndpointUsage.Subscribe, endpointMessagesDict.Keys, _createMissingEndpoints); foreach (var endpointError in endpointsErrorsDict) { string messagePattern = endpointMessagesDict[endpointError.Key]; if (string.IsNullOrWhiteSpace(endpointError.Value)) { _log.WriteInfo(nameof(CqrsEngine), nameof(EnsureEndpoints), string.Format(messagePattern, "OK")); } else { _log.WriteError( nameof(CqrsEngine), nameof(EnsureEndpoints), new InvalidOperationException(string.Format(messagePattern, $"ERROR: {endpointError.Value}"))); } } if (!allEndpointsAreValid) { throw new ApplicationException(errorMessage.ToString()); } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { MessagingEngine.Dispose(); } }