public void Client() { using (var server = new TcpRpcServer()) using (var client = new TcpRpcClient()) { Assert.IsFalse(client.IsComputing); Assert.IsFalse(client.IsWaitingForData); Assert.AreEqual(0L, client.SendCount); Assert.AreEqual(0L, client.RecvCount); Assert.ThrowsException <InvalidOperationException>(() => client.GetMain <ITestInterface>()); Assert.ThrowsException <ArgumentNullException>(() => client.AttachTracer(null)); Assert.ThrowsException <ArgumentNullException>(() => client.InjectMidlayer(null)); (var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort(); server.StartAccepting(addr, port); client.Connect(addr.ToString(), port); Assert.ThrowsException <InvalidOperationException>(() => client.Connect(addr.ToString(), port)); Assert.IsTrue(client.WhenConnected.Wait(MediumNonDbgTimeout)); Assert.ThrowsException <InvalidOperationException>(() => client.AttachTracer(new FrameTracing.RpcFrameTracer(Console.Out, false))); Assert.ThrowsException <InvalidOperationException>(() => client.InjectMidlayer(_ => _)); Assert.AreEqual(port, client.RemotePort); Assert.IsTrue(client.LocalPort != 0); Assert.AreEqual(0L, client.SendCount); Assert.AreEqual(0L, client.RecvCount); Assert.IsTrue(SpinWait.SpinUntil(() => client.IsWaitingForData, MediumNonDbgTimeout)); ((IConnection)client).Close(); Assert.IsTrue(SpinWait.SpinUntil(() => client.State == ConnectionState.Down, MediumNonDbgTimeout)); } }
public void ScatteredTransfer() { using (var server = new TcpRpcServer(IPAddress.Any, TcpPort)) using (var client = new TcpRpcClient()) { server.InjectMidlayer(s => new ScatteringStream(s, 7)); client.InjectMidlayer(s => new ScatteringStream(s, 10)); client.Connect("localhost", TcpPort); client.WhenConnected.Wait(); var counters = new Counters(); server.Main = new TestInterfaceImpl(counters); using (var main = client.GetMain <ITestInterface>()) { for (int i = 0; i < 100; i++) { var request1 = main.Foo(123, true, default); var request3 = Assert.ThrowsExceptionAsync <RpcException>(() => main.Bar(default));
protected static TcpRpcClient SetupClient(IPAddress addr, int port, TcpRpcTestOptions options = TcpRpcTestOptions.None) { var client = new TcpRpcClient(); client.AddBuffering(); if (options.HasFlag(TcpRpcTestOptions.ClientTracer)) { client.AttachTracer(new FrameTracing.RpcFrameTracer(Console.Out, false)); } if (options.HasFlag(TcpRpcTestOptions.ClientFluctStream)) { client.InjectMidlayer(s => new FluctStream(s)); } if (!options.HasFlag(TcpRpcTestOptions.ClientNoConnect)) { client.Connect(addr.ToString(), port); } return(client); }
public void ScatteredTransfer() { (var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort(); using (var server = new TcpRpcServer(addr, port)) using (var client = new TcpRpcClient()) { server.InjectMidlayer(s => new ScatteringStream(s, 7)); client.InjectMidlayer(s => new ScatteringStream(s, 10)); client.Connect(addr.ToString(), port); //client.WhenConnected.Wait(); var counters = new Counters(); server.Main = new TestInterfaceImpl(counters); using (var main = client.GetMain <ITestInterface>()) { for (int i = 0; i < 100; i++) { var request1 = main.Foo(123, true, default); var request3 = Assert.ThrowsExceptionAsync <RpcException>(() => main.Bar(default));