public void TestWriteWithDesiredSpeed() { var keyDistributor = new KeyDistributor(64); var threads = Enumerable.Range(0, 5).Select(number => { var repository = CreateBoxEventRepository((id, obj) => keyDistributor.Distribute(id.ScopeId).ToString()); var testEventWriter = new TestEventWriter(repository, OperationsSpeed.PerSecond(10000), 1000); var thread = new Thread(testEventWriter.BeginExecution); thread.Start(); return(new { Thread = thread, Writer = testEventWriter }); }).ToList(); Thread.Sleep(TimeSpan.FromSeconds(30)); threads.ForEach(x => x.Writer.StopExecution()); threads.ForEach(x => x.Thread.Join()); }
public void TestWriteAndRead64Shard() { boxIds = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; using (var eventRepository = CreateBoxEventRepository((eventId, obj) => { var keyDistributor = new KeyDistributor(64); return(keyDistributor.Distribute(eventId.ScopeId).ToString()); }, 0)) { var expectedEvents = new List <Event>(); const int count = 30; for (var i = 0; i < count; ++i) { Console.WriteLine("Start write event {0}", i); var scopeId = GenerateScopeId(); var eventContent = GenerateEventContent(); var eventInfo = eventRepository.AddEvent(scopeId, eventContent); Assert.AreEqual(scopeId, eventInfo.Id.ScopeId); expectedEvents.Add(new Event { EventInfo = eventInfo, EventContent = eventContent, }); } var shards = new string[64].Select((x, idx) => (idx.ToString())).ToArray(); Console.WriteLine("Get events: all."); var actualEvents = eventRepository.GetEvents(null, shards).ToArray(); CheckEqualEvents(expectedEvents.ToArray(), actualEvents); for (var i = 0; i < expectedEvents.Count; ++i) { Console.WriteLine("Get events: from {0}.", i); actualEvents = eventRepository.GetEvents(expectedEvents[i].EventInfo, shards).ToArray(); CheckEqualEvents(expectedEvents.Skip(i + 1).ToArray(), actualEvents); } } }
private string CalculateShard(EventId eventId, object eventContent) { var keyDistributor = new KeyDistributor(ShardsCount); return(keyDistributor.Distribute(eventId.ScopeId).ToString()); }