public SendToStandIn ( HostOutput>.Tuple |
||
output | HostOutput>.Tuple | |
return | void |
public void Send_to_standIn() { var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt"); using(var sut = new PubnubHostTransceiver(cre, "hostchannel")) { var standIn = new Pubnub(cre.PublishingKey, cre.SubscriptionKey, cre.SecretKey); try { var standInChannel = Guid.NewGuid().ToString(); var are = new AutoResetEvent(false); ReadOnlyCollection<object> result = null; standIn.subscribe(standInChannel, (ReadOnlyCollection<object> _) => { result = _; are.Set(); }); var ho = new HostOutput{CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname"}; sut.SendToStandIn(new Tuple<string, HostOutput>(standInChannel, ho)); Assert.IsTrue(are.WaitOne(5000)); var hoReceived = Convert.FromBase64String((string)((JValue)result[0]).Value).Deserialize() as HostOutput; Assert.AreEqual(ho.CorrelationId, hoReceived.CorrelationId); Assert.AreEqual(ho.Data, hoReceived.Data); Assert.AreEqual(ho.Portname, hoReceived.Portname); } finally { standIn.subscribe("standIn", _ => {}); } } }
public void Connect_transceivers() { var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt"); using(var host = new PubnubHostTransceiver(cre, "thehost")) { var config = new FlowRuntimeConfiguration() .AddOperation(new PubnubStandInOperation("op", cre, "thehost")) .AddStream(".in", "op#greeting") .AddStream("op#greeting", ".out"); using (var fr = new FlowRuntime(config)) { fr.Message += Console.WriteLine; host.ReceivedFromStandIn += rhi => { var data = (string)rhi.Data.Deserialize(); var ho = new HostOutput { CorrelationId=rhi.CorrelationId, Data =(data + "y").Serialize(), Portname = "greeting" }; ThreadPool.QueueUserWorkItem(_ => { host.SendToStandIn(new Tuple<string, HostOutput>(rhi.StandInEndpointAddress, ho)); }); }; fr.Process(".in", "hello"); var result = ""; Assert.IsTrue(fr.WaitForResult(5000, _ => result = _.Data as string)); Assert.AreEqual("helloy", result); } } }