public void ConnectTest() { var e = new Endpoint(new SimpleIdentity("e1")); Assert.NotNull(e.GetEndpoint(new SimpleIdentity("e2"), URI.ToString())); Assert.NotNull(e.GetEndpoint(new SimpleIdentity("e2"), URI.ToString())); Assert.NotNull(e.GetEndpoint(new SimpleIdentity("e2"))); }
public void SendAndWaitTest() { var e = new Endpoint(new SimpleIdentity("e1")); var id = new SimpleIdentity("e2"); var msg = new Dictionary<string, object>(); msg.Add("k", "k"); Assert.AreEqual(msg["k"], e.GetEndpoint(id, URI.ToString()).SendAndWait(msg)["k"]); }
public void SendTest() { var e = new Endpoint(new SimpleIdentity("e1")); var id = new SimpleIdentity("e2"); var msg = new Dictionary<string, object>(); msg.Add("k", "k"); var handle = new EventWaitHandle(false, EventResetMode.AutoReset); e.OnAckMessage += (s, ack) => { Assert.AreEqual(msg["k"], ack.Message["k"]); handle.Set(); }; e.GetEndpoint(id, URI.ToString()).Send(msg); Assert.True(handle.WaitOne(100)); }
public void ConcurrentConnectTest() { var e = new Endpoint(new SimpleIdentity("e1")); var c = 0; while (c++ < 10) { var handles = new AutoResetEvent[10]; for (var i = 0; i < handles.Length; i++) new Thread(h => { Assert.NotNull(e.GetEndpoint(new SimpleIdentity("e2"), URI.ToString())); (h as AutoResetEvent).Set(); }).Start(handles[i] = new AutoResetEvent(false)); AutoResetEvent.WaitAll(handles); } }
public void EndpointTest() { var e = new Endpoint(new DefaultLoggerFactory(true, true, true, true, true), new SimpleIdentity("e1")); EndpointProxy proxy = e.GetEndpoint(new SimpleIdentity("e2"), "ws://localhost:9090/"); var msg = new Dictionary<string, object>(); msg.Add("byte", (byte)1); msg.Add("string", "string"); msg.Add("int16", (short)123); msg.Add("int32", 156); msg.Add("int64", 178L); msg.Add("date", DateTime.Now); var content = "hi中文"; msg.Add("byte[]", GZIPHelper.Zip(Encoding.UTF8.GetBytes(content))); var msg2 = proxy.SendAndWait(msg); foreach (var i in msg) { if (msg2[i.Key] is byte[]) { foreach (var b in msg2[i.Key] as byte[]) Console.Write(b + ","); Console.WriteLine(); var str = Encoding.UTF8.GetString(GZIPHelper.Unzip(msg2[i.Key] as byte[])); Assert.AreEqual(content, str); Console.WriteLine(i.Key + "=" + str); continue; } Assert.AreEqual(msg[i.Key], msg2[i.Key]); Assert.AreEqual(msg[i.Key].GetType(), msg2[i.Key].GetType()); Console.WriteLine(i.Key + "=" + msg2[i.Key]); } }