Ejemplo n.º 1
0
        public void TestRequestThrottling()
        {
            const int numberOfAsyncRequests = 1000;
            const int serverPort            = 9001;
            string    hostAddress           = $"localhost:{serverPort}";

            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                NamedValueSet serverSettings = new NamedValueSet();
                serverSettings.Set(CfgPropName.EnvName, "UTT");
                serverSettings.Set(CfgPropName.Port, serverPort);
                serverSettings.Set(CfgPropName.Endpoints, WcfConst.NetTcp);
                using (CoreServer server = new CoreServer(loggerRef, serverSettings))
                {
                    server.Start();
                    using (ICoreClient client = new CoreClientFactory(loggerRef).SetEnv("UTT").SetServers(hostAddress).Create())
                    {
                        List <IAsyncResult> completions = new List <IAsyncResult>();
                        try
                        {
                            for (int i = 0; i < numberOfAsyncRequests; i++)
                            {
                                completions.Add(client.SaveObjectBegin(new TestData("Test", i), "Test", null, false, TimeSpan.MaxValue));
                                //loggerRef.Target.LogDebug("[{0}] save begun...", i.ToString("0000"));
                            }
                        }
                        finally
                        {
                            for (int i = 0; i < numberOfAsyncRequests; i++)
                            {
                                client.SaveEnd(completions[i]);
                                //loggerRef.Target.LogDebug("[{0}] save done.", i.ToString("0000"));
                            }
                        }
                    }
                }
            }
        }