public void MsgDispatcherLogical_Multi_Handlers_Grouped() { Target4A target1 = new Target4A(); Target4B target2 = new Target4B(); MsgDispatcher dispatcher = new MsgDispatcher(); // I'm going to test whether the handlers for the two targets // were grouped properly in the routing table by sending // instances of the two message types to logical://Foo. // // The message receive counts should match the number // of messages sent if grouping worked properly. If // grouping didn't work, we'd expect to see messages // routed randomly to one target or the other with // messages that aren't handled by each target being // dropped. dispatcher.AddTarget(target1, null, null, target1); dispatcher.AddTarget(target2, null, null, target1); for (int i = 0; i < 10; i++) { dispatcher.Dispatch(new _DispatchMsg1("logical://Foo")); dispatcher.Dispatch(new _DispatchMsg2("logical://Foo")); } Thread.Sleep(1000); Assert.AreEqual(10, target1.Count); Assert.AreEqual(10, target2.Count); }
public void MsgDispatcherPhysical_MultipleHandlers() { MsgDispatcher dispatcher; try { new MsgDispatcher().AddTarget(new Target4()); Assert.Fail("Expected the detection of multiple handlers with the same message type."); } catch (MsgException) { } try { dispatcher = new MsgDispatcher(); dispatcher.AddTarget(new Target2()); dispatcher.AddPhysical(new MsgHandlerDelegate(OnExplicit1), typeof(_DispatchMsg1), null); Assert.Fail("Expected the detection of multiple handlers with the same message type."); } catch (MsgException) { } }
public void MsgDispatcherLogical_Multi_Handlers_Broadcast() { Target3 target1 = new Target3(); Target3 target2 = new Target3(); MsgDispatcher dispatcher = new MsgDispatcher(); _DispatchMsg1 msg; dispatcher.AddTarget(target1); dispatcher.AddTarget(target2); msg = new _DispatchMsg1("logical://Dispatch1"); msg._Flags |= MsgFlag.Broadcast; dispatcher.Dispatch(msg); Thread.Sleep(DispatchWait); Assert.IsTrue(target1.dispatch1 && target2.dispatch1); }
public void MsgDispatcherLogical_LogicalEndpointSetID() { Target2 target = new Target2(); MsgDispatcher dispatcher = new MsgDispatcher(); Guid orgID; orgID = dispatcher.LogicalEndpointSetID; dispatcher.AddTarget(target); Assert.AreNotEqual(orgID, dispatcher.LogicalEndpointSetID); }
public void MsgDispatcherLogical_Multi_Handlers_Send() { Target3 target1 = new Target3(); Target3 target2 = new Target3(); MsgDispatcher dispatcher = new MsgDispatcher(); dispatcher.AddTarget(target1); dispatcher.AddTarget(target2); dispatcher.Dispatch(new _DispatchMsg1("logical://Dispatch1")); Thread.Sleep(DispatchWait); Assert.IsTrue(target1.dispatch1 || target2.dispatch1); for (int i = 0; i < 100; i++) { dispatcher.Dispatch(new _DispatchMsg1("logical://Dispatch1")); } Thread.Sleep(DispatchWait); Assert.IsTrue(target1.dispatch1 && target2.dispatch1); }
public void MsgDispatcherPhysical_NoHandlers() { Target1 target = new Target1(); MsgDispatcher dispatcher = new MsgDispatcher(); dispatcher.AddTarget(target); dispatcher.Dispatch(new _DispatchMsg1()); dispatcher.Dispatch(new _DispatchMsg2()); Thread.Sleep(DispatchWait); Assert.IsFalse(target.dispatch1); Assert.IsFalse(target.dispatch2); }
public void MsgDispatcherLogical_MultipleHandlerAttributes() { MsgDispatcher dispatcher = new MsgDispatcher(); dispatcher.AddTarget(this); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg1("logical://Multiple/1"))); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg1("logical://Multiple/2"))); Assert.AreEqual(2, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler11-1")); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler11-2")); }
public void MsgDispatcherLogical_MultipleHandlers() { MsgDispatcher dispatcher = new MsgDispatcher(); dispatcher.AddTarget(this); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg1("logical://Foo/Bar/1"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler1")); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg2("logical://Foo/Bar/1"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler2")); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg3("logical://Foo/Bar/1"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler3")); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg4("logical://Foo/Bar/1"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler4")); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg1("logical://Foo/Bar/2"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler5")); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg2("logical://Foo/Bar/2"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler6")); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg3("logical://Foo/Bar/2"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler7")); Clear(); Assert.IsTrue(Dispatch(dispatcher, new _DispatchMsg4("logical://Foo/Bar/2"))); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler8")); Clear(); Assert.IsFalse(Dispatch(dispatcher, new _DispatchMsg1("logical://NotPresent"))); Assert.AreEqual(0, dispatchInfo.Count); }
public void MsgDispatcherPhysical_ValidHandlers() { Target2 target = new Target2(); MsgDispatcher dispatcher = new MsgDispatcher(); dispatcher.AddTarget(target); dispatcher.Dispatch(new _DispatchMsg1()); dispatcher.Dispatch(new _DispatchMsg2()); dispatcher.Dispatch(new _DispatchMsg3()); Thread.Sleep(DispatchWait); Assert.IsTrue(target.dispatch1); Assert.IsTrue(target.dispatch2); Assert.IsTrue(target.dispatch3); }
public void MsgDispatcherPhysical_DefaultHandler() { Target3 target = new Target3(); MsgDispatcher dispatcher = new MsgDispatcher(); dispatcher.AddTarget(target); dispatcher.Dispatch(new _DispatchMsg1()); dispatcher.Dispatch(new _DispatchMsg2()); Thread.Sleep(DispatchWait); Assert.IsTrue(target.dispatch1); Assert.IsTrue(target.dispatch2); Assert.IsFalse(target.defHandler); dispatcher.Dispatch(new _DispatchMsg3()); Thread.Sleep(DispatchWait); Assert.IsTrue(target.defHandler); }
public void MsgDispatcherLogical_Broadcast() { MsgDispatcher dispatcher = new MsgDispatcher(); Msg msg; dispatcher.AddTarget(this); Clear(); msg = new _DispatchMsg1("logical://Foo/Bar/1"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler1")); Clear(); msg = new _DispatchMsg1("logical://Foo/Bar/2"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler5")); Clear(); msg = new _DispatchMsg1("logical://Foo/Bar/*"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(2, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler1") && dispatchInfo.ContainsKey("OnHandler5")); //------------------------- Clear(); msg = new _DispatchMsg2("logical://Foo/Bar/1"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler2")); Clear(); msg = new _DispatchMsg2("logical://Foo/Bar/2"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler6")); Clear(); msg = new _DispatchMsg2("logical://Foo/Bar/*"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(2, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler2") && dispatchInfo.ContainsKey("OnHandler6")); //------------------------- Clear(); msg = new _DispatchMsg3("logical://Foo/Bar/1"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler3")); Clear(); msg = new _DispatchMsg3("logical://Foo/Bar/2"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler7")); Clear(); msg = new _DispatchMsg3("logical://Foo/Bar/*"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(2, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler3") && dispatchInfo.ContainsKey("OnHandler7")); //------------------------- Clear(); msg = new _DispatchMsg4("logical://Foo/Bar/1"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler4")); Clear(); msg = new _DispatchMsg4("logical://Foo/Bar/2"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(1, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler8")); Clear(); msg = new _DispatchMsg4("logical://Foo/Bar/*"); msg._Flags |= MsgFlag.Broadcast; Assert.IsTrue(Dispatch(dispatcher, msg)); Assert.AreEqual(2, dispatchInfo.Count); Assert.IsTrue(dispatchInfo.ContainsKey("OnHandler4") && dispatchInfo.ContainsKey("OnHandler8")); }