// ------------------------------ save item methods ------------------------------ public Guid SaveItem(ICoreItem newItem) { if (newItem.DataType == null) { throw new ArgumentNullException("dataType"); } newItem.Freeze(); Cache.Put(newItem.Name, newItem, new CoreItemCacheParams(newItem.DataType, Guid.Empty)); NotifyUserDataChange(Cache.GetUpdates()); return(newItem.Id); }
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 } } } }