public void CanTolerateSubscriberFailure() { if (_messageBus == null) { return; } var latch = new CountDownLatch(2); _messageBus.Subscribe <SimpleMessageA>(msg => { throw new ApplicationException(); }); _messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); _messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); _messageBus.Publish(new SimpleMessageA { Data = "Hello" }); bool success = latch.Wait(5000); Assert.True(success, "Failed to receive all messages."); }
public void CanSendMessageToMultipleSubscribers() { var latch = new CountDownLatch(3); var messageBus = new InMemoryMessageBus(); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.PublishAsync(new SimpleMessageA { Data = "Hello" }); bool success = latch.Wait(100); Assert.True(success, "Failed to receive all messages."); }
public void CanSendMessageToMultipleSubscribers() { if (_messageBus == null) { return; } var latch = new CountDownLatch(3); _messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); _messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); _messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); _messageBus.Publish(new SimpleMessageA { Data = "Hello" }); bool success = latch.Wait(15000); Assert.True(success, "Failed to receive all messages."); }
public virtual void CanSendMessageToMultipleSubscribers() { var messageBus = GetMessageBus(); if (messageBus == null) { return; } using (messageBus) { var latch = new CountDownLatch(3); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Publish(new SimpleMessageA { Data = "Hello" }); bool success = latch.Wait(2000); Assert.True(success, "Failed to receive all messages."); } Thread.Sleep(50); }
public void WillReceiveDerivedMessageTypes() { if (_messageBus == null) { return; } var latch = new CountDownLatch(2); _messageBus.Subscribe <ISimpleMessage>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); _messageBus.PublishAsync(new SimpleMessageA { Data = "Hello" }); _messageBus.PublishAsync(new SimpleMessageB { Data = "Hello" }); _messageBus.PublishAsync(new SimpleMessageC { Data = "Hello" }); bool success = latch.Wait(5000); Assert.True(success, "Failed to receive all messages."); }
public virtual void CanSubscribeToAllMessageTypes() { var messageBus = GetMessageBus(); if (messageBus == null) { return; } using (messageBus) { var latch = new CountDownLatch(3); messageBus.Subscribe <object>(msg => { latch.Signal(); }); messageBus.Publish(new SimpleMessageA { Data = "Hello" }); messageBus.Publish(new SimpleMessageB { Data = "Hello" }); messageBus.Publish(new SimpleMessageC { Data = "Hello" }); bool success = latch.Wait(2000); Assert.True(success, "Failed to receive all messages."); } Thread.Sleep(50); }
public void CanSubscribeToAllMessageTypes() { if (_messageBus == null) { return; } var latch = new CountDownLatch(3); _messageBus.Subscribe <object>(msg => { latch.Signal(); }); _messageBus.Publish(new SimpleMessageA { Data = "Hello" }); _messageBus.Publish(new SimpleMessageB { Data = "Hello" }); _messageBus.Publish(new SimpleMessageC { Data = "Hello" }); bool success = latch.Wait(5000); Assert.True(success, "Failed to receive all messages."); }
public virtual void WillReceiveDerivedMessageTypes() { var messageBus = GetMessageBus(); if (messageBus == null) { return; } using (messageBus) { var latch = new CountDownLatch(2); messageBus.Subscribe <ISimpleMessage>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Publish(new SimpleMessageA { Data = "Hello" }); messageBus.Publish(new SimpleMessageB { Data = "Hello" }); messageBus.Publish(new SimpleMessageC { Data = "Hello" }); bool success = latch.Wait(5000); Assert.True(success, "Failed to receive all messages."); } Thread.Sleep(50); }
internal void OnDisconnect() { if (connectorStateEngine.getConnectionState() == ConnectorStateEngine.ConnectorState.DISCONNECTING /*&& disconnectLatch.getCount() == 1*/) { disconnectLatch.Signal(); } else { Backtory.Dispatch(() => sdkListener.OnDisconnect()); } connectorStateEngine.ChangeState(ConnectorStateEngine.StateChangeEvent.CONNECTED); }
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(); } }
public void CanTolerateSubscriberFailure() { var latch = new CountDownLatch(2); var messageBus = new InMemoryMessageBus(); messageBus.Subscribe <SimpleMessageA>(msg => { throw new ApplicationException(); }); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Subscribe <SimpleMessageA>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.PublishAsync(new SimpleMessageA { Data = "Hello" }); bool success = latch.Wait(900); Assert.True(success, "Failed to receive all messages."); }
public void MeasureWorkerThroughput() { var queue = GetQueue(retries: 3, workItemTimeout: TimeSpan.FromSeconds(2), retryDelay: TimeSpan.FromSeconds(1)); if (queue == null) { return; } FlushAll(); using (queue) { queue.DeleteQueue(); const int workItemCount = 10000; for (int i = 0; i < workItemCount; i++) { queue.Enqueue(new SimpleWorkItem { Data = "Hello" }); } Assert.Equal(workItemCount, queue.GetQueueCount()); var countdown = new CountDownLatch(workItemCount); var metrics = new InMemoryMetricsClient(); queue.StartWorking(workItem => { Assert.Equal("Hello", workItem.Value.Data); workItem.Complete(); metrics.Counter("work"); countdown.Signal(); }); countdown.Wait(60 * 1000); metrics.DisplayStats(); Assert.Equal(workItemCount, queue.DequeuedCount); Assert.Equal(workItemCount, queue.CompletedCount); Assert.Equal(0, queue.GetQueueCount()); Trace.WriteLine(CountAllKeys()); } }
public void CanSubscribeToAllMessageTypes() { var latch = new CountDownLatch(3); _messageBus.Value.Subscribe <object>(msg => { latch.Signal(); }); _messageBus.Value.PublishAsync(new SimpleMessageA { Data = "Hello" }); _messageBus.Value.PublishAsync(new SimpleMessageB { Data = "Hello" }); _messageBus.Value.PublishAsync(new SimpleMessageC { Data = "Hello" }); bool success = latch.Wait(5000); Assert.True(success, "Failed to recieve all messages."); }
public void CanSubscribeToAllMessageTypes() { var latch = new CountDownLatch(3); var messageBus = new InMemoryMessageBus(); messageBus.Subscribe <object>(msg => { latch.Signal(); }); messageBus.Publish(new SimpleMessageA { Data = "Hello" }); messageBus.Publish(new SimpleMessageB { Data = "Hello" }); messageBus.Publish(new SimpleMessageC { Data = "Hello" }); bool success = latch.Wait(100); Assert.True(success, "Failed to receive all messages."); }
public void WillReceiveDerivedMessageTypes() { var latch = new CountDownLatch(2); var messageBus = new InMemoryMessageBus(); messageBus.Subscribe <ISimpleMessage>(msg => { Assert.Equal("Hello", msg.Data); latch.Signal(); }); messageBus.Publish(new SimpleMessageA { Data = "Hello" }); messageBus.Publish(new SimpleMessageB { Data = "Hello" }); messageBus.Publish(new SimpleMessageC { Data = "Hello" }); bool success = latch.Wait(100); Assert.True(success, "Failed to receive all messages."); }
public void WillSaveOnce() { var latch = new CountDownLatch(2); var storage = new InMemoryFileStorage(); var dict = new PersistedDictionary("test.json", storage, new DefaultJsonSerializer(), 50); dict.Saved += (sender, args) => latch.Signal(); for (int i = 0; i < 10; i++) { dict["test" + i] = i.ToString(); } Assert.Equal(10, dict.Count); bool success = latch.Wait(250); Assert.False(success, "Dictionary was saved multiple times."); Assert.Equal(1, latch.Remaining); Assert.True(storage.Exists("test.json")); dict["test"] = "test"; Assert.Equal(11, dict.Count); success = latch.Wait(250); Assert.True(success, "Failed to save dictionary."); Assert.True(storage.Exists("test.json")); }
private void DoWork(QueueEntry <SimpleWorkItem> w, CountDownLatch latch, ref int abandonCount, ref int errorCount) { Assert.Equal("Hello", w.Value.Data); latch.Signal(); // randomly complete, abandon or blowup. if (RandomHelper.GetBool()) { Console.WriteLine("Completing: {0}", w.Value.Id); w.CompleteAsync().Wait(); } else if (RandomHelper.GetBool()) { Console.WriteLine("Abandoning: {0}", w.Value.Id); w.AbandonAsync(); Interlocked.Increment(ref abandonCount); } else { Console.WriteLine("Erroring: {0}", w.Value.Id); Interlocked.Increment(ref errorCount); throw new ApplicationException(); } }
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(JsonConvert.SerializeObject(events)).CompressAsync().Result; var actionResult = _eventController.PostAsync(compressedEvents, version: 2, userAgent: "exceptionless/2.0.0.0").Result; 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(); } }