public static async Task <IDisposable> StressGroups(int max = 100) { var host = new MemoryHost(); host.Configure(app => { var config = new HubConfiguration() { Resolver = new DefaultDependencyResolver() }; app.MapSignalR(config); var configuration = config.Resolver.Resolve <IConfigurationManager>(); // The below effectively sets the heartbeat interval to five seconds. configuration.KeepAlive = TimeSpan.FromSeconds(10); }); var countDown = new CountDownRange <int>(Enumerable.Range(0, max)); var connection = new HubConnection("http://foo"); var proxy = connection.CreateHubProxy("HubWithGroups"); proxy.On <int>("Do", i => { if (!countDown.Mark(i)) { Debugger.Break(); } }); try { connection.Start(new Client.Transports.LongPollingTransport(host)).Wait(); proxy.Invoke("Join", "foo").Wait(); for (int i = 0; i < max; i++) { proxy.Invoke("Send", "foo", i).Wait(); } proxy.Invoke("Leave", "foo").Wait(); for (int i = max + 1; i < max + 50; i++) { proxy.Invoke("Send", "foo", i).Wait(); } await countDown.WaitAsync().OrTimeout(); } finally { connection.Stop(); } return(host); }
public async Task SubscriptionWithExistingCursor() { var dr = new DefaultDependencyResolver(); var passThroughMinfier = new PassThroughStringMinifier(); dr.Register(typeof(IStringMinifier), () => passThroughMinfier); using (var bus = new MessageBus(dr)) { Func <TestSubscriber> subscriberFactory = () => new TestSubscriber(new[] { "key" }); var cd = new CountDownRange <int>(Enumerable.Range(2, 4)); IDisposable subscription = null; string prefix = DefaultSubscription._defaultCursorPrefix; // Pretend like we had an initial subscription bus.Subscribe(subscriberFactory(), null, (result, state) => TaskAsyncHelper.True, 10, null) .Dispose(); await bus.Publish("test", "key", "1"); await bus.Publish("test", "key", "2"); await bus.Publish("test", "key", "3"); await bus.Publish("test", "key", "4"); try { subscription = bus.Subscribe(subscriberFactory(), prefix + "key,00000001", (result, state) => { foreach (var m in result.GetMessages()) { int n = Int32.Parse(m.GetString()); Assert.True(cd.Mark(n)); } return(TaskAsyncHelper.True); }, 10, null); await bus.Publish("test", "key", "5"); await cd.WaitAsync().OrTimeout(); } finally { if (subscription != null) { subscription.Dispose(); } } } }
public async Task SubscriptionWithExistingCursor() { var dr = new DefaultDependencyResolver(); using (var bus = new TestScaleoutBus(dr, streams: 2)) { var subscriber = new TestSubscriber(new[] { "key" }); var cd = new CountDownRange <int>(Enumerable.Range(2, 4)); IDisposable subscription = null; bus.Publish(0, 0, new[] { new Message("test", "key", "1"), new Message("test", "key", "50") }); bus.Publish(1, 0, new[] { new Message("test1", "key", "51") }); bus.Publish(1, 2, new[] { new Message("test2", "key", "2"), new Message("test3", "key", "3"), new Message("test2", "key", "4"), }); try { subscription = bus.Subscribe(subscriber, "s-0,00000000|1,00000000", (result, state) => { foreach (var m in result.GetMessages()) { int n = Int32.Parse(m.GetString()); Assert.True(cd.Mark(n)); } return(TaskAsyncHelper.True); }, 10, null); bus.Publish(0, 2, new[] { new Message("test", "key", "5") }); await cd.WaitAsync().OrTimeout(); } finally { if (subscription != null) { subscription.Dispose(); } } } }
public async Task AddingEventAndSendingMessages() { var dr = new DefaultDependencyResolver(); using (var bus = new MessageBus(dr)) { var subscriber = new TestSubscriber(new[] { "a" }); int max = 100; var cd = new CountDownRange <int>(Enumerable.Range(0, max)); int prev = -1; IDisposable subscription = null; try { subscription = bus.Subscribe(subscriber, null, (result, state) => { foreach (var m in result.GetMessages()) { int n = Int32.Parse(m.GetString()); Assert.True(prev < n, "out of order"); prev = n; Assert.True(cd.Mark(n)); } return(TaskAsyncHelper.True); }, 10, null); for (int i = 0; i < max; i++) { subscriber.AddEvent("b"); await bus.Publish("test", "b", i.ToString()); } await cd.WaitAsync().OrTimeout(); } finally { if (subscription != null) { subscription.Dispose(); } } } }