public void Test() { using (var source = new CancellationTokenSource()) { var dev = AzureStorage.CreateConfigurationForDev(); WipeAzureAccount.Fast(s => s.StartsWith("test-"), dev); var b = new RawEngineBuilder(); b.Dispatch(dev.CreateInbox("test-publish"), bytes => { if (bytes[0] == 42) source.Cancel(); }); using (var engine = b.Build()) { var task = engine.Start(source.Token); dev.CreateQueueWriter("test-publish").PutMessage(new byte[] {42}); if (!task.Wait(5000)) { source.Cancel(); } } } }
public void Direct() { var config = new MemoryStorageConfig(); var raw = new RawEngineBuilder(); var doWriter = config.CreateQueueWriter("do"); // forwarder do => do raw.Dispatch(config.CreateInbox("do"), envelope => doWriter.PutMessage(envelope)); TestConfiguration(doWriter, raw); }
public void PartitionWithRouter() { var config = new MemoryAccount(); var raw = new RawEngineBuilder(); var inWriter = config.CreateQueueWriter("in"); var doWriter = config.CreateQueueWriter("do"); // forwarder in => do raw.Dispatch(config.CreateInbox("in"), doWriter.PutMessage); // forwarder do => in raw.Dispatch(config.CreateInbox("do"), inWriter.PutMessage); TestConfiguration(inWriter, raw); }
public void RouterChain() { var config = new MemoryStorageConfig(); var raw = new RawEngineBuilder(); var doWriter = config.CreateQueueWriter("do"); var route1 = config.CreateQueueWriter("route1"); var route2 = config.CreateQueueWriter("route2"); // in => (route1 OR route2) raw.Dispatch(config.CreateInbox("in"), bytes => LoadBalance(bytes, route1, route2)); // forwarder (route1,route2) => do raw.Dispatch(config.CreateInbox("route1", "route2"), envelope => doWriter.PutMessage(envelope)); raw.Dispatch(config.CreateInbox("do"), bytes => LoadBalance(bytes, route1, route2)); TestConfiguration(config.CreateQueueWriter("in"), raw); }
public void Memory_lambda() { var config = new MemoryAccount(); var writer = config.CreateQueueWriter("test"); var inbox = config.CreateInbox("test"); var builder = new RawEngineBuilder(); builder.Dispatch(inbox, bytes => { }); var setup = new Setup { Send = i => writer.PutMessage(new[] {i}), Engine = builder.Build() }; TestConfiguration(setup, 1000000); }
public void Throughput_Azure_lambda() { var config = AzureStorage.CreateConfigurationForDev(); WipeAzureAccount.Fast(s => s.StartsWith("throughput"), config); var writer = config.CreateQueueWriter("test"); var inbox = config.CreateInbox("test", u => TimeSpan.Zero); var builder = new RawEngineBuilder(); builder.Dispatch(inbox, bytes => { }); var setup = new Setup { Send = i => writer.PutMessage(new[] {i}), Engine = builder.Build() }; TestConfiguration(setup, 100); }
public void File_lambda() { var config = FileStorage.CreateConfig("throughput-tests"); config.Wipe(); var writer = config.CreateQueueWriter("test"); var inbox = config.CreateInbox("test", u => TimeSpan.FromMilliseconds(0)); var builder = new RawEngineBuilder(); builder.Dispatch(inbox, bytes => { }); var setup = new Setup { Send = i => writer.PutMessage(new[] {i}), Engine = builder.Build() }; TestConfiguration(setup, 1000); }
// ReSharper disable InconsistentNaming static void TestConfiguration(IQueueWriter sender, RawEngineBuilder builder) { int i = 0; using (var t = new CancellationTokenSource()) using (TestObserver.When<MessageAcked>(ea => { if (ea.Context.QueueName != "do") return; if (i++ >= 5) t.Cancel(); })) using (var engine = builder.Build()) { engine.Start(t.Token); sender.PutMessage(new byte[1]); if (!t.Token.WaitHandle.WaitOne(5000)) { t.Cancel(); } Assert.IsTrue(t.IsCancellationRequested); } }