public void AsynchronousData() { // Create the endpoints NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Asynchronous, _host); // Connect the endpoints endpoints.ManagerEndpoint.Listen(_host); endpoints.NodeEndpoint.Connect(_host); // Create our test packets INodePacket managerPacket = new TestPacket(); INodePacket nodePacket = new TestPacket(); // Send data from the manager. We expect to receive it from the node endpoint, and it should // be on the same thread. endpoints.ManagerEndpoint.SendData(managerPacket); if (!_host.DataReceivedEvent.WaitOne(1000, false)) { Assert.Fail("Data not received before timeout expired."); } Assert.IsTrue(_host.DataReceivedContext.packet == managerPacket); Assert.IsTrue(_host.DataReceivedContext.thread.ManagedThreadId != Thread.CurrentThread.ManagedThreadId); // Send data from the node. We expect to receive it from the manager endpoint, and it should // be on the same thread. endpoints.NodeEndpoint.SendData(nodePacket); if (!_host.DataReceivedEvent.WaitOne(1000, false)) { Assert.Fail("Data not received before timeout expired."); } Assert.IsTrue(_host.DataReceivedContext.packet == nodePacket); Assert.IsTrue(_host.DataReceivedContext.thread.ManagedThreadId != Thread.CurrentThread.ManagedThreadId); }
public void SynchronousData() { // Create the endpoints NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Synchronous, _host); // Connect the endpoints endpoints.ManagerEndpoint.Listen(_host); endpoints.NodeEndpoint.Connect(_host); // Create our test packets INodePacket managerPacket = new TestPacket(); INodePacket nodePacket = new TestPacket(); // Send data from the manager. We expect to receive it from the node endpoint, and it should // be on the same thread. endpoints.ManagerEndpoint.SendData(managerPacket); Assert.Equal(_host.DataReceivedContext.packet, managerPacket); Assert.Equal(_host.DataReceivedContext.thread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId); // Send data from the node. We expect to receive it from the manager endpoint, and it should // be on the same thread. endpoints.NodeEndpoint.SendData(nodePacket); Assert.Equal(_host.DataReceivedContext.packet, nodePacket); Assert.Equal(_host.DataReceivedContext.thread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId); }
private void DisconnectionTestHelper(NodeEndpointInProc.EndpointMode mode) { NodeEndpointInProc.EndpointPair endpoints = SetupConnection(mode); endpoints.ManagerEndpoint.Disconnect(); VerifyLinksAndCallbacksInactive(endpoints); endpoints = SetupConnection(mode); endpoints.NodeEndpoint.Disconnect(); VerifyLinksAndCallbacksInactive(endpoints); }
public void ConstructionWithValidHost() { NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Synchronous, _host); endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Asynchronous, _host); }
public void ConstructionAsynchronousWithInvalidHost() { Assert.Throws <ArgumentNullException>(() => { NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Asynchronous, null); } ); }
private NodeEndpointInProc.EndpointPair SetupConnection(NodeEndpointInProc.EndpointMode mode) { NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints(mode, _host); endpoints.ManagerEndpoint.OnLinkStatusChanged += LinkStatusChanged; endpoints.NodeEndpoint.OnLinkStatusChanged += LinkStatusChanged; // Call listen. This shouldn't have any effect on the link statuses. endpoints.ManagerEndpoint.Listen(_host); endpoints.NodeEndpoint.Connect(_host); return(endpoints); }
public void InactiveLinkTestSynchronous() { NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Synchronous, _host); CallOpOnEndpoints(endpoints, VerifyLinkInactive); CallOpOnEndpoints(endpoints, VerifySendDataInvalidOperation); CallOpOnEndpoints(endpoints, VerifyDisconnectInvalidOperation); // The following should not throw endpoints.ManagerEndpoint.Listen(_host); endpoints.NodeEndpoint.Connect(_host); }
public void ConnectionTestSynchronous() { NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Synchronous, _host); endpoints.ManagerEndpoint.OnLinkStatusChanged += LinkStatusChanged; endpoints.NodeEndpoint.OnLinkStatusChanged += LinkStatusChanged; // Call listen. This shouldn't have any effect on the link statuses. endpoints.ManagerEndpoint.Listen(_host); CallOpOnEndpoints(endpoints, VerifyLinkInactive); // No link status callback should have occurred. Assert.False(_linkStatusTable.ContainsKey(endpoints.NodeEndpoint)); Assert.False(_linkStatusTable.ContainsKey(endpoints.ManagerEndpoint)); // Now call connect on the node side. This should activate the link on both ends. endpoints.NodeEndpoint.Connect(_host); CallOpOnEndpoints(endpoints, VerifyLinkActive); // We should have received callbacks informing us of the link change. Assert.Equal(LinkStatus.Active, _linkStatusTable[endpoints.NodeEndpoint].status); Assert.Equal(LinkStatus.Active, _linkStatusTable[endpoints.ManagerEndpoint].status); }
private void VerifyLinksAndCallbacksInactive(NodeEndpointInProc.EndpointPair endpoints) { CallOpOnEndpoints(endpoints, VerifyLinkInactive); Assert.Equal(LinkStatus.Inactive, _linkStatusTable[endpoints.NodeEndpoint].status); Assert.Equal(LinkStatus.Inactive, _linkStatusTable[endpoints.ManagerEndpoint].status); }
private void CallOpOnEndpoints(NodeEndpointInProc.EndpointPair pair, EndpointOperationDelegate opDelegate) { opDelegate(pair.NodeEndpoint); opDelegate(pair.ManagerEndpoint); }
public void ConstructionAsynchronousWithInvalidHost() { NodeEndpointInProc.EndpointPair endpoints = NodeEndpointInProc.CreateInProcEndpoints( NodeEndpointInProc.EndpointMode.Asynchronous, null); }