public void TestOrderServiceSuccessRunAndStop() { var service = new OrderService(); var producer = new Producer(service.Disruptor.RingBuffer); Task.Run(() => service.Run()); for (int i = 0; i < 10; i++) { var msg = EventMessageFactory.GetEventMessage(); msg.EventType = EventType.OrderPlaced; msg.EventData.Order.Id = i; msg.EventData.Order.Price = 100; msg.EventData.Order.AccountId = 1000001; producer.OnData(msg); } service.Stop(); var actual = service.Disruptor.RingBuffer.ClaimAndGetPreallocated(9); Assert.Multiple(() => { Assert.That(actual.EventType, Is.EqualTo(EventType.OrderPlaced)); Assert.That(actual.EventData.Order.Id, Is.EqualTo(9)); Assert.That(actual.EventData.Order.Price, Is.EqualTo(100)); }); }
public void TestGetEventMessage() { var target = EventMessageFactory.GetEventMessage(); Assert.Multiple(() => { Assert.That(target, Is.Not.Null, "EventMessage must not be null"); Assert.That(target.EventType, Is.EqualTo(EventType.Undefined)); }); }
public void TestPublishSuccess() { var ringBuffer = new RingBuffer <EventMessage>(() => new EventMessage(), new SingleProducerSequencer(8, new YieldingWaitStrategy())); var target = new Producer(ringBuffer); var message = EventMessageFactory.GetEventMessage(); message.EventType = EventType.OrderPlaced; message.EventData.Order.Id = GetOrderId(); message.EventData.Order.AccountId = 100001L; message.EventData.Order.Price = 100m; target.OnData(message); Assert.That(ringBuffer.ClaimAndGetPreallocated(0).EventData.Order.Id, Is.EqualTo(message.EventData.Order.Id)); }
public static EventMessage <T1> GetEventMessage() { var message = EventMessageFactory <EventMessage <T1> > .GetEventMessage(); return(message); }