public int TestException(string serverUrl, string param, RpcErrorCode exceptedCode, string errMsg) { Stopwatch watch = new Stopwatch(); watch.Start(); try { RpcClientProxy proxy = RpcProxyFactory.GetProxy <IRpcTestService>(serverUrl); proxy.Invoke <string, string>("TestException", param); Assert.Fail("Should Failed..."); } catch (RpcException ex) { Console.WriteLine(ex.ToString()); Assert.AreEqual(exceptedCode, ex.RpcCode); if (!string.IsNullOrEmpty(errMsg)) { Assert.IsTrue(ex.ToString().Contains(errMsg)); } } int ms = (int)watch.ElapsedMilliseconds; Console.WriteLine("Cost Ms: {0}", ms); return(ms); }
public void FixtureSetUp() { // // TODO: Add constructor logic here // if (!_inited) { ServiceSettings.InitService("UnitTest-Common"); RpcProxyFactory.RegisterClientChannel(new RpcHttpClientChannel()); RpcProxyFactory.RegisterClientChannel(new RpcPipeClientChannel()); RpcProxyFactory.RegisterClientChannel(RpcInprocClientChannel.Instance); RpcProxyFactory.RegisterClientChannel(new RpcTcpClientChannel()); RpcServiceManager.RegisterServerChannel(new RpcHttpServerChannel(8899)); RpcServiceManager.RegisterServerChannel(new RpcPipeServerChannel("UnitTest", 10)); RpcServiceManager.RegisterServerChannel(RpcInprocServerChannel.Instance); RpcServiceManager.RegisterServerChannel(new RpcTcpServerChannel(3900)); RpcServiceManager.Start(); RpcServiceManager.RegisterService <IRpcTestService>(new RpcTestService()); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); _inited = true; } CurrentTestUrl = RpcTcpUrl; CurrentFailedUrl = "tcp://127.0.0.1:49494"; }
public void MethodTestBatch() { Exception _ex = null; for (int i = 0; i < 128; i++) { RpcClientProxy proxy = RpcProxyFactory.GetProxy <IRpcTestService>(CurrentTestUrl); proxy.BeginInvoke( "TestBatch", "Hello", delegate(RpcClientContext ctx) { try { var s = ctx.EndInvoke <string>(); if (s != "Hello:OK") { throw new Exception("Response Failed:" + s); } } catch (Exception ex) { _ex = ex; } } ); } Thread.Sleep(5000); if (_ex != null) { throw _ex; } }
public async Task EchoAsyncShouldBeOkAsync() { var settings = new Settings(); var service = RpcProxyFactory.CreateProxyInstance <ITestJsonRpcService>(_client, settings); var echoResult = await service.EchoAsync("hello"); Assert.Equal("hello", echoResult); }
public async Task ArrayArgumentShouldBeOkAsync() { var settings = new Settings(); var service = RpcProxyFactory.CreateProxyInstance <ITestJsonRpcService>(_client, settings); var totalResult = await service.TotalAsync(new[] { 1, 2, 3, 4, 5 }); Assert.Equal(15, totalResult); }
public int TestMethod2 <TArgs, TResults>(string serverUrl, string method, TArgs args, Action <TResults> assertCallback) { Stopwatch watch = new Stopwatch(); watch.Start(); RpcClientProxy proxy = RpcProxyFactory.GetProxy <IRpcTestService>(serverUrl); TResults r = proxy.Invoke <TArgs, TResults>(method, args, 30000); assertCallback(r); return((int)watch.ElapsedMilliseconds); }
public TracingSniffer(string url, TracingLevel level, string from, string to) { _url = url; _level = level; _from = from; _to = to; _enabled = true; _queueTracing = new LazyQueue <TracingEvent>("TracingSniffer.Tracing", 32, 50, DequeueActionTracing); _queueSystemLog = new LazyQueue <SystemLogEvent>("TracingSniffer.SystemLog", 32, 50, DequeueActionSystemLog); _proxy = RpcProxyFactory.GetProxy <ITracingSniffer>(_url); // _proxy.ShutUp = true; }
private void BatchDequeueProc(KeyWrapper <ServerUri, RpcConnection> key, RpcBatchClientTransaction[] txs) { RpcBatchRequest[] requests = new RpcBatchRequest[txs.Length]; for (int i = 0; i < txs.Length; i++) { requests[i] = txs[i].BatchRequest; } RpcRequest request = new RpcRequest(txs[0].Request.Service, txs[0].Request.Method, null); request.BodyBuffer = new RpcBodyBuffer <RpcBatchRequest[]>(requests); if (key.Token == null) { lock (_syncRoot) { key.Token = RpcProxyFactory.GetConnection(key.Key, txs[0].ServiceRole); } } RpcClientTransaction trans = key.Token.CreateTransaction(request); RpcClientContext ctx = new RpcClientContext(trans); ctx.SendRequest( delegate(long elapseTicks, RpcClientContext c2, bool successed) { try { RpcBatchResponse[] resps = ctx.EndInvoke <RpcBatchResponse[]>(); if (resps.Length != txs.Length) { ProcessFailedTxs(txs, RpcErrorCode.InvaildResponseArgs, new Exception("Batch Length NotMatch")); } else { for (int i = 0; i < resps.Length; i++) { txs[i].BatchResponse = resps[i]; txs[i].OnTransactionEnd(); } } } catch (RpcException ex) { ProcessFailedTxs(txs, ex.RpcCode, ex.InnerException); } catch (Exception ex) { ProcessFailedTxs(txs, RpcErrorCode.ServerError, ex); } }, -1 ); }
public void MethodTestAddBulk() { TracingManager.Level = TracingLevel.Warn; int failed = 0; int succ = 0; Exception lastEx; int total = 1500000; for (int i = 0; i < total; i++) { if (i % 1000 == 0) { Thread.Sleep(10); } RpcClientProxy proxy = RpcProxyFactory.GetProxy <IRpcTestService>(CurrentTestUrl); proxy.BeginInvoke( "Add", new RpcClass <int, int>(120, 120), ctx => { try { var s = ctx.EndInvoke <RpcClass <int> >(); if (s.Value != 240) { throw new Exception("Response Failed:" + s); } Interlocked.Increment(ref succ); } catch (Exception ex) { Interlocked.Increment(ref failed); lastEx = ex; } } ); } Thread.Sleep(5000); Assert.AreEqual(0, failed); Assert.AreEqual(total, succ); TracingManager.Level = TracingLevel.Info; }
public void MethodTestException_Timeout() { Stopwatch watch = new Stopwatch(); watch.Start(); try { RpcClientProxy proxy = RpcProxyFactory.GetProxy <IRpcTestService>(CurrentTestUrl); proxy.Timeout = 3000; proxy.Invoke <string, string>("TestTimeout", null); Assert.Fail("Should Failed..."); } catch (RpcException ex) { Assert.AreEqual(RpcErrorCode.TransactionTimeout, ex.RpcCode); Console.WriteLine(ex.ToString()); int ms = (int)watch.ElapsedMilliseconds; } }
private void InvokeAction(string prefix, TccWorkUnitContext <TContext> ctx, bool convertResults) { var uri = GetUri(ctx.Value); RpcClientProxy proxy = RpcProxyFactory.GetProxy <ITccRpcHostService>(uri); proxy.BeginInvoke <TArgs>( prefix + WorkName, ConvertArgs(ctx.Value), delegate(RpcClientContext context) { try { var rets = context.EndInvoke <TResults>(); if (convertResults) { ConvertResults(rets, ctx.Value); } ctx.Return(); } catch (Exception ex) { ctx.ThrowException(ex); } } ); }
public RpcDuplexClient(ServerUri serverUri) { _serverUri = serverUri; _channel = RpcProxyFactory.GetChannel(serverUri); _timeout = _channel.Timeout; _connection = _channel.CreateConnection(serverUri, RpcConnectionMode.Duplex); _connection.Disconnected += new Action <RpcConnection>( (c) => { OnDisconnected(); } ); _connection.TransactionCreated += new Action <RpcConnection, RpcServerTransaction>( (c, tx) => { _dispatcher.ProcessTransaction(tx); } ); _dispatcher = new RpcServiceDispather("duplex"); }
public HAConfigurationLoader(string serviceName, string computerName, string centerUrl) { _computerName = computerName; _serviceName = serviceName; _proxy = RpcProxyFactory.GetProxy <IHACenterConfigService>(centerUrl); }