public void CanPostString() { _eventQueue.DeleteQueue(); RemoveAllEvents(); try { _eventController.Request = CreateRequestMessage(new ClaimsPrincipal(IdentityUtils.CreateUserIdentity(TestConstants.UserEmail, TestConstants.UserId, new[] { TestConstants.OrganizationId }, new[] { AuthorizationRoles.Client }, TestConstants.ProjectId)), false, false); var statsCounter = IoC.GetInstance <IAppStatsClient>() as InMemoryAppStatsClient; Assert.NotNull(statsCounter); Assert.True(statsCounter.WaitForCounter(StatNames.PostsQueued, work: () => { var actionResult = _eventController.Post(Encoding.UTF8.GetBytes("simple string")); Assert.IsType <StatusCodeResult>(actionResult); })); Assert.Equal(1, _eventQueue.GetQueueCount()); var processEventsJob = IoC.GetInstance <EventPostsJob>(); processEventsJob.Run(); Assert.Equal(0, _eventQueue.GetQueueCount()); Assert.Equal(1, EventCount()); } finally { RemoveAllEvents(); } }
public void CanPostSingleEvent() { RemoveAllEvents(); try { _eventController.Request = CreateRequestMessage(new ClaimsPrincipal(IdentityUtils.CreateUserIdentity(TestConstants.UserEmail, TestConstants.UserId, new[] { TestConstants.OrganizationId }, new[] { AuthorizationRoles.Client }, TestConstants.ProjectId)), true, false); var actionResult = _eventController.Post(Encoding.UTF8.GetBytes("simple string").Compress()).Result; Assert.IsType <StatusCodeResult>(actionResult); Assert.Equal(1, _eventQueue.Count); var processEventsJob = IoC.GetInstance <ProcessEventPostsJob>(); processEventsJob.Run(1); Assert.Equal(0, _eventQueue.Count); Assert.Equal(1, EventCount()); } finally { RemoveAllEvents(); } }
public void CanPostManyEvents() { _eventQueue.DeleteQueue(); RemoveAllEvents(); const int batchSize = 250; const int batchCount = 10; try { var countdown = new CountDownLatch(10); var messageSubscriber = IoC.GetInstance <IMessageSubscriber>(); messageSubscriber.Subscribe <EntityChanged>(ch => { if (ch.ChangeType != ChangeType.Added || ch.Type != typeof(PersistentEvent).Name) { return; } if (countdown.Remaining <= 0) { throw new ApplicationException("Too many change notifications."); } countdown.Signal(); }); Parallel.For(0, batchCount, i => { _eventController.Request = CreateRequestMessage(new ClaimsPrincipal(IdentityUtils.CreateUserIdentity(TestConstants.UserEmail, TestConstants.UserId, new[] { TestConstants.OrganizationId }, new[] { AuthorizationRoles.Client }, TestConstants.ProjectId)), true, false); var events = new RandomEventGenerator().Generate(batchSize); var compressedEvents = Encoding.UTF8.GetBytes(new DefaultJsonSerializer().Serialize(events)).Compress(); var actionResult = _eventController.Post(compressedEvents, version: 2, userAgent: "exceptionless/2.0.0.0"); Assert.IsType <StatusCodeResult>(actionResult); }); Assert.Equal(batchCount, _eventQueue.GetQueueCount()); var sw = new Stopwatch(); var processEventsJob = IoC.GetInstance <EventPostsJob>(); sw.Start(); processEventsJob.RunUntilEmpty(); sw.Stop(); Trace.WriteLine(sw.Elapsed); Assert.Equal(0, _eventQueue.GetQueueCount()); Assert.Equal(batchSize * batchCount, EventCount()); bool success = countdown.Wait(5000); Assert.True(success); } finally { _eventQueue.DeleteQueue(); } }