public AsyncReqReplyServiceSpecs() { Reply = string.Empty; Replied = new ManualResetEvent(false); Console.WriteLine("Start client fiber"); Func <byte[], string> unmarshaller = x => Encoding.Unicode.GetString(x); Func <string, byte[]> marshaller = x => Encoding.Unicode.GetBytes(x); ServerFiber = PoolFiber.StartNew(); ServerContext = NetMQContext.Create(); Service = new AsyncRequestHandlerSocket <string, string>(ServerContext, "tcp://localhost:9997", unmarshaller, marshaller); Service.SetRequestHandler(ServerFiber, request => request.Reply(request.Request.ToUpper())); Console.WriteLine("Start service"); ClientFiber = StubFiber.StartNew(); ClientContext = NetMQContext.Create(); Client = new AsyncRequestSocket <string, string>(ClientContext, "tcp://localhost:9997", marshaller, unmarshaller); Console.WriteLine("Start client"); }
public void TestTwoFibers() { FiberTester.TestPubSubWExtraFiber(ThreadFiber.StartNew(), ThreadFiber.StartNew()); FiberTester.TestPubSubWExtraFiber(PoolFiber.StartNew(), ThreadFiber.StartNew()); FiberTester.TestPubSubWExtraFiber(PoolFiber.StartNew(), PoolFiber.StartNew()); FiberTester.TestPubSubWExtraFiber(PoolFiber.StartNew(), StubFiber.StartNew()); }
public void TestBatching() { FiberTester.TestBatching(ThreadFiber.StartNew()); FiberTester.TestBatching(PoolFiber.StartNew()); FiberTester.TestBatching(StubFiber.StartNew()); FiberTester.TestBatchingWithKey(ThreadFiber.StartNew()); FiberTester.TestBatchingWithKey(PoolFiber.StartNew()); FiberTester.TestBatchingWithKey(StubFiber.StartNew()); }
public RequestSocket(NetMQContext context, string address, Func <TRequest, byte[]> requestMarshaller, Func <byte[], TReply> replyUnmarshaller) { _requestMarshaller = requestMarshaller; _replyUnmarshaller = replyUnmarshaller; _socket = context.CreateSocket(ZmqSocketType.Req); _socket.Connect(address); _internalChannel.SetRequestHandler(StubFiber.StartNew(), InternalSendRequest); }
public void Cancel() { int executionCount = 0; Action action = () => executionCount++; var timer = new TimerAction(StubFiber.StartNew(), action, TimeSpan.FromMilliseconds(2)); Thread.Sleep(100); Assert.AreEqual(1, executionCount); timer.Dispose(); Thread.Sleep(150); Assert.AreEqual(1, executionCount); }
public void CanSubscribeToEvent() { bool triggered = false; var stub = StubFiber.StartNew(); var evt = new EventTester(); var dispose = stub.SubscribeToEvent <object>(evt, "Event", x => triggered = true); Assert.IsTrue(evt.IsAttached); evt.Invoke(); Assert.IsTrue(triggered); dispose.Dispose(); Assert.IsFalse(evt.IsAttached); }
public void ChannelSubscription() { var fiber = StubFiber.StartNew(); var channel = new Channel <int>(); fiber.Subscribe(channel, i => { }); Assert.AreEqual(true, channel.HasSubscriptions()); fiber.Dispose(); Assert.AreEqual(false, channel.HasSubscriptions()); var sub = fiber.Subscribe(channel, i => { }); Assert.AreEqual(true, channel.HasSubscriptions()); sub.Dispose(); Assert.AreEqual(false, channel.HasSubscriptions()); }
public void PipelineTest1() { string value = null; int tvalue = 0; var stage1 = new Stage <double, int>(d => (int)d); var stage2 = new Tee <int>(i => tvalue = i); var stage3 = new Stage <int, string>(i => (i * 10).ToString()); var stub = StubFiber.StartNew(); var pipeline = stage1.To(stage2).To(stage3); pipeline.Subscribe(stub, s => value = s); stage1.Publish(1.3); Thread.Sleep(10); Assert.AreEqual("10", value); Assert.AreEqual(1, tvalue); }
public void CallbackFromIntervalTimerWithCancel() { int executionCount = 0; Action action = () => executionCount++; using (IFiber stubFiber = StubFiber.StartNew()) { var timer = new TimerAction(stubFiber, action, TimeSpan.FromMilliseconds(2), TimeSpan.FromMilliseconds(150)); Thread.Sleep(100); Assert.AreEqual(1, executionCount); timer.Dispose(); Thread.Sleep(150); Assert.AreEqual(1, executionCount); } }
static void Main(string[] args) { //This example uses mutable messages, which require care. Normally you want to //default to using immutable messages for each stage. //Its possible to fan out certain stages to deal with the issue with pipelines only being //as fast as the slowest stage. You can use a Queue channel say between stage1 and stage2 and then //instantiate more than one stage2 processor. var channels = new Channels(); using (var stage1 = new ConcurrentComponent <Payload, Payload>(new Stage1(new SomeService()), channels.Input, channels.Stage1To2, channels.Errors)) using (var stage2 = new ConcurrentComponent <Payload, Payload>(new Stage2(new SomeDataAccess()), channels.Stage1To2, channels.Output, channels.Errors)) using (var stub = StubFiber.StartNew()) { channels.Output.Subscribe(stub, payload => Console.WriteLine("Got output")); channels.Stage1To2.Subscribe(stub, payload => Console.WriteLine("Monitoring Stage1to2 channel saw a message")); using (var timer = new ThreadSafeTimer()) { timer.Schedule(() => channels.Input.Publish(new Payload()), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2)); Console.WriteLine("Hit any key to stop"); Console.ReadKey(); } } }
public void TestReqReply() { FiberTester.TestReqReply1(ThreadFiber.StartNew()); FiberTester.TestReqReply1(PoolFiber.StartNew()); FiberTester.TestReqReply1(StubFiber.StartNew()); }
public void TestPubSubWithFilter() { FiberTester.TestPubSubWithFilter(ThreadFiber.StartNew()); FiberTester.TestPubSubWithFilter(PoolFiber.StartNew()); FiberTester.TestPubSubWithFilter(StubFiber.StartNew()); }
public void TestPubSubSimple() { FiberTester.TestPubSubSimple(ThreadFiber.StartNew()); FiberTester.TestPubSubSimple(PoolFiber.StartNew()); FiberTester.TestPubSubSimple(StubFiber.StartNew()); }
public void InOrderExecution() { FiberTester.InOrderExecution(ThreadFiber.StartNew()); FiberTester.InOrderExecution(PoolFiber.StartNew()); FiberTester.InOrderExecution(StubFiber.StartNew()); }