Exemple #1
0
        [Ignore] // this is an integration test
        public void StressUttServerLoadAndSubscribe()
        {
            // return an increasing number of trades until failure
            // on a 4GB workstation, the limit is about 13,000 trades.
            Trade trade = XmlSerializerHelper.DeserializeFromString <Trade>(
                ResourceHelper.GetResourceWithPartialName(Assembly.GetExecutingAssembly(), "SampleSwap.xml"));
            NamedValueSet tradeProps = new NamedValueSet(
                ResourceHelper.GetResourceWithPartialName(Assembly.GetExecutingAssembly(), "SampleSwap.nvs"));

            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                //NamedValueSet serverSettings = new NamedValueSet();
                //serverSettings.Set(CfgPropName.NodeType, (int)NodeType.Router);
                //serverSettings.Set(CfgPropName.EnvName, "UTT");
                //using (CoreServer server = new CoreServer(logger, serverSettings))
                {
                    //server.Start();
                    //using (ICoreClient client = new CoreClientFactory(loggerRef).SetEnv("UTT").SetHosts("localhost:8113").Create())
                    using (ICoreClient client = new CoreClientFactory(loggerRef).SetEnv("UTT").Create())
                    {
                        // delete the test trades
                        IExpression deleteExpr = Expr.ALL;
                        client.DeleteObjects <Trade>(deleteExpr);
                        const int maxLoops         = 3;
                        const int loopRepeat       = 3;
                        const int incrementPerLoop = 1024;
                        int       itemsPerLoop     = 1024;
                        int       itemsSaved       = 0;
                        for (int loop = 0; loop < maxLoops; loop++)
                        {
                            string loopName = $"Test.{loop}.";
                            for (int repeat = 0; repeat < loopRepeat; repeat++)
                            {
                                // create trades
                                loggerRef.Target.LogDebug("[{0}-{1}] Creating {2} trades...", loop, repeat, itemsPerLoop);
                                ICoreItem[] items = new ICoreItem[itemsPerLoop];
                                for (int i = 0; i < itemsPerLoop; i++)
                                {
                                    string tradeName = $"Test.{loop}.{i}";
                                    items[i] = client.MakeObject <Trade>(trade, tradeName, tradeProps);
                                    itemsSaved++;
                                }
                                client.SaveItems(items);
                                // start subscription
                                loggerRef.Target.LogDebug("[{0}-{1}] Receiving {2} trades...", loop, repeat, itemsPerLoop);
                                long          itemsReceived   = 0;
                                DateTime      testStartedTime = DateTime.Now;
                                DateTime      lastReceiveTime = testStartedTime;
                                ISubscription subscription    = client.CreateSubscription <Trade>(Expr.StartsWith(Expr.SysPropItemName, loopName));
                                subscription.UserCallback = delegate
                                {
                                    Interlocked.Increment(ref itemsReceived);
                                    lastReceiveTime = DateTime.Now;
                                };
                                //subscription.ExcludeDataBody = true;
                                subscription.Start();
                                // wait a bit to ensure subscription is up to date
                                while ((Interlocked.Add(ref itemsReceived, 0) < itemsPerLoop) && ((DateTime.Now - testStartedTime) < TimeSpan.FromSeconds(10)))
                                {
                                    Thread.Sleep(100);
                                }
                                Thread.Sleep(100);
                                subscription.Cancel();
                                // load all that have been saved
                                loggerRef.Target.LogDebug("[{0}-{1}] Received {2} trades in {3} seconds.", loop, repeat, itemsReceived, (lastReceiveTime - testStartedTime).TotalSeconds);
                                Assert.AreEqual(itemsPerLoop, Interlocked.Add(ref itemsReceived, 0));
                                // delete the test trades
                                //client.DeleteObjects<Trade>(deleteExpr);
                                //GC.Collect();
                            }

                            // next loop
                            itemsPerLoop += incrementPerLoop;
                        } // for loop
                    }
                }
            }
        }
Exemple #2
0
        public void TestStressServerLoadAndRetrieve()
        {
            // return an increasing number of trades until failure
            Trade trade = XmlSerializerHelper.DeserializeFromString <Trade>(
                ResourceHelper.GetResourceWithPartialName(Assembly.GetExecutingAssembly(), "SampleSwap.xml"));
            NamedValueSet tradeProps = new NamedValueSet(
                ResourceHelper.GetResourceWithPartialName(Assembly.GetExecutingAssembly(), "SampleSwap.nvs"));

            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                NamedValueSet serverSettings = new NamedValueSet();
                serverSettings.Set(CfgPropName.NodeType, (int)NodeType.Router);
                serverSettings.Set(CfgPropName.EnvName, "UTT");
                using (CoreServer server = new CoreServer(loggerRef, serverSettings))
                {
                    server.Start();
                    using (ICoreClient client = new CoreClientFactory(loggerRef).SetEnv("UTT").SetServers("localhost:8113").Create())
                    //using (ICoreClient client = new CoreClientFactory(loggerRef).SetEnv(EnvId.DEV_Development).Create())
                    {
                        // delete the test trades
                        IExpression deleteExpr = Expr.StartsWith(Expr.SysPropItemName, "Test.");
                        client.DeleteObjects <Trade>(deleteExpr);
                        const int maxLoops         = 1;
                        const int loopRepeat       = 1;
                        const int incrementPerLoop = 1024;
                        int       itemsPerLoop     = 8192 - 1024;
                        int       itemsSaved       = 0;
                        for (int loop = 0; loop < maxLoops; loop++)
                        {
                            for (int repeat = 0; repeat < loopRepeat; repeat++)
                            {
                                // create trades
                                loggerRef.Target.LogDebug("[{0}-{1}] Making {2} trades...", loop, repeat, itemsPerLoop);
                                List <IAsyncResult> completions = new List <IAsyncResult>();
                                ICoreItem[]         items       = new ICoreItem[itemsPerLoop];
                                for (int i = 0; i < itemsPerLoop; i++)
                                {
                                    string    tradeName = $"Test.{loop}.{i}";
                                    ICoreItem item      = client.MakeObject(trade, tradeName, tradeProps);
                                    item.Freeze(); // serialises
                                    items[i] = item;
                                }
                                loggerRef.Target.LogDebug("[{0}-{1}] Commencing save of {2} trades...", loop, repeat, itemsPerLoop);
                                for (int i = 0; i < itemsPerLoop; i++)
                                {
                                    completions.Add(client.SaveItemBegin(items[i]));
                                    itemsSaved++;
                                }
                                loggerRef.Target.LogDebug("[{0}-{1}] Completing save of {2} trades...", loop, repeat, itemsPerLoop);
                                foreach (IAsyncResult ar in completions)
                                {
                                    client.SaveEnd(ar);
                                }
                                // load all that have been saved
                                string loopName = $"Test.{loop}.";
                                loggerRef.Target.LogDebug("[{0}-{1}] Loading {2} trades...", loop, repeat, itemsPerLoop);
                                List <ICoreItem> tradeItems = client.LoadItems <Trade>(Expr.StartsWith(Expr.SysPropItemName, loopName));
                                Assert.AreEqual(itemsPerLoop, tradeItems.Count);
                                loggerRef.Target.LogDebug("[{0}-{1}] Unpacking {2} trades...", loop, repeat, itemsPerLoop);
                                List <Trade> trades = new List <Trade>();
                                foreach (ICoreItem item in tradeItems)
                                {
                                    trades.Add((Trade)item.Data);
                                }
                                loggerRef.Target.LogDebug("[{0}-{1}] Retrieved {2} trades.", loop, repeat, itemsPerLoop);
                                // delete the test trades
                                client.DeleteObjects <Trade>(deleteExpr);
                                GC.Collect();
                            }
                            // next loop
                            itemsPerLoop += incrementPerLoop;
                        } // for loop
                    }
                }
            }
        }